From b224e7c7322ec102f5450f6b061022499c0176d1 Mon Sep 17 00:00:00 2001 From: Michal Jez Date: Tue, 13 Aug 2024 03:29:23 -0400 Subject: [PATCH] feat(testing): support positional arg for jest executor (#27328) ## Current Behavior The syntax to test a single file is different when using the jest executor versus the jest cli ```sh jest # vs nx test project --testFile ``` ## Expected Behavior I would expect the jest executor to support a single positional argument as well ```sh nx test project ``` This is one of the common questions/complaints that I hear from developers when transitioning from our standalone apps to our monorepo This change supports both syntaxes so that this is not a breaking change and prints a warning when both are used --- docs/generated/packages/jest/documents/overview.md | 10 ++++++++++ docs/generated/packages/jest/executors/jest.json | 3 ++- docs/shared/packages/jest/jest-plugin.md | 10 ++++++++++ packages/jest/src/executors/jest/schema.json | 6 +++++- 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/docs/generated/packages/jest/documents/overview.md b/docs/generated/packages/jest/documents/overview.md index 2012ffe1f091b..7923cb998e1e2 100644 --- a/docs/generated/packages/jest/documents/overview.md +++ b/docs/generated/packages/jest/documents/overview.md @@ -161,6 +161,16 @@ To run Jest tests via nx use nx test frontend ``` +### Testing Specific Files + +Using a single positional argument or the `--testFile` flag will run all test files matching the regex. For more info check out the [Jest documentation](https://jestjs.io/docs/cli#jest-regexfortestfiles). + +```shell +nx test frontend HomePage.tsx +# or +nx test frontend --testFile HomePage.tsx +``` + ### Watching for Changes Using the `--watch` flag will run the tests whenever a file changes. diff --git a/docs/generated/packages/jest/executors/jest.json b/docs/generated/packages/jest/executors/jest.json index 07818365c09ae..321c0d1e222c2 100644 --- a/docs/generated/packages/jest/executors/jest.json +++ b/docs/generated/packages/jest/executors/jest.json @@ -51,7 +51,8 @@ }, "testFile": { "description": "The name of the file to test.", - "type": "string" + "type": "string", + "$default": { "$source": "argv", "index": 0 } }, "tsConfig": { "description": "The name of the Typescript configuration file.", diff --git a/docs/shared/packages/jest/jest-plugin.md b/docs/shared/packages/jest/jest-plugin.md index 2012ffe1f091b..7923cb998e1e2 100644 --- a/docs/shared/packages/jest/jest-plugin.md +++ b/docs/shared/packages/jest/jest-plugin.md @@ -161,6 +161,16 @@ To run Jest tests via nx use nx test frontend ``` +### Testing Specific Files + +Using a single positional argument or the `--testFile` flag will run all test files matching the regex. For more info check out the [Jest documentation](https://jestjs.io/docs/cli#jest-regexfortestfiles). + +```shell +nx test frontend HomePage.tsx +# or +nx test frontend --testFile HomePage.tsx +``` + ### Watching for Changes Using the `--watch` flag will run the tests whenever a file changes. diff --git a/packages/jest/src/executors/jest/schema.json b/packages/jest/src/executors/jest/schema.json index 3c1aed561e417..708e33a399c4c 100644 --- a/packages/jest/src/executors/jest/schema.json +++ b/packages/jest/src/executors/jest/schema.json @@ -53,7 +53,11 @@ }, "testFile": { "description": "The name of the file to test.", - "type": "string" + "type": "string", + "$default": { + "$source": "argv", + "index": 0 + } }, "tsConfig": { "description": "The name of the Typescript configuration file.",