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

feat: stop shipping jsdom by default #12354

Merged
merged 2 commits into from
Feb 10, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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**] Add default `browser` condition to `exportConditions` for `jsdom` environment ([#11924](https://github.com/facebook/jest/pull/11924))
- `[jest-environment-jsdom]` [**BREAKING**] Migrate to ESM ([#12340](https://github.com/facebook/jest/pull/12340))
Expand Down
1 change: 0 additions & 1 deletion packages/jest-config/package.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -12790,7 +12790,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 @@ -12860,7 +12859,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 @@ -13173,7 +13172,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