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/',

packages/jest-cli/src/init/__tests__/__snapshots__/init.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ module.exports = {
177177
// snapshotSerializers: [],
178178
179179
// The test environment that will be used for testing
180-
// testEnvironment: \\"jest-environment-jsdom\\",
180+
// testEnvironment: \\"jest-environment-node\\",
181181
182182
// Options that will be passed to the testEnvironment
183183
// testEnvironmentOptions: {},

packages/jest-cli/src/init/__tests__/init.test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ describe('init', () => {
100100

101101
const writtenJestConfig = fs.writeFileSync.mock.calls[0][1];
102102
const evaluatedConfig = eval(writtenJestConfig);
103-
// should modify when the default environment will be changed to "node"
104-
expect(evaluatedConfig).toEqual({});
103+
expect(evaluatedConfig).toEqual({testEnvironment: 'jsdom'});
105104
});
106105

107106
it('should create configuration for {environment: "node"}', async () => {
@@ -111,8 +110,7 @@ describe('init', () => {
111110

112111
const writtenJestConfig = fs.writeFileSync.mock.calls[0][1];
113112
const evaluatedConfig = eval(writtenJestConfig);
114-
// should modify when the default environment will be changed to "node"
115-
expect(evaluatedConfig).toEqual({testEnvironment: 'node'});
113+
expect(evaluatedConfig).toEqual({});
116114
});
117115

118116
it('should create package.json with configured test command when {scripts: true}', async () => {

packages/jest-cli/src/init/generate_config_file.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ const generateConfigFile = (
4545
});
4646
}
4747

48-
if (environment === 'node') {
48+
if (environment === 'jsdom') {
4949
Object.assign(overrides, {
50-
testEnvironment: 'node',
50+
testEnvironment: 'jsdom',
5151
});
5252
}
5353

packages/jest-config/src/Defaults.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const defaultOptions: Config.DefaultOptions = {
5151
setupFilesAfterEnv: [],
5252
skipFilter: false,
5353
snapshotSerializers: [],
54-
testEnvironment: 'jest-environment-jsdom',
54+
testEnvironment: 'jest-environment-node',
5555
testEnvironmentOptions: {},
5656
testFailureExitCode: 1,
5757
testLocationInResults: false,

website/versioned_docs/version-22.x/Configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ _Note: Jest comes with JSDOM@11 by default. Due to JSDOM 12 and newer dropping s
716716

717717
Default: `{}`
718718

719-
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"}`.
719+
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"}`.
720720

721721
### `testMatch` [array\<string>]
722722

website/versioned_docs/version-23.x/Configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ _Note: Jest comes with JSDOM@11 by default. Due to JSDOM 12 and newer dropping s
782782

783783
Default: `{}`
784784

785-
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"}`.
785+
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"}`.
786786

787787
### `testMatch` [array\<string>]
788788

website/versioned_docs/version-24.x/Configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ _Note: Jest comes with JSDOM@11 by default. Due to JSDOM 12 and newer dropping s
944944

945945
Default: `{}`
946946

947-
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"}`.
947+
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"}`.
948948

949949
### `testMatch` [array\<string>]
950950

website/versioned_docs/version-25.x/Configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ beforeAll(() => {
966966

967967
Default: `{}`
968968

969-
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"}`.
969+
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"}`.
970970

971971
### `testMatch` [array\<string>]
972972

website/versioned_docs/version-26.0/Configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ beforeAll(() => {
966966

967967
Default: `{}`
968968

969-
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"}`.
969+
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"}`.
970970

971971
### `testMatch` [array\<string>]
972972

0 commit comments

Comments
 (0)