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, });