From 09278348b355c0450ddd6d40d074e69e4add688e Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Fri, 28 May 2021 15:32:21 +0200 Subject: [PATCH] fix dependency issues (#11465) --- CHANGELOG.md | 2 ++ e2e/__tests__/__snapshots__/showConfig.test.ts.snap | 2 +- packages/jest-circus/package.json | 1 + packages/jest-config/package.json | 1 + packages/jest-config/src/__tests__/normalize.test.ts | 2 +- packages/jest-config/src/normalize.ts | 4 ++++ packages/jest-config/tsconfig.json | 1 + packages/jest-core/src/__tests__/runJest.test.js | 5 ++++- packages/jest-runner/src/runTest.ts | 4 +++- packages/jest-types/src/Config.ts | 2 +- packages/jest-util/src/requireOrImportModule.ts | 4 +++- yarn.lock | 2 ++ 12 files changed, 24 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef1541b09591..c07213831398 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,9 @@ ### Fixes +- `[jest-circus]` Add missing `slash` dependency ([#11465](https://github.com/facebook/jest/pull/11465)) - `[jest-circus, @jest/test-sequencer]` Remove dependency on `jest-runner` ([#11466](https://github.com/facebook/jest/pull/11466)) +- `[jest-config]` Resolve `config.runner` to absolute path ([#11465](https://github.com/facebook/jest/pull/11465)) - `[jest-core]` Do not warn about `DNSCHANNEL` handles when using the `--detectOpenHandles` option ([#11470](https://github.com/facebook/jest/pull/11470)) - `[jest-runner]` Remove dependency on `jest-config` ([#11466](https://github.com/facebook/jest/pull/11466)) - `[jest-worker]` Loosen engine requirement to `>= 10.13.0` ([#11451](https://github.com/facebook/jest/pull/11451)) diff --git a/e2e/__tests__/__snapshots__/showConfig.test.ts.snap b/e2e/__tests__/__snapshots__/showConfig.test.ts.snap index d8af652bf08d..4ca4895bad34 100644 --- a/e2e/__tests__/__snapshots__/showConfig.test.ts.snap +++ b/e2e/__tests__/__snapshots__/showConfig.test.ts.snap @@ -48,7 +48,7 @@ exports[`--showConfig outputs config info and exits 1`] = ` "roots": [ "<>" ], - "runner": "jest-runner", + "runner": "<>/jest-runner/build/index.js", "setupFiles": [], "setupFilesAfterEnv": [], "skipFilter": false, diff --git a/packages/jest-circus/package.json b/packages/jest-circus/package.json index 328e023f1b2f..06016431ba90 100644 --- a/packages/jest-circus/package.json +++ b/packages/jest-circus/package.json @@ -31,6 +31,7 @@ "jest-snapshot": "^27.0.1", "jest-util": "^27.0.1", "pretty-format": "^27.0.1", + "slash": "^3.0.0", "stack-utils": "^2.0.3", "throat": "^6.0.1" }, diff --git a/packages/jest-config/package.json b/packages/jest-config/package.json index 329b5d01924f..641f383fcf24 100644 --- a/packages/jest-config/package.json +++ b/packages/jest-config/package.json @@ -38,6 +38,7 @@ "jest-jasmine2": "^27.0.1", "jest-regex-util": "^27.0.1", "jest-resolve": "^27.0.1", + "jest-runner": "^27.0.1", "jest-util": "^27.0.1", "jest-validate": "^27.0.1", "micromatch": "^4.0.4", diff --git a/packages/jest-config/src/__tests__/normalize.test.ts b/packages/jest-config/src/__tests__/normalize.test.ts index 751c0cabe7dc..3a29e19d6337 100644 --- a/packages/jest-config/src/__tests__/normalize.test.ts +++ b/packages/jest-config/src/__tests__/normalize.test.ts @@ -1401,7 +1401,7 @@ describe('runner', () => { it('defaults to `jest-runner`', async () => { const {options} = await normalize({rootDir: '/root'}, {} as Config.Argv); - expect(options.runner).toBe('jest-runner'); + expect(options.runner).toBe(require.resolve('jest-runner')); }); it('resolves to runners that do not have the prefix', async () => { diff --git a/packages/jest-config/src/normalize.ts b/packages/jest-config/src/normalize.ts index a703f7f7a179..c13e0d3b4d40 100644 --- a/packages/jest-config/src/normalize.ts +++ b/packages/jest-config/src/normalize.ts @@ -1058,6 +1058,10 @@ export default async function normalize( rootDir: options.rootDir, }); + if (newOptions.runner === DEFAULT_CONFIG.runner) { + newOptions.runner = require.resolve(newOptions.runner); + } + newOptions.nonFlagArgs = argv._?.map(arg => `${arg}`); newOptions.testPathPattern = buildTestPathPattern(argv); newOptions.json = !!argv.json; diff --git a/packages/jest-config/tsconfig.json b/packages/jest-config/tsconfig.json index 7c9dc85e0510..4ffd33734047 100644 --- a/packages/jest-config/tsconfig.json +++ b/packages/jest-config/tsconfig.json @@ -13,6 +13,7 @@ {"path": "../jest-get-type"}, {"path": "../jest-regex-util"}, {"path": "../jest-resolve"}, + {"path": "../jest-runner"}, {"path": "../jest-types"}, {"path": "../jest-util"}, {"path": "../jest-validate"}, diff --git a/packages/jest-core/src/__tests__/runJest.test.js b/packages/jest-core/src/__tests__/runJest.test.js index 842407438f0c..daa74b5ac499 100644 --- a/packages/jest-core/src/__tests__/runJest.test.js +++ b/packages/jest-core/src/__tests__/runJest.test.js @@ -21,7 +21,10 @@ describe('runJest', () => { await runJest({ changedFilesPromise: Promise.resolve({repos: {git: {size: 0}}}), contexts: [], - globalConfig: {testSequencer: '@jest/test-sequencer', watch: true}, + globalConfig: { + testSequencer: require.resolve('@jest/test-sequencer'), + watch: true, + }, onComplete: () => null, outputStream: {}, startRun: {}, diff --git a/packages/jest-runner/src/runTest.ts b/packages/jest-runner/src/runTest.ts index b661248b94ee..23825859b0b9 100644 --- a/packages/jest-runner/src/runTest.ts +++ b/packages/jest-runner/src/runTest.ts @@ -109,7 +109,9 @@ async function runTestInternal( await transformer.requireAndTranspileModule(testEnvironment); const testFramework: TestFramework = await transformer.requireAndTranspileModule( - process.env.JEST_JASMINE === '1' ? 'jest-jasmine2' : config.testRunner, + process.env.JEST_JASMINE === '1' + ? require.resolve('jest-jasmine2') + : config.testRunner, ); const Runtime: typeof RuntimeClass = interopRequireDefault( config.moduleLoader diff --git a/packages/jest-types/src/Config.ts b/packages/jest-types/src/Config.ts index a2ffd2773c0c..68eaa4124a01 100644 --- a/packages/jest-types/src/Config.ts +++ b/packages/jest-types/src/Config.ts @@ -98,7 +98,7 @@ export type DefaultOptions = { restoreMocks: boolean; roots: Array; runTestsByPath: boolean; - runner: 'jest-runner'; + runner: string; setupFiles: Array; setupFilesAfterEnv: Array; skipFilter: boolean; diff --git a/packages/jest-util/src/requireOrImportModule.ts b/packages/jest-util/src/requireOrImportModule.ts index 9966ee727ba9..bd93854d3e71 100644 --- a/packages/jest-util/src/requireOrImportModule.ts +++ b/packages/jest-util/src/requireOrImportModule.ts @@ -15,7 +15,9 @@ export default async function requireOrImportModule( applyInteropRequireDefault = true, ): Promise { if (!isAbsolute(filePath) && filePath[0] === '.') { - throw new Error(`Jest: requireOrImportModule path must be absolute`); + throw new Error( + `Jest: requireOrImportModule path must be absolute, was "${filePath}"`, + ); } try { const requiredModule = require(filePath); diff --git a/yarn.lock b/yarn.lock index 09304724cd7d..3c48f95e3958 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13266,6 +13266,7 @@ fsevents@^1.2.7: jest-snapshot-serializer-raw: ^1.1.0 jest-util: ^27.0.1 pretty-format: ^27.0.1 + slash: ^3.0.0 stack-utils: ^2.0.3 throat: ^6.0.1 languageName: unknown @@ -13327,6 +13328,7 @@ fsevents@^1.2.7: jest-jasmine2: ^27.0.1 jest-regex-util: ^27.0.1 jest-resolve: ^27.0.1 + jest-runner: ^27.0.1 jest-snapshot-serializer-raw: ^1.1.0 jest-util: ^27.0.1 jest-validate: ^27.0.1