Skip to content

Commit 5281822

Browse files
authored
test: remove temp files after test run (#960)
* test(test): remove temp files after test run * test(test-environment): create test environment package * refactor(test-environment): rename tmp to test
1 parent 41916da commit 5281822

File tree

7 files changed

+69
-13
lines changed

7 files changed

+69
-13
lines changed

Diff for: @packages/test-environment/package.json

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "@commitlint/test-environment",
3+
"version": "8.3.5",
4+
"description": "test environment for @commitlint",
5+
"main": "lib/test-environment.js",
6+
"types": "lib/test-environment.d.ts",
7+
"files": [
8+
"lib/"
9+
],
10+
"engines": {
11+
"node": ">=8"
12+
},
13+
"repository": {
14+
"type": "git",
15+
"url": "https://github.com/conventional-changelog/commitlint.git"
16+
},
17+
"bugs": {
18+
"url": "https://github.com/conventional-changelog/commitlint/issues"
19+
},
20+
"homepage": "https://github.com/conventional-changelog/commitlint#readme",
21+
"keywords": [
22+
"conventional-changelog",
23+
"commitlint",
24+
"test",
25+
"cli"
26+
],
27+
"license": "MIT",
28+
"dependencies": {
29+
"@types/tmp": "^0.1.0",
30+
"tmp": "0.1.0"
31+
}
32+
}

Diff for: @packages/test-environment/src/test-environment.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// https://github.com/raszi/node-tmp/issues/229
2+
import NodeEnvironment from 'jest-environment-node';
3+
import tmp from 'tmp';
4+
5+
class TestEnvironment extends NodeEnvironment {
6+
async setup() {
7+
await super.setup();
8+
9+
tmp.setGracefulCleanup();
10+
11+
this.global.tmp = tmp;
12+
}
13+
}
14+
15+
export default TestEnvironment;

Diff for: @packages/test-environment/tsconfig.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"extends": "../../tsconfig.shared.json",
3+
"compilerOptions": {
4+
"composite": true,
5+
"rootDir": "./src",
6+
"outDir": "./lib"
7+
},
8+
"include": [
9+
"./src/**/*.ts"
10+
],
11+
"exclude": [
12+
"./src/**/*.test.ts",
13+
"./lib/**/*"
14+
]
15+
}

Diff for: @packages/test/src/fix.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
import tmp from 'tmp';
21
import fs from 'fs-extra';
32
import path from 'path';
43
import pkgDir from 'pkg-dir';
54

5+
declare global {
6+
var tmp: typeof import('tmp');
7+
}
8+
69
export async function bootstrap(fixture?: string, directory?: string) {
710
const tmpDir = tmp.dirSync({
811
keep: false,

Diff for: jest.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
22
preset: 'ts-jest/presets/js-with-babel',
3-
testEnvironment: 'node',
3+
testEnvironment: '@commitlint/test-environment',
44
testRegex: undefined,
55
testMatch: [
66
'**/*.test.ts?(x)',

Diff for: tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"include": [],
44
"extends": "./tsconfig.shared.json",
55
"references": [
6+
{ "path": "@packages/test-environment" },
67
{ "path": "@packages/test" },
78
{ "path": "@commitlint/ensure" },
89
{ "path": "@commitlint/execute-rule" },

Diff for: yarn.lock

+1-11
Original file line numberDiff line numberDiff line change
@@ -2036,21 +2036,11 @@
20362036
resolved "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d"
20372037
integrity sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA==
20382038

2039-
"@types/node@*":
2040-
version "12.0.2"
2041-
resolved "https://registry.npmjs.org/@types/node/-/node-12.0.2.tgz#3452a24edf9fea138b48fad4a0a028a683da1e40"
2042-
integrity sha512-5tabW/i+9mhrfEOUcLDu2xBPsHJ+X5Orqy9FKpale3SjDA17j5AEpYq5vfy3oAeAHGcvANRCO3NV3d2D6q3NiA==
2043-
2044-
2039+
"@types/node@*", "@types/[email protected]", "@types/node@>= 8":
20452040
version "12.12.26"
20462041
resolved "https://registry.npmjs.org/@types/node/-/node-12.12.26.tgz#213e153babac0ed169d44a6d919501e68f59dea9"
20472042
integrity sha512-UmUm94/QZvU5xLcUlNR8hA7Ac+fGpO1EG/a8bcWVz0P0LqtxFmun9Y2bbtuckwGboWJIT70DoWq1r3hb56n3DA==
20482043

2049-
"@types/node@>= 8":
2050-
version "13.5.0"
2051-
resolved "https://registry.npmjs.org/@types/node/-/node-13.5.0.tgz#4e498dbf355795a611a87ae5ef811a8660d42662"
2052-
integrity sha512-Onhn+z72D2O2Pb2ql2xukJ55rglumsVo1H6Fmyi8mlU9SvKdBk/pUSUAiBY/d9bAOF7VVWajX3sths/+g6ZiAQ==
2053-
20542044
"@types/normalize-package-data@^2.4.0":
20552045
version "2.4.0"
20562046
resolved "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz#e486d0d97396d79beedd0a6e33f4534ff6b4973e"

0 commit comments

Comments
 (0)