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
  • Loading branch information
SamChou19815 authored May 29, 2021
1 parent 50d590a commit 56a60c6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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 56a60c6

Please sign in to comment.