mirror of https://github.com/facebook/jest.git
chore: default to node test env rather than browser (#9874)
This commit is contained in:
parent
54955a4302
commit
30b6cee924
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
|
- `[jest-config]` [**BREAKING**] Default to Node testing environment instead of browser (JSDOM) ([#9874](https://github.com/facebook/jest/pull/9874))
|
||||||
|
|
||||||
### Fixes
|
### Fixes
|
||||||
|
|
||||||
- `[jest-transform]` Show enhanced `SyntaxError` message for all `SyntaxError`s ([#10749](https://github.com/facebook/jest/pull/10749))
|
- `[jest-transform]` Show enhanced `SyntaxError` message for all `SyntaxError`s ([#10749](https://github.com/facebook/jest/pull/10749))
|
||||||
|
|
|
@ -989,9 +989,9 @@ More about serializers API can be found [here](https://github.com/facebook/jest/
|
||||||
|
|
||||||
### `testEnvironment` [string]
|
### `testEnvironment` [string]
|
||||||
|
|
||||||
Default: `"jsdom"`
|
Default: `"node"`
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
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:
|
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:
|
||||||
|
|
||||||
|
@ -1071,7 +1071,7 @@ beforeAll(() => {
|
||||||
|
|
||||||
Default: `{}`
|
Default: `{}`
|
||||||
|
|
||||||
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"}`.
|
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"}`.
|
||||||
|
|
||||||
### `testFailureExitCode` [number]
|
### `testFailureExitCode` [number]
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ exports[`--showConfig outputs config info and exits 1`] = `
|
||||||
"skipFilter": false,
|
"skipFilter": false,
|
||||||
"slowTestThreshold": 5,
|
"slowTestThreshold": 5,
|
||||||
"snapshotSerializers": [],
|
"snapshotSerializers": [],
|
||||||
"testEnvironment": "<<REPLACED_JEST_PACKAGES_DIR>>/jest-environment-jsdom/build/index.js",
|
"testEnvironment": "<<REPLACED_JEST_PACKAGES_DIR>>/jest-environment-node/build/index.js",
|
||||||
"testEnvironmentOptions": {},
|
"testEnvironmentOptions": {},
|
||||||
"testLocationInResults": false,
|
"testLocationInResults": false,
|
||||||
"testMatch": [
|
"testMatch": [
|
||||||
|
|
|
@ -59,6 +59,7 @@ test('works with jsdom testEnvironmentOptions config JSON', () => {
|
||||||
const result = runJest('environmentOptions', [
|
const result = runJest('environmentOptions', [
|
||||||
'--config=' +
|
'--config=' +
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
|
testEnvironment: 'jsdom',
|
||||||
testEnvironmentOptions: {
|
testEnvironmentOptions: {
|
||||||
url: 'https://jestjs.io',
|
url: 'https://jestjs.io',
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
{
|
{
|
||||||
"jest": {}
|
"jest": {
|
||||||
|
"testEnvironment": "jsdom"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
moduleFileExtensions: ['ts', 'html', 'js', 'json'],
|
moduleFileExtensions: ['ts', 'html', 'js', 'json'],
|
||||||
setupFilesAfterEnv: ['<rootDir>/setupJest.js'],
|
setupFilesAfterEnv: ['<rootDir>/setupJest.js'],
|
||||||
|
testEnvironment: 'jsdom',
|
||||||
transform: {
|
transform: {
|
||||||
'\\.[tj]s$': ['babel-jest', {configFile: require.resolve('./.babelrc')}],
|
'\\.[tj]s$': ['babel-jest', {configFile: require.resolve('./.babelrc')}],
|
||||||
},
|
},
|
||||||
|
|
|
@ -13,5 +13,8 @@
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "jest"
|
"test": "jest"
|
||||||
|
},
|
||||||
|
"jest": {
|
||||||
|
"testEnvironment": "jsdom"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,5 +17,8 @@
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "jest"
|
"test": "jest"
|
||||||
|
},
|
||||||
|
"jest": {
|
||||||
|
"testEnvironment": "jsdom"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,5 +16,8 @@
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "jest"
|
"test": "jest"
|
||||||
|
},
|
||||||
|
"jest": {
|
||||||
|
"testEnvironment": "jsdom"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,5 +18,8 @@
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "jest"
|
"test": "jest"
|
||||||
|
},
|
||||||
|
"jest": {
|
||||||
|
"testEnvironment": "jsdom"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,6 @@ module.exports = {
|
||||||
'<rootDir>/packages/pretty-format/build/plugins/ConvertAnsi.js',
|
'<rootDir>/packages/pretty-format/build/plugins/ConvertAnsi.js',
|
||||||
require.resolve('jest-snapshot-serializer-raw'),
|
require.resolve('jest-snapshot-serializer-raw'),
|
||||||
],
|
],
|
||||||
testEnvironment: './packages/jest-environment-node',
|
|
||||||
testPathIgnorePatterns: [
|
testPathIgnorePatterns: [
|
||||||
'/test-types/',
|
'/test-types/',
|
||||||
'/__arbitraries__/',
|
'/__arbitraries__/',
|
||||||
|
|
|
@ -255,7 +255,7 @@ module.exports = {
|
||||||
// snapshotSerializers: [],
|
// snapshotSerializers: [],
|
||||||
|
|
||||||
// The test environment that will be used for testing
|
// The test environment that will be used for testing
|
||||||
// testEnvironment: \\"jest-environment-jsdom\\",
|
// testEnvironment: \\"jest-environment-node\\",
|
||||||
|
|
||||||
// Options that will be passed to the testEnvironment
|
// Options that will be passed to the testEnvironment
|
||||||
// testEnvironmentOptions: {},
|
// testEnvironmentOptions: {},
|
||||||
|
|
|
@ -124,8 +124,7 @@ describe('init', () => {
|
||||||
|
|
||||||
const writtenJestConfig = fs.writeFileSync.mock.calls[0][1];
|
const writtenJestConfig = fs.writeFileSync.mock.calls[0][1];
|
||||||
const evaluatedConfig = eval(writtenJestConfig);
|
const evaluatedConfig = eval(writtenJestConfig);
|
||||||
// should modify when the default environment will be changed to "node"
|
expect(evaluatedConfig).toEqual({testEnvironment: 'jsdom'});
|
||||||
expect(evaluatedConfig).toEqual({});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create configuration for {environment: "node"}', async () => {
|
it('should create configuration for {environment: "node"}', async () => {
|
||||||
|
@ -135,8 +134,7 @@ describe('init', () => {
|
||||||
|
|
||||||
const writtenJestConfig = fs.writeFileSync.mock.calls[0][1];
|
const writtenJestConfig = fs.writeFileSync.mock.calls[0][1];
|
||||||
const evaluatedConfig = eval(writtenJestConfig);
|
const evaluatedConfig = eval(writtenJestConfig);
|
||||||
// should modify when the default environment will be changed to "node"
|
expect(evaluatedConfig).toEqual({});
|
||||||
expect(evaluatedConfig).toEqual({testEnvironment: 'node'});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create package.json with configured test command when {scripts: true}', async () => {
|
it('should create package.json with configured test command when {scripts: true}', async () => {
|
||||||
|
|
|
@ -57,9 +57,9 @@ const generateConfigFile = (
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (environment === 'node') {
|
if (environment === 'jsdom') {
|
||||||
Object.assign(overrides, {
|
Object.assign(overrides, {
|
||||||
testEnvironment: 'node',
|
testEnvironment: 'jsdom',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ const defaultOptions: Config.DefaultOptions = {
|
||||||
skipFilter: false,
|
skipFilter: false,
|
||||||
slowTestThreshold: 5,
|
slowTestThreshold: 5,
|
||||||
snapshotSerializers: [],
|
snapshotSerializers: [],
|
||||||
testEnvironment: 'jest-environment-jsdom',
|
testEnvironment: 'jest-environment-node',
|
||||||
testEnvironmentOptions: {},
|
testEnvironmentOptions: {},
|
||||||
testFailureExitCode: 1,
|
testFailureExitCode: 1,
|
||||||
testLocationInResults: false,
|
testLocationInResults: false,
|
||||||
|
|
|
@ -800,7 +800,7 @@ _Note: Jest comes with JSDOM@11 by default. Due to JSDOM 12 and newer dropping s
|
||||||
|
|
||||||
Default: `{}`
|
Default: `{}`
|
||||||
|
|
||||||
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"}`.
|
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"}`.
|
||||||
|
|
||||||
### `testFailureExitCode` [number]
|
### `testFailureExitCode` [number]
|
||||||
|
|
||||||
|
|
|
@ -826,7 +826,7 @@ _Note: Jest comes with JSDOM@11 by default. Due to JSDOM 12 and newer dropping s
|
||||||
|
|
||||||
Default: `{}`
|
Default: `{}`
|
||||||
|
|
||||||
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"}`.
|
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"}`.
|
||||||
|
|
||||||
### `testFailureExitCode` [number]
|
### `testFailureExitCode` [number]
|
||||||
|
|
||||||
|
|
|
@ -967,7 +967,7 @@ _Note: Jest comes with JSDOM@11 by default. Due to JSDOM 12 and newer dropping s
|
||||||
|
|
||||||
Default: `{}`
|
Default: `{}`
|
||||||
|
|
||||||
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"}`.
|
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"}`.
|
||||||
|
|
||||||
### `testFailureExitCode` [number]
|
### `testFailureExitCode` [number]
|
||||||
|
|
||||||
|
|
|
@ -989,7 +989,7 @@ beforeAll(() => {
|
||||||
|
|
||||||
Default: `{}`
|
Default: `{}`
|
||||||
|
|
||||||
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"}`.
|
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"}`.
|
||||||
|
|
||||||
### `testFailureExitCode` [number]
|
### `testFailureExitCode` [number]
|
||||||
|
|
||||||
|
|
|
@ -989,7 +989,7 @@ beforeAll(() => {
|
||||||
|
|
||||||
Default: `{}`
|
Default: `{}`
|
||||||
|
|
||||||
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"}`.
|
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"}`.
|
||||||
|
|
||||||
### `testFailureExitCode` [number]
|
### `testFailureExitCode` [number]
|
||||||
|
|
||||||
|
|
|
@ -1003,7 +1003,7 @@ beforeAll(() => {
|
||||||
|
|
||||||
Default: `{}`
|
Default: `{}`
|
||||||
|
|
||||||
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"}`.
|
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"}`.
|
||||||
|
|
||||||
### `testFailureExitCode` [number]
|
### `testFailureExitCode` [number]
|
||||||
|
|
||||||
|
|
|
@ -1034,7 +1034,7 @@ beforeAll(() => {
|
||||||
|
|
||||||
Default: `{}`
|
Default: `{}`
|
||||||
|
|
||||||
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"}`.
|
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"}`.
|
||||||
|
|
||||||
### `testFailureExitCode` [number]
|
### `testFailureExitCode` [number]
|
||||||
|
|
||||||
|
|
|
@ -1052,7 +1052,7 @@ beforeAll(() => {
|
||||||
|
|
||||||
Default: `{}`
|
Default: `{}`
|
||||||
|
|
||||||
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"}`.
|
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"}`.
|
||||||
|
|
||||||
### `testFailureExitCode` [number]
|
### `testFailureExitCode` [number]
|
||||||
|
|
||||||
|
|
|
@ -1072,7 +1072,7 @@ beforeAll(() => {
|
||||||
|
|
||||||
Default: `{}`
|
Default: `{}`
|
||||||
|
|
||||||
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"}`.
|
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"}`.
|
||||||
|
|
||||||
### `testFailureExitCode` [number]
|
### `testFailureExitCode` [number]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue