Skip to content

Commit fbfe79b

Browse files
committed
chore: default to node test env rather than browser
1 parent 7e5e27a commit fbfe79b

File tree

18 files changed

+30
-17
lines changed

18 files changed

+30
-17
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 ([#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
@@ -930,9 +930,9 @@ More about serializers API can be found [here](https://github.com/facebook/jest/
930930

931931
### `testEnvironment` [string]
932932

933-
Default: `"jsdom"`
933+
Default: `"node"`
934934

935-
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.
935+
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.
936936

937937
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:
938938

@@ -1012,7 +1012,7 @@ beforeAll(() => {
10121012

10131013
Default: `{}`
10141014

1015-
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"}`.
1015+
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"}`.
10161016

10171017
### `testMatch` [array\<string>]
10181018

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ exports[`--showConfig outputs config info and exits 1`] = `
5050
"skipFilter": false,
5151
"slowTestThreshold": 5,
5252
"snapshotSerializers": [],
53-
"testEnvironment": "<<REPLACED_JEST_PACKAGES_DIR>>/jest-environment-jsdom/build/index.js",
53+
"testEnvironment": "<<REPLACED_JEST_PACKAGES_DIR>>/jest-environment-node/build/index.js",
5454
"testEnvironmentOptions": {},
5555
"testLocationInResults": false,
5656
"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
},

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
}

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
}

jest.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ module.exports = {
3333
'<rootDir>/packages/pretty-format/build/plugins/ConvertAnsi.js',
3434
require.resolve('jest-snapshot-serializer-raw'),
3535
],
36-
testEnvironment: './packages/jest-environment-node',
3736
testPathIgnorePatterns: [
3837
'/test-types/',
3938
'/__arbitraries__/',

0 commit comments

Comments
 (0)