From 05cd5e8b5b0e308c8ef5d24015b72d385fa741ed Mon Sep 17 00:00:00 2001 From: mrazauskas <72159681+mrazauskas@users.noreply.github.com> Date: Tue, 28 Sep 2021 11:06:40 +0300 Subject: [PATCH 1/9] fix: improve `testEnvironmentOptions` description --- packages/jest-cli/src/cli/args.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/jest-cli/src/cli/args.ts b/packages/jest-cli/src/cli/args.ts index 3e378b31d15c..26d2101e24f0 100644 --- a/packages/jest-cli/src/cli/args.ts +++ b/packages/jest-cli/src/cli/args.ts @@ -549,9 +549,9 @@ export const options = { }, testEnvironmentOptions: { description: - 'Test environment options that will be passed to the testEnvironment. ' + + 'A JSON string with options that will be passed to the `testEnvironment`. ' + 'The relevant options depend on the environment.', - type: 'string', // Object + type: 'string', }, testFailureExitCode: { description: 'Exit code of `jest` command if the test run failed', From 1a90d3a3658375857c7238bde5ba1daf86965bdf Mon Sep 17 00:00:00 2001 From: mrazauskas <72159681+mrazauskas@users.noreply.github.com> Date: Tue, 28 Sep 2021 11:17:36 +0300 Subject: [PATCH 2/9] chore: update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f749e0b2cdc..b4a2eb0d65bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ ### Fixes - `[jest-reporters]` Call `destroy` on `v8-to-istanbul` converters to free memory ([#11896](https://github.com/facebook/jest/pull/11896)) +- `[jest-cli]` Improve description of `testEnvironmentOptions` option ([#11902](https://github.com/facebook/jest/pull/11902)) ### Chore & Maintenance From a77becff3d60ab49e52d44721cfd373a1e3e9d92 Mon Sep 17 00:00:00 2001 From: mrazauskas <72159681+mrazauskas@users.noreply.github.com> Date: Tue, 28 Sep 2021 12:05:08 +0300 Subject: [PATCH 3/9] fix(config): parse `testEnvironmentOptions` --- packages/jest-config/src/__tests__/setFromArgv.test.ts | 4 ++++ packages/jest-config/src/setFromArgv.ts | 3 ++- packages/jest-types/src/Config.ts | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/jest-config/src/__tests__/setFromArgv.test.ts b/packages/jest-config/src/__tests__/setFromArgv.test.ts index 99d810f58e32..370b0e9cdda4 100644 --- a/packages/jest-config/src/__tests__/setFromArgv.test.ts +++ b/packages/jest-config/src/__tests__/setFromArgv.test.ts @@ -47,6 +47,7 @@ test('works with string objects', () => { const argv = { moduleNameMapper: '{"types/(.*)": "/src/types/$1", "types2/(.*)": ["/src/types2/$1", "/src/types3/$1"]}', + testEnvironmentOptions: '{"userAgent": "Agent/007"}', transform: '{"*.js": "/transformer"}', } as Config.Argv; expect(setFromArgv(options, argv)).toMatchObject({ @@ -54,6 +55,9 @@ test('works with string objects', () => { 'types/(.*)': '/src/types/$1', 'types2/(.*)': ['/src/types2/$1', '/src/types3/$1'], }, + testEnvironmentOptions: { + userAgent: 'Agent/007', + }, transform: { '*.js': '/transformer', }, diff --git a/packages/jest-config/src/setFromArgv.ts b/packages/jest-config/src/setFromArgv.ts index aedb9b3792f8..0a977d8f70b8 100644 --- a/packages/jest-config/src/setFromArgv.ts +++ b/packages/jest-config/src/setFromArgv.ts @@ -35,9 +35,10 @@ export default function setFromArgv( break; case 'coverageThreshold': case 'globals': + case 'haste': case 'moduleNameMapper': + case 'testEnvironmentOptions': case 'transform': - case 'haste': const str = argv[key]; if (isJSONString(str)) { options[key] = JSON.parse(str); diff --git a/packages/jest-types/src/Config.ts b/packages/jest-types/src/Config.ts index 79c89df32244..e2967dc9dacc 100644 --- a/packages/jest-types/src/Config.ts +++ b/packages/jest-types/src/Config.ts @@ -462,6 +462,7 @@ export type Argv = Arguments< silent: boolean; snapshotSerializers: Array; testEnvironment: string; + testEnvironmentOptions: string; testFailureExitCode: string | null | undefined; testMatch: Array; testNamePattern: string; From 88d5c68092d8df6917ca3205a0296db5b2ad9c8e Mon Sep 17 00:00:00 2001 From: mrazauskas <72159681+mrazauskas@users.noreply.github.com> Date: Tue, 28 Sep 2021 12:05:56 +0300 Subject: [PATCH 4/9] docs(cli): include `testEnvironmentOptions` --- docs/CLI.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/CLI.md b/docs/CLI.md index 4479ccb8e180..69cfe230cdd7 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -302,6 +302,10 @@ Print your Jest config and then exits. Prevent tests from printing messages through the console. +### `--testEnvironmentOptions` + +A JSON string with options that will be passed to the `testEnvironment`. The relevant options depend on the environment. + ### `--testNamePattern=` Alias: `-t`. Run only tests with a name that matches the regex. For example, suppose you want to run only tests related to authorization which will have names like `"GET /api/posts with auth"`, then you can use `jest -t=auth`. From 8b8e972ffdb46412446ea6768dbb04b991783a97 Mon Sep 17 00:00:00 2001 From: mrazauskas <72159681+mrazauskas@users.noreply.github.com> Date: Tue, 28 Sep 2021 12:08:18 +0300 Subject: [PATCH 5/9] chore: update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b4a2eb0d65bc..28f5f853277c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ ### Fixes - `[jest-reporters]` Call `destroy` on `v8-to-istanbul` converters to free memory ([#11896](https://github.com/facebook/jest/pull/11896)) -- `[jest-cli]` Improve description of `testEnvironmentOptions` option ([#11902](https://github.com/facebook/jest/pull/11902)) +- `[jest-config]` Parse JSON string `testEnvironmentOptions` received from CLI ([#11902](https://github.com/facebook/jest/pull/11902)) ### Chore & Maintenance From a65fda5a111ac8ddedf2011400ee064aa06c9cca Mon Sep 17 00:00:00 2001 From: mrazauskas <72159681+mrazauskas@users.noreply.github.com> Date: Tue, 28 Sep 2021 12:13:33 +0300 Subject: [PATCH 6/9] chore: update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28f5f853277c..af53effaa488 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ ### Fixes - `[jest-reporters]` Call `destroy` on `v8-to-istanbul` converters to free memory ([#11896](https://github.com/facebook/jest/pull/11896)) -- `[jest-config]` Parse JSON string `testEnvironmentOptions` received from CLI ([#11902](https://github.com/facebook/jest/pull/11902)) +- `[jest-config]` Parse `testEnvironmentOptions` if received from CLI ([#11902](https://github.com/facebook/jest/pull/11902)) ### Chore & Maintenance From 0c247a646874e2dd5e73fccba4ee42be3aac1ecf Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Tue, 28 Sep 2021 11:15:00 +0200 Subject: [PATCH 7/9] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index af53effaa488..eb17b7e359c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,8 +6,8 @@ ### Fixes -- `[jest-reporters]` Call `destroy` on `v8-to-istanbul` converters to free memory ([#11896](https://github.com/facebook/jest/pull/11896)) - `[jest-config]` Parse `testEnvironmentOptions` if received from CLI ([#11902](https://github.com/facebook/jest/pull/11902)) +- `[jest-reporters]` Call `destroy` on `v8-to-istanbul` converters to free memory ([#11896](https://github.com/facebook/jest/pull/11896)) ### Chore & Maintenance From 1e7bff35ce78263fe77d7e3f3a1c5e7913ad0918 Mon Sep 17 00:00:00 2001 From: mrazauskas <72159681+mrazauskas@users.noreply.github.com> Date: Tue, 28 Sep 2021 12:17:33 +0300 Subject: [PATCH 8/9] add versioned docs --- website/versioned_docs/version-27.2/CLI.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/website/versioned_docs/version-27.2/CLI.md b/website/versioned_docs/version-27.2/CLI.md index 4479ccb8e180..69cfe230cdd7 100644 --- a/website/versioned_docs/version-27.2/CLI.md +++ b/website/versioned_docs/version-27.2/CLI.md @@ -302,6 +302,10 @@ Print your Jest config and then exits. Prevent tests from printing messages through the console. +### `--testEnvironmentOptions` + +A JSON string with options that will be passed to the `testEnvironment`. The relevant options depend on the environment. + ### `--testNamePattern=` Alias: `-t`. Run only tests with a name that matches the regex. For example, suppose you want to run only tests related to authorization which will have names like `"GET /api/posts with auth"`, then you can use `jest -t=auth`. From 85311c66afd0dd76257db3706a2a013cf1219512 Mon Sep 17 00:00:00 2001 From: mrazauskas <72159681+mrazauskas@users.noreply.github.com> Date: Tue, 28 Sep 2021 12:48:01 +0300 Subject: [PATCH 9/9] docs: add `json string` type --- docs/CLI.md | 2 +- website/versioned_docs/version-27.2/CLI.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/CLI.md b/docs/CLI.md index 69cfe230cdd7..dfc34da58456 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -302,7 +302,7 @@ Print your Jest config and then exits. Prevent tests from printing messages through the console. -### `--testEnvironmentOptions` +### `--testEnvironmentOptions=` A JSON string with options that will be passed to the `testEnvironment`. The relevant options depend on the environment. diff --git a/website/versioned_docs/version-27.2/CLI.md b/website/versioned_docs/version-27.2/CLI.md index 69cfe230cdd7..dfc34da58456 100644 --- a/website/versioned_docs/version-27.2/CLI.md +++ b/website/versioned_docs/version-27.2/CLI.md @@ -302,7 +302,7 @@ Print your Jest config and then exits. Prevent tests from printing messages through the console. -### `--testEnvironmentOptions` +### `--testEnvironmentOptions=` A JSON string with options that will be passed to the `testEnvironment`. The relevant options depend on the environment.