Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: pass along Jest testNamePattern argument if provided #182

Merged
merged 4 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the alias here to make it consistent with Jest documentation

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While technically a breaking change, this is a new feature that many users haven't upgraded to and its only a CLI and not a production dep, I think its fine to go ahead and merge.

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
Loading