From 56a60c6e20dc6655ffbc39f2a1c28d16fd545f3a Mon Sep 17 00:00:00 2001 From: Sam Zhou Date: Sat, 29 May 2021 13:41:54 -0400 Subject: [PATCH] fix: `require.resolve` on default test sequencer and test environment (#11482) --- CHANGELOG.md | 1 + .../jest-config/src/__tests__/normalize.test.ts | 13 +++++++++++++ packages/jest-config/src/normalize.ts | 7 +++++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13a4077437eb..57c0c7d69d20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ ### Fixes +- `[jest-config]` `require.resolve` on default test sequencer and test environment ([#11482](https://github.com/facebook/jest/pull/11482)) - `[jest-mock]` Fixed `fn` and `spyOn` exports ([#11480](https://github.com/facebook/jest/pull/11480)) ## 27.0.2 diff --git a/packages/jest-config/src/__tests__/normalize.test.ts b/packages/jest-config/src/__tests__/normalize.test.ts index 3a29e19d6337..924391a49335 100644 --- a/packages/jest-config/src/__tests__/normalize.test.ts +++ b/packages/jest-config/src/__tests__/normalize.test.ts @@ -754,6 +754,19 @@ describe('testEnvironment', () => { ); }); + it('resolves to node environment by default', async () => { + const {options} = await normalize( + { + rootDir: '/root', + }, + {} as Config.Argv, + ); + + expect(options.testEnvironment).toEqual( + require.resolve('jest-environment-node'), + ); + }); + it('throws on invalid environment names', async () => { await expect( normalize( diff --git a/packages/jest-config/src/normalize.ts b/packages/jest-config/src/normalize.ts index c13e0d3b4d40..71aa54e53d60 100644 --- a/packages/jest-config/src/normalize.ts +++ b/packages/jest-config/src/normalize.ts @@ -608,7 +608,9 @@ export default async function normalize( options.testEnvironment = resolveTestEnvironment({ rootDir: options.rootDir, - testEnvironment: options.testEnvironment || DEFAULT_CONFIG.testEnvironment, + testEnvironment: + options.testEnvironment || + require.resolve(DEFAULT_CONFIG.testEnvironment), }); if (!options.roots && options.testPathDirs) { @@ -1054,7 +1056,8 @@ export default async function normalize( } newOptions.testSequencer = resolveSequencer(newOptions.resolver, { - filePath: options.testSequencer || DEFAULT_CONFIG.testSequencer, + filePath: + options.testSequencer || require.resolve(DEFAULT_CONFIG.testSequencer), rootDir: options.rootDir, });