Skip to content

Commit af4cec4

Browse files
committed
chore: default to node test env rather than browser
1 parent 6bd96a0 commit af4cec4

File tree

19 files changed

+33
-18
lines changed

19 files changed

+33
-18
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
### Features
44

5+
- `[jest-config]` [**BREAKING**] Default to Node testing environment instead of browser (JSDOM) ([#9874](https://github.com/facebook/jest/pull/9874))
6+
57
### Fixes
68

79
### Chore & Maintenance

docs/Configuration.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -989,9 +989,9 @@ More about serializers API can be found [here](https://github.com/facebook/jest/
989989

990990
### `testEnvironment` [string]
991991

992-
Default: `"jsdom"`
992+
Default: `"node"`
993993

994-
The test environment that will be used for testing. The default environment in Jest is a browser-like environment through [jsdom](https://github.com/jsdom/jsdom). If you are building a node service, you can use the `node` option to use a node-like environment instead.
994+
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.
995995

996996
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:
997997

@@ -1071,7 +1071,7 @@ beforeAll(() => {
10711071

10721072
Default: `{}`
10731073

1074-
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"}`.
1074+
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"}`.
10751075

10761076
### `testFailureExitCode` [number]
10771077

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
"skipFilter": false,
5252
"slowTestThreshold": 5,
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/dom-diffing/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
{
2-
"jest": {}
2+
"jest": {
3+
"testEnvironment": "jsdom"
4+
}
35
}

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
'\\.[tj]s$': ['babel-jest', {configFile: require.resolve('./.babelrc')}],
67
},

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
}

examples/typescript/package.json

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

0 commit comments

Comments
 (0)