Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: require.resolve on default test sequencer and test environment #11482

Merged
merged 3 commits into from May 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
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
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
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