From 67aa05cfe1bbab5e61833fa5e40fbf2ce7045b38 Mon Sep 17 00:00:00 2001 From: Tom Mrazauskas Date: Wed, 8 Mar 2023 17:56:43 +0200 Subject: [PATCH] docs: add `testEnvironmentOptions` configuration examples (#13991) --- docs/Configuration.md | 56 ++++++++++++++++++- .../version-25.x/Configuration.md | 14 ++++- .../version-26.x/Configuration.md | 14 ++++- .../version-27.x/Configuration.md | 14 ++++- .../version-28.x/Configuration.md | 22 +++++++- .../version-29.0/Configuration.md | 56 ++++++++++++++++++- .../version-29.1/Configuration.md | 56 ++++++++++++++++++- .../version-29.2/Configuration.md | 56 ++++++++++++++++++- .../version-29.3/Configuration.md | 56 ++++++++++++++++++- .../version-29.4/Configuration.md | 56 ++++++++++++++++++- .../version-29.5/Configuration.md | 56 ++++++++++++++++++- 11 files changed, 445 insertions(+), 11 deletions(-) diff --git a/docs/Configuration.md b/docs/Configuration.md index e935d8729985..ed7eb7c09f00 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -1908,10 +1908,64 @@ Default: `{}` Test environment options that will be passed to the `testEnvironment`. The relevant options depend on the environment. -For example, in `jest-environment-jsdom`, you can override options given to [`jsdom`](https://github.com/jsdom/jsdom) such as `{html: "", url: 'https://jestjs.io/', userAgent: "Agent/007"}`. +For example, you can override options passed to [`jsdom`](https://github.com/jsdom/jsdom): + +```js tab +/** @type {import('jest').Config} */ +const config = { + testEnvironment: 'jsdom', + testEnvironmentOptions: { + html: '', + url: 'https://jestjs.io/', + userAgent: 'Agent/007', + }, +}; + +module.exports = config; +``` + +```ts tab +import type {Config} from 'jest'; + +const config: Config = { + testEnvironment: 'jsdom', + testEnvironmentOptions: { + html: '', + url: 'https://jestjs.io/', + userAgent: 'Agent/007', + }, +}; + +export default config; +``` Both `jest-environment-jsdom` and `jest-environment-node` allow specifying `customExportConditions`, which allow you to control which versions of a library are loaded from `exports` in `package.json`. `jest-environment-jsdom` defaults to `['browser']`. `jest-environment-node` defaults to `['node', 'node-addons']`. +```js tab +/** @type {import('jest').Config} */ +const config = { + testEnvironment: 'jsdom', + testEnvironmentOptions: { + customExportConditions: ['react-native'], + }, +}; + +module.exports = config; +``` + +```ts tab +import type {Config} from 'jest'; + +const config: Config = { + testEnvironment: 'jsdom', + testEnvironmentOptions: { + customExportConditions: ['react-native'], + }, +}; + +export default config; +``` + These options can also be passed in a docblock, similar to `testEnvironment`. The string with options must be parseable by `JSON.parse`: ```js diff --git a/website/versioned_docs/version-25.x/Configuration.md b/website/versioned_docs/version-25.x/Configuration.md index 299a27674a02..ac955a96935d 100644 --- a/website/versioned_docs/version-25.x/Configuration.md +++ b/website/versioned_docs/version-25.x/Configuration.md @@ -1100,7 +1100,19 @@ 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 passed to [`jsdom`](https://github.com/jsdom/jsdom): + +```js +module.exports = { + testEnvironment: 'jsdom', + testEnvironmentOptions: { + html: '', + userAgent: 'Agent/007', + }, +}; +``` ### `testFailureExitCode` \[number] diff --git a/website/versioned_docs/version-26.x/Configuration.md b/website/versioned_docs/version-26.x/Configuration.md index db2a9d840be3..a3e5c2a5b331 100644 --- a/website/versioned_docs/version-26.x/Configuration.md +++ b/website/versioned_docs/version-26.x/Configuration.md @@ -1186,7 +1186,19 @@ 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 passed to [`jsdom`](https://github.com/jsdom/jsdom): + +```js +module.exports = { + testEnvironment: 'jsdom', + testEnvironmentOptions: { + html: '', + userAgent: 'Agent/007', + }, +}; +``` ### `testFailureExitCode` \[number] diff --git a/website/versioned_docs/version-27.x/Configuration.md b/website/versioned_docs/version-27.x/Configuration.md index 585dc6213b6c..c9d0653cc23d 100644 --- a/website/versioned_docs/version-27.x/Configuration.md +++ b/website/versioned_docs/version-27.x/Configuration.md @@ -1256,7 +1256,19 @@ 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 `{html: "", 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 passed to [`jsdom`](https://github.com/jsdom/jsdom): + +```js +module.exports = { + testEnvironment: 'jsdom', + testEnvironmentOptions: { + html: '', + userAgent: 'Agent/007', + }, +}; +``` ### `testFailureExitCode` \[number] diff --git a/website/versioned_docs/version-28.x/Configuration.md b/website/versioned_docs/version-28.x/Configuration.md index 50bae7c6a6db..c09915f6b902 100644 --- a/website/versioned_docs/version-28.x/Configuration.md +++ b/website/versioned_docs/version-28.x/Configuration.md @@ -1393,10 +1393,30 @@ Default: `{}` Test environment options that will be passed to the `testEnvironment`. The relevant options depend on the environment. -For example, in `jest-environment-jsdom`, you can override options given to [`jsdom`](https://github.com/jsdom/jsdom) such as `{html: "", url: 'https://jestjs.io/', userAgent: "Agent/007"}`. +For example, you can override options passed to [`jsdom`](https://github.com/jsdom/jsdom): + +```js +module.exports = { + testEnvironment: 'jsdom', + testEnvironmentOptions: { + html: '', + url: 'https://jestjs.io/', + userAgent: 'Agent/007', + }, +}; +``` Both `jest-environment-jsdom` and `jest-environment-node` allow specifying `customExportConditions`, which allow you to control which versions of a library are loaded from `exports` in `package.json`. `jest-environment-jsdom` defaults to `['browser']`. `jest-environment-node` defaults to `['node', 'node-addons']`. +```js +module.exports = { + testEnvironment: 'jsdom', + testEnvironmentOptions: { + customExportConditions: ['react-native'], + }, +}; +``` + These options can also be passed in a docblock, similar to `testEnvironment`. The string with options must be parseable by `JSON.parse`: ```js diff --git a/website/versioned_docs/version-29.0/Configuration.md b/website/versioned_docs/version-29.0/Configuration.md index bcc5c276d3c4..061437d52c6a 100644 --- a/website/versioned_docs/version-29.0/Configuration.md +++ b/website/versioned_docs/version-29.0/Configuration.md @@ -1867,10 +1867,64 @@ Default: `{}` Test environment options that will be passed to the `testEnvironment`. The relevant options depend on the environment. -For example, in `jest-environment-jsdom`, you can override options given to [`jsdom`](https://github.com/jsdom/jsdom) such as `{html: "", url: 'https://jestjs.io/', userAgent: "Agent/007"}`. +For example, you can override options passed to [`jsdom`](https://github.com/jsdom/jsdom): + +```js tab +/** @type {import('jest').Config} */ +const config = { + testEnvironment: 'jsdom', + testEnvironmentOptions: { + html: '', + url: 'https://jestjs.io/', + userAgent: 'Agent/007', + }, +}; + +module.exports = config; +``` + +```ts tab +import type {Config} from 'jest'; + +const config: Config = { + testEnvironment: 'jsdom', + testEnvironmentOptions: { + html: '', + url: 'https://jestjs.io/', + userAgent: 'Agent/007', + }, +}; + +export default config; +``` Both `jest-environment-jsdom` and `jest-environment-node` allow specifying `customExportConditions`, which allow you to control which versions of a library are loaded from `exports` in `package.json`. `jest-environment-jsdom` defaults to `['browser']`. `jest-environment-node` defaults to `['node', 'node-addons']`. +```js tab +/** @type {import('jest').Config} */ +const config = { + testEnvironment: 'jsdom', + testEnvironmentOptions: { + customExportConditions: ['react-native'], + }, +}; + +module.exports = config; +``` + +```ts tab +import type {Config} from 'jest'; + +const config: Config = { + testEnvironment: 'jsdom', + testEnvironmentOptions: { + customExportConditions: ['react-native'], + }, +}; + +export default config; +``` + These options can also be passed in a docblock, similar to `testEnvironment`. The string with options must be parseable by `JSON.parse`: ```js diff --git a/website/versioned_docs/version-29.1/Configuration.md b/website/versioned_docs/version-29.1/Configuration.md index 48386f355224..1a50cf2ced89 100644 --- a/website/versioned_docs/version-29.1/Configuration.md +++ b/website/versioned_docs/version-29.1/Configuration.md @@ -1867,10 +1867,64 @@ Default: `{}` Test environment options that will be passed to the `testEnvironment`. The relevant options depend on the environment. -For example, in `jest-environment-jsdom`, you can override options given to [`jsdom`](https://github.com/jsdom/jsdom) such as `{html: "", url: 'https://jestjs.io/', userAgent: "Agent/007"}`. +For example, you can override options passed to [`jsdom`](https://github.com/jsdom/jsdom): + +```js tab +/** @type {import('jest').Config} */ +const config = { + testEnvironment: 'jsdom', + testEnvironmentOptions: { + html: '', + url: 'https://jestjs.io/', + userAgent: 'Agent/007', + }, +}; + +module.exports = config; +``` + +```ts tab +import type {Config} from 'jest'; + +const config: Config = { + testEnvironment: 'jsdom', + testEnvironmentOptions: { + html: '', + url: 'https://jestjs.io/', + userAgent: 'Agent/007', + }, +}; + +export default config; +``` Both `jest-environment-jsdom` and `jest-environment-node` allow specifying `customExportConditions`, which allow you to control which versions of a library are loaded from `exports` in `package.json`. `jest-environment-jsdom` defaults to `['browser']`. `jest-environment-node` defaults to `['node', 'node-addons']`. +```js tab +/** @type {import('jest').Config} */ +const config = { + testEnvironment: 'jsdom', + testEnvironmentOptions: { + customExportConditions: ['react-native'], + }, +}; + +module.exports = config; +``` + +```ts tab +import type {Config} from 'jest'; + +const config: Config = { + testEnvironment: 'jsdom', + testEnvironmentOptions: { + customExportConditions: ['react-native'], + }, +}; + +export default config; +``` + These options can also be passed in a docblock, similar to `testEnvironment`. The string with options must be parseable by `JSON.parse`: ```js diff --git a/website/versioned_docs/version-29.2/Configuration.md b/website/versioned_docs/version-29.2/Configuration.md index f6759438bb75..c1327a44fbed 100644 --- a/website/versioned_docs/version-29.2/Configuration.md +++ b/website/versioned_docs/version-29.2/Configuration.md @@ -1873,10 +1873,64 @@ Default: `{}` Test environment options that will be passed to the `testEnvironment`. The relevant options depend on the environment. -For example, in `jest-environment-jsdom`, you can override options given to [`jsdom`](https://github.com/jsdom/jsdom) such as `{html: "", url: 'https://jestjs.io/', userAgent: "Agent/007"}`. +For example, you can override options passed to [`jsdom`](https://github.com/jsdom/jsdom): + +```js tab +/** @type {import('jest').Config} */ +const config = { + testEnvironment: 'jsdom', + testEnvironmentOptions: { + html: '', + url: 'https://jestjs.io/', + userAgent: 'Agent/007', + }, +}; + +module.exports = config; +``` + +```ts tab +import type {Config} from 'jest'; + +const config: Config = { + testEnvironment: 'jsdom', + testEnvironmentOptions: { + html: '', + url: 'https://jestjs.io/', + userAgent: 'Agent/007', + }, +}; + +export default config; +``` Both `jest-environment-jsdom` and `jest-environment-node` allow specifying `customExportConditions`, which allow you to control which versions of a library are loaded from `exports` in `package.json`. `jest-environment-jsdom` defaults to `['browser']`. `jest-environment-node` defaults to `['node', 'node-addons']`. +```js tab +/** @type {import('jest').Config} */ +const config = { + testEnvironment: 'jsdom', + testEnvironmentOptions: { + customExportConditions: ['react-native'], + }, +}; + +module.exports = config; +``` + +```ts tab +import type {Config} from 'jest'; + +const config: Config = { + testEnvironment: 'jsdom', + testEnvironmentOptions: { + customExportConditions: ['react-native'], + }, +}; + +export default config; +``` + These options can also be passed in a docblock, similar to `testEnvironment`. The string with options must be parseable by `JSON.parse`: ```js diff --git a/website/versioned_docs/version-29.3/Configuration.md b/website/versioned_docs/version-29.3/Configuration.md index ac437e182574..9b6ac34b271b 100644 --- a/website/versioned_docs/version-29.3/Configuration.md +++ b/website/versioned_docs/version-29.3/Configuration.md @@ -1873,10 +1873,64 @@ Default: `{}` Test environment options that will be passed to the `testEnvironment`. The relevant options depend on the environment. -For example, in `jest-environment-jsdom`, you can override options given to [`jsdom`](https://github.com/jsdom/jsdom) such as `{html: "", url: 'https://jestjs.io/', userAgent: "Agent/007"}`. +For example, you can override options passed to [`jsdom`](https://github.com/jsdom/jsdom): + +```js tab +/** @type {import('jest').Config} */ +const config = { + testEnvironment: 'jsdom', + testEnvironmentOptions: { + html: '', + url: 'https://jestjs.io/', + userAgent: 'Agent/007', + }, +}; + +module.exports = config; +``` + +```ts tab +import type {Config} from 'jest'; + +const config: Config = { + testEnvironment: 'jsdom', + testEnvironmentOptions: { + html: '', + url: 'https://jestjs.io/', + userAgent: 'Agent/007', + }, +}; + +export default config; +``` Both `jest-environment-jsdom` and `jest-environment-node` allow specifying `customExportConditions`, which allow you to control which versions of a library are loaded from `exports` in `package.json`. `jest-environment-jsdom` defaults to `['browser']`. `jest-environment-node` defaults to `['node', 'node-addons']`. +```js tab +/** @type {import('jest').Config} */ +const config = { + testEnvironment: 'jsdom', + testEnvironmentOptions: { + customExportConditions: ['react-native'], + }, +}; + +module.exports = config; +``` + +```ts tab +import type {Config} from 'jest'; + +const config: Config = { + testEnvironment: 'jsdom', + testEnvironmentOptions: { + customExportConditions: ['react-native'], + }, +}; + +export default config; +``` + These options can also be passed in a docblock, similar to `testEnvironment`. The string with options must be parseable by `JSON.parse`: ```js diff --git a/website/versioned_docs/version-29.4/Configuration.md b/website/versioned_docs/version-29.4/Configuration.md index eebddd813855..5c8c06689d56 100644 --- a/website/versioned_docs/version-29.4/Configuration.md +++ b/website/versioned_docs/version-29.4/Configuration.md @@ -1873,10 +1873,64 @@ Default: `{}` Test environment options that will be passed to the `testEnvironment`. The relevant options depend on the environment. -For example, in `jest-environment-jsdom`, you can override options given to [`jsdom`](https://github.com/jsdom/jsdom) such as `{html: "", url: 'https://jestjs.io/', userAgent: "Agent/007"}`. +For example, you can override options passed to [`jsdom`](https://github.com/jsdom/jsdom): + +```js tab +/** @type {import('jest').Config} */ +const config = { + testEnvironment: 'jsdom', + testEnvironmentOptions: { + html: '', + url: 'https://jestjs.io/', + userAgent: 'Agent/007', + }, +}; + +module.exports = config; +``` + +```ts tab +import type {Config} from 'jest'; + +const config: Config = { + testEnvironment: 'jsdom', + testEnvironmentOptions: { + html: '', + url: 'https://jestjs.io/', + userAgent: 'Agent/007', + }, +}; + +export default config; +``` Both `jest-environment-jsdom` and `jest-environment-node` allow specifying `customExportConditions`, which allow you to control which versions of a library are loaded from `exports` in `package.json`. `jest-environment-jsdom` defaults to `['browser']`. `jest-environment-node` defaults to `['node', 'node-addons']`. +```js tab +/** @type {import('jest').Config} */ +const config = { + testEnvironment: 'jsdom', + testEnvironmentOptions: { + customExportConditions: ['react-native'], + }, +}; + +module.exports = config; +``` + +```ts tab +import type {Config} from 'jest'; + +const config: Config = { + testEnvironment: 'jsdom', + testEnvironmentOptions: { + customExportConditions: ['react-native'], + }, +}; + +export default config; +``` + These options can also be passed in a docblock, similar to `testEnvironment`. The string with options must be parseable by `JSON.parse`: ```js diff --git a/website/versioned_docs/version-29.5/Configuration.md b/website/versioned_docs/version-29.5/Configuration.md index e935d8729985..ed7eb7c09f00 100644 --- a/website/versioned_docs/version-29.5/Configuration.md +++ b/website/versioned_docs/version-29.5/Configuration.md @@ -1908,10 +1908,64 @@ Default: `{}` Test environment options that will be passed to the `testEnvironment`. The relevant options depend on the environment. -For example, in `jest-environment-jsdom`, you can override options given to [`jsdom`](https://github.com/jsdom/jsdom) such as `{html: "", url: 'https://jestjs.io/', userAgent: "Agent/007"}`. +For example, you can override options passed to [`jsdom`](https://github.com/jsdom/jsdom): + +```js tab +/** @type {import('jest').Config} */ +const config = { + testEnvironment: 'jsdom', + testEnvironmentOptions: { + html: '', + url: 'https://jestjs.io/', + userAgent: 'Agent/007', + }, +}; + +module.exports = config; +``` + +```ts tab +import type {Config} from 'jest'; + +const config: Config = { + testEnvironment: 'jsdom', + testEnvironmentOptions: { + html: '', + url: 'https://jestjs.io/', + userAgent: 'Agent/007', + }, +}; + +export default config; +``` Both `jest-environment-jsdom` and `jest-environment-node` allow specifying `customExportConditions`, which allow you to control which versions of a library are loaded from `exports` in `package.json`. `jest-environment-jsdom` defaults to `['browser']`. `jest-environment-node` defaults to `['node', 'node-addons']`. +```js tab +/** @type {import('jest').Config} */ +const config = { + testEnvironment: 'jsdom', + testEnvironmentOptions: { + customExportConditions: ['react-native'], + }, +}; + +module.exports = config; +``` + +```ts tab +import type {Config} from 'jest'; + +const config: Config = { + testEnvironment: 'jsdom', + testEnvironmentOptions: { + customExportConditions: ['react-native'], + }, +}; + +export default config; +``` + These options can also be passed in a docblock, similar to `testEnvironment`. The string with options must be parseable by `JSON.parse`: ```js