Skip to content

Commit 402f7f3

Browse files
committed
chore: default to node test env rather than browser
1 parent 1c2011d commit 402f7f3

File tree

22 files changed

+38
-25
lines changed

22 files changed

+38
-25
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### Features
44

5+
- `[jest-config]` [**BREAKING**] Default to Node testing environment instead of browser ([#9874](https://github.com/facebook/jest/pull/9874))
56
- `[@jest/globals]` New package so Jest's globals can be explicitly imported ([#9801](https://github.com/facebook/jest/pull/9801))
67
- `[jest-runtime]` Populate `require.cache` ([#9841](https://github.com/facebook/jest/pull/9841))
78

docs/Configuration.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -881,9 +881,9 @@ To make a dependency explicit instead of implicit, you can call [`expect.addSnap
881881

882882
### `testEnvironment` [string]
883883

884-
Default: `"jsdom"`
884+
Default: `"node"`
885885

886-
The test environment that will be used for testing. The default environment in Jest is a browser-like environment through [jsdom](https://github.com/tmpvar/jsdom). If you are building a node service, you can use the `node` option to use a node-like environment instead.
886+
The test environment that will be used for testing. The default environment in Jest is a Node.js environment. If you are building a web app, you can use a browser-like environment through [`jsdom`](https://github.com/jsdom/jsdom) instead.
887887

888888
By adding a `@jest-environment` docblock at the top of the file, you can specify another environment to be used for all tests in that file:
889889

@@ -963,7 +963,7 @@ beforeAll(() => {
963963

964964
Default: `{}`
965965

966-
Test environment options that will be passed to the `testEnvironment`. The relevant options depend on the environment. For example you can override options given to [jsdom](https://github.com/tmpvar/jsdom) such as `{userAgent: "Agent/007"}`.
966+
Test environment options that will be passed to the `testEnvironment`. The relevant options depend on the environment. For example, you can override options given to [jsdom](https://github.com/jsdom/jsdom) such as `{userAgent: "Agent/007"}`.
967967

968968
### `testMatch` [array\<string>]
969969

e2e/__tests__/__snapshots__/consoleLogOutputWhenRunInBand.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ exports[`prints console.logs when run with forceExit 3`] = `
2020
console.log
2121
Hey
2222
23-
at Object.<anonymous> (__tests__/a-banana.js:1:1)
23+
at Object.log (__tests__/a-banana.js:1:30)
2424
2525
`;

e2e/__tests__/__snapshots__/showConfig.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ exports[`--showConfig outputs config info and exits 1`] = `
5151
"setupFilesAfterEnv": [],
5252
"skipFilter": false,
5353
"snapshotSerializers": [],
54-
"testEnvironment": "<<REPLACED_JEST_PACKAGES_DIR>>/jest-environment-jsdom/build/index.js",
54+
"testEnvironment": "<<REPLACED_JEST_PACKAGES_DIR>>/jest-environment-node/build/index.js",
5555
"testEnvironmentOptions": {},
5656
"testLocationInResults": false,
5757
"testMatch": [

e2e/__tests__/config.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ test('works with jsdom testEnvironmentOptions config JSON', () => {
5959
const result = runJest('environmentOptions', [
6060
'--config=' +
6161
JSON.stringify({
62+
testEnvironment: 'jsdom',
6263
testEnvironmentOptions: {
6364
url: 'https://jestjs.io',
6465
},

e2e/__tests__/resolveBrowserField.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ test('preserves module identity for symlinks when using browser field resolution
3535
`,
3636
'package.json': JSON.stringify({
3737
jest: {
38+
testEnvironment: 'jsdom',
3839
testMatch: ['<rootDir>/test-files/test.js'],
3940
browser: true,
4041
},

examples/angular/jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module.exports = {
22
moduleFileExtensions: ['ts', 'html', 'js', 'json'],
33
setupFilesAfterEnv: ['<rootDir>/setupJest.js'],
4+
testEnvironment: 'jsdom',
45
transform: {
56
'^.+\\.[t|j]s$': [
67
'babel-jest',

examples/jquery/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@
1313
},
1414
"scripts": {
1515
"test": "jest"
16+
},
17+
"jest": {
18+
"testEnvironment": "jsdom"
1619
}
1720
}

examples/react-testing-library/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,8 @@
1717
},
1818
"scripts": {
1919
"test": "jest"
20+
},
21+
"jest": {
22+
"testEnvironment": "jsdom"
2023
}
2124
}

examples/react/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,8 @@
1616
},
1717
"scripts": {
1818
"test": "jest"
19+
},
20+
"jest": {
21+
"testEnvironment": "jsdom"
1922
}
2023
}

0 commit comments

Comments
 (0)