diff --git a/@packages/test-environment/package.json b/@packages/test-environment/package.json new file mode 100644 index 0000000000..e1b7c74c2e --- /dev/null +++ b/@packages/test-environment/package.json @@ -0,0 +1,32 @@ +{ + "name": "@commitlint/test-environment", + "version": "8.3.5", + "description": "test environment for @commitlint", + "main": "lib/test-environment.js", + "types": "lib/test-environment.d.ts", + "files": [ + "lib/" + ], + "engines": { + "node": ">=8" + }, + "repository": { + "type": "git", + "url": "https://github.com/conventional-changelog/commitlint.git" + }, + "bugs": { + "url": "https://github.com/conventional-changelog/commitlint/issues" + }, + "homepage": "https://github.com/conventional-changelog/commitlint#readme", + "keywords": [ + "conventional-changelog", + "commitlint", + "test", + "cli" + ], + "license": "MIT", + "dependencies": { + "@types/tmp": "^0.1.0", + "tmp": "0.1.0" + } +} diff --git a/@packages/test-environment/src/test-environment.ts b/@packages/test-environment/src/test-environment.ts new file mode 100644 index 0000000000..b314a06e5d --- /dev/null +++ b/@packages/test-environment/src/test-environment.ts @@ -0,0 +1,15 @@ +// https://github.com/raszi/node-tmp/issues/229 +import NodeEnvironment from 'jest-environment-node'; +import tmp from 'tmp'; + +class TestEnvironment extends NodeEnvironment { + async setup() { + await super.setup(); + + tmp.setGracefulCleanup(); + + this.global.tmp = tmp; + } +} + +export default TestEnvironment; diff --git a/@packages/test-environment/tsconfig.json b/@packages/test-environment/tsconfig.json new file mode 100644 index 0000000000..a38b053b3c --- /dev/null +++ b/@packages/test-environment/tsconfig.json @@ -0,0 +1,15 @@ +{ + "extends": "../../tsconfig.shared.json", + "compilerOptions": { + "composite": true, + "rootDir": "./src", + "outDir": "./lib" + }, + "include": [ + "./src/**/*.ts" + ], + "exclude": [ + "./src/**/*.test.ts", + "./lib/**/*" + ] +} diff --git a/@packages/test/src/fix.ts b/@packages/test/src/fix.ts index 85a45fc9da..446e81c630 100644 --- a/@packages/test/src/fix.ts +++ b/@packages/test/src/fix.ts @@ -1,8 +1,11 @@ -import tmp from 'tmp'; import fs from 'fs-extra'; import path from 'path'; import pkgDir from 'pkg-dir'; +declare global { + var tmp: typeof import('tmp'); +} + export async function bootstrap(fixture?: string, directory?: string) { const tmpDir = tmp.dirSync({ keep: false, diff --git a/jest.config.js b/jest.config.js index 67bfbbc991..c21326e247 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,6 +1,6 @@ module.exports = { preset: 'ts-jest/presets/js-with-babel', - testEnvironment: 'node', + testEnvironment: '@commitlint/test-environment', testRegex: undefined, testMatch: [ '**/*.test.ts?(x)', diff --git a/tsconfig.json b/tsconfig.json index 314a1e218e..1e84cc1ba1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,6 +3,7 @@ "include": [], "extends": "./tsconfig.shared.json", "references": [ + { "path": "@packages/test-environment" }, { "path": "@packages/test" }, { "path": "@commitlint/ensure" }, { "path": "@commitlint/execute-rule" }, diff --git a/yarn.lock b/yarn.lock index a20efebb65..5d6dac6595 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2036,21 +2036,11 @@ resolved "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d" integrity sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA== -"@types/node@*": - version "12.0.2" - resolved "https://registry.npmjs.org/@types/node/-/node-12.0.2.tgz#3452a24edf9fea138b48fad4a0a028a683da1e40" - integrity sha512-5tabW/i+9mhrfEOUcLDu2xBPsHJ+X5Orqy9FKpale3SjDA17j5AEpYq5vfy3oAeAHGcvANRCO3NV3d2D6q3NiA== - -"@types/node@12.12.26": +"@types/node@*", "@types/node@12.12.26", "@types/node@>= 8": version "12.12.26" resolved "https://registry.npmjs.org/@types/node/-/node-12.12.26.tgz#213e153babac0ed169d44a6d919501e68f59dea9" integrity sha512-UmUm94/QZvU5xLcUlNR8hA7Ac+fGpO1EG/a8bcWVz0P0LqtxFmun9Y2bbtuckwGboWJIT70DoWq1r3hb56n3DA== -"@types/node@>= 8": - version "13.5.0" - resolved "https://registry.npmjs.org/@types/node/-/node-13.5.0.tgz#4e498dbf355795a611a87ae5ef811a8660d42662" - integrity sha512-Onhn+z72D2O2Pb2ql2xukJ55rglumsVo1H6Fmyi8mlU9SvKdBk/pUSUAiBY/d9bAOF7VVWajX3sths/+g6ZiAQ== - "@types/normalize-package-data@^2.4.0": version "2.4.0" resolved "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz#e486d0d97396d79beedd0a6e33f4534ff6b4973e"