Skip to content

Commit 24b421e

Browse files
committed
chore: default to node test env rather than browser
1 parent 1d891d1 commit 24b421e

File tree

19 files changed

+30
-18
lines changed

19 files changed

+30
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
### Features
44

55
- `[jest-config]` Support config files exporting (`async`) `function`s ([#10001](https://github.com/facebook/jest/pull/10001))
6+
- `[jest-config]` [**BREAKING**] Default to Node testing environment instead of browser ([#9874](https://github.com/facebook/jest/pull/9874))
67
- `[jest-cli, jest-core]` Add `--selectProjects` CLI argument to filter test suites by project name ([#8612](https://github.com/facebook/jest/pull/8612))
78

89
### Fixes

docs/Configuration.md

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

892892
### `testEnvironment` [string]
893893

894-
Default: `"jsdom"`
894+
Default: `"node"`
895895

896-
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.
896+
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.
897897

898898
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:
899899

@@ -973,7 +973,7 @@ beforeAll(() => {
973973

974974
Default: `{}`
975975

976-
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"}`.
976+
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"}`.
977977

978978
### `testMatch` [array\<string>]
979979

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ exports[`--showConfig outputs config info and exits 1`] = `
4949
"setupFilesAfterEnv": [],
5050
"skipFilter": false,
5151
"snapshotSerializers": [],
52-
"testEnvironment": "<<REPLACED_JEST_PACKAGES_DIR>>/jest-environment-jsdom/build/index.js",
52+
"testEnvironment": "<<REPLACED_JEST_PACKAGES_DIR>>/jest-environment-node/build/index.js",
5353
"testEnvironmentOptions": {},
5454
"testLocationInResults": false,
5555
"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
'/__arbitraries__/',
3938
'/node_modules/',

0 commit comments

Comments
 (0)