Skip to content

Commit

Permalink
fix(jest-config): parse testEnvironmentOptions if received from CLI (
Browse files Browse the repository at this point in the history
  • Loading branch information
mrazauskas authored Sep 28, 2021
1 parent 8024306 commit 7e40893
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

### Fixes

- `[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
Expand Down
4 changes: 4 additions & 0 deletions docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ Print your Jest config and then exits.

Prevent tests from printing messages through the console.

### `--testEnvironmentOptions=<json string>`

A JSON string with options that will be passed to the `testEnvironment`. The relevant options depend on the environment.

### `--testNamePattern=<regex>`

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`.
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-cli/src/cli/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 4 additions & 0 deletions packages/jest-config/src/__tests__/setFromArgv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,17 @@ test('works with string objects', () => {
const argv = {
moduleNameMapper:
'{"types/(.*)": "<rootDir>/src/types/$1", "types2/(.*)": ["<rootDir>/src/types2/$1", "<rootDir>/src/types3/$1"]}',
testEnvironmentOptions: '{"userAgent": "Agent/007"}',
transform: '{"*.js": "<rootDir>/transformer"}',
} as Config.Argv;
expect(setFromArgv(options, argv)).toMatchObject({
moduleNameMapper: {
'types/(.*)': '<rootDir>/src/types/$1',
'types2/(.*)': ['<rootDir>/src/types2/$1', '<rootDir>/src/types3/$1'],
},
testEnvironmentOptions: {
userAgent: 'Agent/007',
},
transform: {
'*.js': '<rootDir>/transformer',
},
Expand Down
3 changes: 2 additions & 1 deletion packages/jest-config/src/setFromArgv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions packages/jest-types/src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ export type Argv = Arguments<
silent: boolean;
snapshotSerializers: Array<string>;
testEnvironment: string;
testEnvironmentOptions: string;
testFailureExitCode: string | null | undefined;
testMatch: Array<string>;
testNamePattern: string;
Expand Down
4 changes: 4 additions & 0 deletions website/versioned_docs/version-27.2/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ Print your Jest config and then exits.

Prevent tests from printing messages through the console.

### `--testEnvironmentOptions=<json string>`

A JSON string with options that will be passed to the `testEnvironment`. The relevant options depend on the environment.

### `--testNamePattern=<regex>`

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`.
Expand Down

0 comments on commit 7e40893

Please sign in to comment.