Skip to content

Commit

Permalink
fix: require.resolve on default test sequencer and test environment
Browse files Browse the repository at this point in the history
They are currently broken in yarn v2 pnp mode. See https://github.com/yarnpkg/berry/runs/2701218390
  • Loading branch information
SamChou19815 committed May 29, 2021
1 parent 50d590a commit 71313b7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
13 changes: 13 additions & 0 deletions packages/jest-config/src/__tests__/normalize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 5 additions & 2 deletions packages/jest-config/src/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
});

Expand Down

0 comments on commit 71313b7

Please sign in to comment.