Skip to content

Commit

Permalink
feat: stop shipping jsdom by default (#12354)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Feb 10, 2022
1 parent 4255241 commit a8e997a
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,7 @@
### Features

- `[expect]` [**BREAKING**] Migrate to ESM ([#12344](https://github.com/facebook/jest/pull/12344))
- `[jest-config]` [**BREAKING**] Stop shipping `jest-environment-jsdom` by default ([#12354](https://github.com/facebook/jest/pull/12354))
- `[jest-config]` [**BREAKING**] Stop shipping `jest-jasmine2` by default ([#12355](https://github.com/facebook/jest/pull/12355))
- `[jest-environment-jsdom]` [**BREAKING**] Upgrade jsdom to 19.0.0 ([#12290](https://github.com/facebook/jest/pull/12290))
- `[jest-environment-jsdom]` [**BREAKING**] Add default `browser` condition to `exportConditions` for `jsdom` environment ([#11924](https://github.com/facebook/jest/pull/11924))
Expand Down
1 change: 0 additions & 1 deletion packages/jest-config/package.json
Expand Up @@ -35,7 +35,6 @@
"glob": "^7.1.1",
"graceful-fs": "^4.2.9",
"jest-circus": "^27.5.1",
"jest-environment-jsdom": "^27.5.1",
"jest-environment-node": "^27.5.1",
"jest-get-type": "^27.5.1",
"jest-regex-util": "^27.5.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/src/ValidConfig.ts
Expand Up @@ -113,7 +113,7 @@ const initialOptions: Config.InitialOptions = {
snapshotFormat: PRETTY_FORMAT_DEFAULTS,
snapshotResolver: '<rootDir>/snapshotResolver.js',
snapshotSerializers: ['my-serializer-module'],
testEnvironment: 'jest-environment-jsdom',
testEnvironment: 'jest-environment-node',
testEnvironmentOptions: {userAgent: 'Agent/007'},
testFailureExitCode: 1,
testLocationInResults: false,
Expand Down
1 change: 0 additions & 1 deletion packages/jest-config/tsconfig.json
Expand Up @@ -10,7 +10,6 @@
// jest-test-sequencer, but that is just `require.resolve`d, so no real use
// for their types
"references": [
{"path": "../jest-environment-jsdom"},
{"path": "../jest-environment-node"},
{"path": "../jest-get-type"},
{"path": "../jest-regex-util"},
Expand Down
28 changes: 19 additions & 9 deletions packages/jest-resolve/src/utils.ts
Expand Up @@ -101,15 +101,25 @@ export const resolveTestEnvironment = ({
rootDir: Config.Path;
testEnvironment: string;
requireResolveFunction: (moduleName: string) => string;
}): string =>
resolveWithPrefix(undefined, {
filePath,
humanOptionName: 'Test environment',
optionName: 'testEnvironment',
prefix: 'jest-environment-',
requireResolveFunction,
rootDir,
});
}): string => {
try {
return resolveWithPrefix(undefined, {
filePath,
humanOptionName: 'Test environment',
optionName: 'testEnvironment',
prefix: 'jest-environment-',
requireResolveFunction,
rootDir,
});
} catch (error: any) {
if (filePath === 'jsdom' || filePath === 'jest-environment-jsdom') {
error.message +=
'\n\nAs of Jest 28 "jest-environment-jsdom" is no longer shipped by default, make sure to install it separately.';
}

throw error;
}
};

/**
* Finds the watch plugins to use:
Expand Down
1 change: 0 additions & 1 deletion packages/jest-runner/package.json
Expand Up @@ -27,7 +27,6 @@
"emittery": "^0.8.1",
"graceful-fs": "^4.2.9",
"jest-docblock": "^27.5.1",
"jest-environment-jsdom": "^27.5.1",
"jest-environment-node": "^27.5.1",
"jest-haste-map": "^27.5.1",
"jest-leak-detector": "^27.5.1",
Expand Down
1 change: 0 additions & 1 deletion packages/jest-runner/tsconfig.json
Expand Up @@ -10,7 +10,6 @@
{"path": "../jest-console"},
{"path": "../jest-docblock"},
{"path": "../jest-environment"},
{"path": "../jest-environment-jsdom"},
{"path": "../jest-environment-node"},
{"path": "../jest-haste-map"},
{"path": "../jest-leak-detector"},
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-validate/src/__tests__/fixtures/jestConfig.ts
Expand Up @@ -44,7 +44,7 @@ const defaultConfig = {
restoreMocks: false,
roots: ['<rootDir>'],
snapshotSerializers: [],
testEnvironment: 'jest-environment-jsdom',
testEnvironment: 'jest-environment-node',
testPathIgnorePatterns: [NODE_MODULES_REGEXP],
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.[jt]sx?$',
testResultsProcessor: null,
Expand Down Expand Up @@ -106,7 +106,7 @@ const validConfig = {
setupFilesAfterEnv: ['<rootDir>/testSetupFile.js'],
silent: true,
snapshotSerializers: ['my-serializer-module'],
testEnvironment: 'jest-environment-jsdom',
testEnvironment: 'jest-environment-node',
testNamePattern: 'test signature',
testPathIgnorePatterns: [NODE_MODULES_REGEXP],
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.[jt]sx?$',
Expand Down
11 changes: 10 additions & 1 deletion scripts/verifyPnP.js
Expand Up @@ -34,6 +34,7 @@ try {
{
dependencies: {
jest: '*',
'jest-environment-jsdom': '*',
},
name: 'test-pnp',
},
Expand All @@ -42,7 +43,7 @@ try {
),
);
fs.writeFileSync(
path.join(cwd, 'test.js'),
path.join(cwd, 'jsdom.test.js'),
dedent`
/*
* @jest-environment jsdom
Expand All @@ -53,6 +54,14 @@ try {
});
`,
);
fs.writeFileSync(
path.join(cwd, 'node.test.js'),
dedent`
test('dummy', () => {
expect(typeof window).toBe('undefined');
});
`,
);
execa.sync('yarn', ['link', '--private', '--all', rootDirectory], {
cwd,
stdio: 'inherit',
Expand Down
4 changes: 1 addition & 3 deletions yarn.lock
Expand Up @@ -12819,7 +12819,6 @@ __metadata:
glob: ^7.1.1
graceful-fs: ^4.2.9
jest-circus: ^27.5.1
jest-environment-jsdom: ^27.5.1
jest-environment-node: ^27.5.1
jest-get-type: ^27.5.1
jest-regex-util: ^27.5.1
Expand Down Expand Up @@ -12889,7 +12888,7 @@ __metadata:
languageName: unknown
linkType: soft

"jest-environment-jsdom@^27.5.1, jest-environment-jsdom@workspace:packages/jest-environment-jsdom":
"jest-environment-jsdom@workspace:packages/jest-environment-jsdom":
version: 0.0.0-use.local
resolution: "jest-environment-jsdom@workspace:packages/jest-environment-jsdom"
dependencies:
Expand Down Expand Up @@ -13202,7 +13201,6 @@ __metadata:
emittery: ^0.8.1
graceful-fs: ^4.2.9
jest-docblock: ^27.5.1
jest-environment-jsdom: ^27.5.1
jest-environment-node: ^27.5.1
jest-haste-map: ^27.5.1
jest-jasmine2: ^27.5.1
Expand Down

0 comments on commit a8e997a

Please sign in to comment.