Skip to content

Commit

Permalink
Feat: pass along Jest testNamePattern argument if provided (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
danibrutal authored Oct 3, 2024
1 parent 374043e commit 15f3de0
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/great-mayflies-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-native-owl': minor
---

Ability to pass along Jest testNamePattern when the argument is provided
12 changes: 7 additions & 5 deletions docs/cli/testing-the-app.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
9 changes: 8 additions & 1 deletion lib/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
Expand All @@ -44,6 +50,7 @@ const builderOptionsTest = {
config: configOption,
platform: plaformOption,
update: updateOption,
testNamePattern: testNamePattern,
testPathPattern: testPathPatternOption,
};

Expand Down
4 changes: 4 additions & 0 deletions lib/cli/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface CliRunOptions extends Arguments {
platform: Platform;
config: string;
update: boolean;
testNamePattern: string;
testPathPattern: string;
}

Expand Down

0 comments on commit 15f3de0

Please sign in to comment.