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
|
||||
|
||||
- `[jest-config]` [**BREAKING**] Default to Node testing environment instead of browser (JSDOM) ([#9874](https://github.com/facebook/jest/pull/9874))
|
||||
|
||||
### Fixes
|
||||
|
||||
- `[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]
|
||||
|
||||
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:
|
||||
|
||||
|
@ -1071,7 +1071,7 @@ beforeAll(() => {
|
|||
|
||||
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]
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ exports[`--showConfig outputs config info and exits 1`] = `
|
|||
"skipFilter": false,
|
||||
"slowTestThreshold": 5,
|
||||
"snapshotSerializers": [],
|
||||
"testEnvironment": "<<REPLACED_JEST_PACKAGES_DIR>>/jest-environment-jsdom/build/index.js",
|
||||
"testEnvironment": "<<REPLACED_JEST_PACKAGES_DIR>>/jest-environment-node/build/index.js",
|
||||
"testEnvironmentOptions": {},
|
||||
"testLocationInResults": false,
|
||||
"testMatch": [
|
||||
|
|
|
@ -59,6 +59,7 @@ test('works with jsdom testEnvironmentOptions config JSON', () => {
|
|||
const result = runJest('environmentOptions', [
|
||||
'--config=' +
|
||||
JSON.stringify({
|
||||
testEnvironment: 'jsdom',
|
||||
testEnvironmentOptions: {
|
||||
url: 'https://jestjs.io',
|
||||
},
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
{
|
||||
"jest": {}
|
||||
"jest": {
|
||||
"testEnvironment": "jsdom"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
module.exports = {
|
||||
moduleFileExtensions: ['ts', 'html', 'js', 'json'],
|
||||
setupFilesAfterEnv: ['<rootDir>/setupJest.js'],
|
||||
testEnvironment: 'jsdom',
|
||||
transform: {
|
||||
'\\.[tj]s$': ['babel-jest', {configFile: require.resolve('./.babelrc')}],
|
||||
},
|
||||
|
|
|
@ -13,5 +13,8 @@
|
|||
},
|
||||
"scripts": {
|
||||
"test": "jest"
|
||||
},
|
||||
"jest": {
|
||||
"testEnvironment": "jsdom"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,5 +17,8 @@
|
|||
},
|
||||
"scripts": {
|
||||
"test": "jest"
|
||||
},
|
||||
"jest": {
|
||||
"testEnvironment": "jsdom"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,5 +16,8 @@
|
|||
},
|
||||
"scripts": {
|
||||
"test": "jest"
|
||||
},
|
||||
"jest": {
|
||||
"testEnvironment": "jsdom"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,5 +18,8 @@
|
|||
},
|
||||
"scripts": {
|
||||
"test": "jest"
|
||||
},
|
||||
"jest": {
|
||||
"testEnvironment": "jsdom"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,6 @@ module.exports = {
|
|||
'<rootDir>/packages/pretty-format/build/plugins/ConvertAnsi.js',
|
||||
require.resolve('jest-snapshot-serializer-raw'),
|
||||
],
|
||||
testEnvironment: './packages/jest-environment-node',
|
||||
testPathIgnorePatterns: [
|
||||
'/test-types/',
|
||||
'/__arbitraries__/',
|
||||
|
|
|
@ -255,7 +255,7 @@ module.exports = {
|
|||
// snapshotSerializers: [],
|
||||
|
||||
// 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
|
||||
// testEnvironmentOptions: {},
|
||||
|
|
|
@ -124,8 +124,7 @@ describe('init', () => {
|
|||
|
||||
const writtenJestConfig = fs.writeFileSync.mock.calls[0][1];
|
||||
const evaluatedConfig = eval(writtenJestConfig);
|
||||
// should modify when the default environment will be changed to "node"
|
||||
expect(evaluatedConfig).toEqual({});
|
||||
expect(evaluatedConfig).toEqual({testEnvironment: 'jsdom'});
|
||||
});
|
||||
|
||||
it('should create configuration for {environment: "node"}', async () => {
|
||||
|
@ -135,8 +134,7 @@ describe('init', () => {
|
|||
|
||||
const writtenJestConfig = fs.writeFileSync.mock.calls[0][1];
|
||||
const evaluatedConfig = eval(writtenJestConfig);
|
||||
// should modify when the default environment will be changed to "node"
|
||||
expect(evaluatedConfig).toEqual({testEnvironment: 'node'});
|
||||
expect(evaluatedConfig).toEqual({});
|
||||
});
|
||||
|
||||
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, {
|
||||
testEnvironment: 'node',
|
||||
testEnvironment: 'jsdom',
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ const defaultOptions: Config.DefaultOptions = {
|
|||
skipFilter: false,
|
||||
slowTestThreshold: 5,
|
||||
snapshotSerializers: [],
|
||||
testEnvironment: 'jest-environment-jsdom',
|
||||
testEnvironment: 'jest-environment-node',
|
||||
testEnvironmentOptions: {},
|
||||
testFailureExitCode: 1,
|
||||
testLocationInResults: false,
|
||||
|
|
|
@ -800,7 +800,7 @@ _Note: Jest comes with JSDOM@11 by default. Due to JSDOM 12 and newer dropping s
|
|||
|
||||
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]
|
||||
|
||||
|
|
|
@ -826,7 +826,7 @@ _Note: Jest comes with JSDOM@11 by default. Due to JSDOM 12 and newer dropping s
|
|||
|
||||
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]
|
||||
|
||||
|
|
|
@ -967,7 +967,7 @@ _Note: Jest comes with JSDOM@11 by default. Due to JSDOM 12 and newer dropping s
|
|||
|
||||
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]
|
||||
|
||||
|
|
|
@ -989,7 +989,7 @@ beforeAll(() => {
|
|||
|
||||
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]
|
||||
|
||||
|
|
|
@ -989,7 +989,7 @@ beforeAll(() => {
|
|||
|
||||
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]
|
||||
|
||||
|
|
|
@ -1003,7 +1003,7 @@ beforeAll(() => {
|
|||
|
||||
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]
|
||||
|
||||
|
|
|
@ -1034,7 +1034,7 @@ beforeAll(() => {
|
|||
|
||||
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]
|
||||
|
||||
|
|
|
@ -1052,7 +1052,7 @@ beforeAll(() => {
|
|||
|
||||
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]
|
||||
|
||||
|
|
|
@ -1072,7 +1072,7 @@ beforeAll(() => {
|
|||
|
||||
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]
|
||||
|
||||
|
|
Loading…
Reference in New Issue