From 15f3de02b6f0cc5cb2f28459eb7071fa841e0c00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=ADnez?= Date: Thu, 3 Oct 2024 22:51:12 +0200 Subject: [PATCH] Feat: pass along Jest testNamePattern argument if provided (#182) --- .changeset/great-mayflies-explain.md | 5 +++++ docs/cli/testing-the-app.mdx | 12 +++++++----- lib/cli/index.ts | 9 ++++++++- lib/cli/run.ts | 4 ++++ lib/types.ts | 1 + 5 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 .changeset/great-mayflies-explain.md diff --git a/.changeset/great-mayflies-explain.md b/.changeset/great-mayflies-explain.md new file mode 100644 index 00000000..cda555ae --- /dev/null +++ b/.changeset/great-mayflies-explain.md @@ -0,0 +1,5 @@ +--- +'react-native-owl': minor +--- + +Ability to pass along Jest testNamePattern when the argument is provided diff --git a/docs/cli/testing-the-app.mdx b/docs/cli/testing-the-app.mdx index 5f2dec32..d5811db8 100644 --- a/docs/cli/testing-the-app.mdx +++ b/docs/cli/testing-the-app.mdx @@ -11,11 +11,13 @@ Use the `test` command to run the app on the simulator, either comparing screens #### Options -| Name | Required | Default | Options/Types | Description | -| ------------------ | -------- | ----------------- | --------------- | ----------------------------------------------- | -| `--config`, `-c` | false | ./owl.config.json | String | Path to the configuration file | -| `--platform`, `-p` | true | - | `ios`,`android` | The platform the app should be built on | -| `--update`, `-u` | true | false | Boolean | A flag about rewriting existing baseline images | +| Name | Required | Default | Options/Types | Description | +| ------------------------- | -------- | ----------------- | --------------- | ------------------------------------------------- | +| `--config`, `-c` | false | ./owl.config.json | String | Path to the configuration file | +| `--platform`, `-p` | true | - | `ios`,`android` | The platform the app should be built on | +| `--update`, `-u` | true | false | Boolean | A flag about rewriting existing baseline images | +| `--testNamePattern`, `-t` | false | false | String | Run only tests with a name that matches the regex | +| `--testPathPattern`, `-p` | false | false | String | A regexp string matched against all tests path | When comparing images, any difference in the current vs baseline will fail the test. diff --git a/lib/cli/index.ts b/lib/cli/index.ts index 0104ea22..aa7e3775 100644 --- a/lib/cli/index.ts +++ b/lib/cli/index.ts @@ -28,8 +28,14 @@ const updateOption: Options = { default: false, }; -const testPathPatternOption: Options = { +const testNamePattern: Options = { alias: 't', + describe: 'Run only tests with a name that matches the regex', + type: 'string', +}; + +const testPathPatternOption: Options = { + alias: 'p', describe: 'Run Test for a matching path pattern', type: 'string', default: '', @@ -44,6 +50,7 @@ const builderOptionsTest = { config: configOption, platform: plaformOption, update: updateOption, + testNamePattern: testNamePattern, testPathPattern: testPathPatternOption, }; diff --git a/lib/cli/run.ts b/lib/cli/run.ts index 9b84ff62..1b175a9a 100644 --- a/lib/cli/run.ts +++ b/lib/cli/run.ts @@ -136,6 +136,10 @@ export const runHandler = async (args: CliRunOptions) => { jestCommandArgs.push(`--json --outputFile=${outputFile}`); } + if (args.testNamePattern) { + jestCommandArgs.push(`-t`, `${args.testNamePattern}`); + } + const jestCommand = jestCommandArgs.join(' '); logger.print( diff --git a/lib/types.ts b/lib/types.ts index 4249fbcd..a6357965 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -11,6 +11,7 @@ export interface CliRunOptions extends Arguments { platform: Platform; config: string; update: boolean; + testNamePattern: string; testPathPattern: string; }