Skip to content

Commit

Permalink
feat: Add testPathPattern option for running specific tests (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
kagrawal98 authored Oct 1, 2024
1 parent eb595a4 commit 099008a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/rude-mayflies-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-native-owl': minor
---

implements a new `testPathPattern` option for the CLI, allowing users to run tests for specific path patterns.
8 changes: 8 additions & 0 deletions lib/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ const updateOption: Options = {
default: false,
};

const testPathPatternOption: Options = {
alias: 't',
describe: 'Run Test for a matching path pattern',
type: 'string',
default: '',
};

const builderOptionsRun = {
config: configOption,
platform: plaformOption,
Expand All @@ -37,6 +44,7 @@ const builderOptionsTest = {
config: configOption,
platform: plaformOption,
update: updateOption,
testPathPattern: testPathPatternOption,
};

argv
Expand Down
29 changes: 29 additions & 0 deletions lib/cli/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,5 +302,34 @@ describe('run.ts', () => {
await expect(mockGenerateReport).not.toHaveBeenCalled();
}
});

it('runs with a specific testPathPattern', async () => {
jest.spyOn(configHelpers, 'getConfig').mockResolvedValueOnce(config);
const mockRunIOS = jest.spyOn(run, 'runIOS').mockResolvedValueOnce();

const testPathPattern = '*';
await run.runHandler({ ...args, testPathPattern });

await expect(mockRunIOS).toHaveBeenCalled();
await expect(commandSyncMock).toHaveBeenCalledTimes(1);
await expect(commandSyncMock).toHaveBeenCalledWith(
`${expectedJestCommand} --globals='{\"OWL_CLI_ARGS\":{\"platform\":\"ios\",\"config\":\"./owl.config.json\",\"update\":false,\"testPathPattern\":\"${testPathPattern}\"}}' --testPathPattern="${testPathPattern}"`,
expect.anything()
);
});

it('runs without a testPathPattern', async () => {
jest.spyOn(configHelpers, 'getConfig').mockResolvedValueOnce(config);
const mockRunIOS = jest.spyOn(run, 'runIOS').mockResolvedValueOnce();

await run.runHandler(args);

await expect(mockRunIOS).toHaveBeenCalled();
await expect(commandSyncMock).toHaveBeenCalledTimes(1);
await expect(commandSyncMock).toHaveBeenCalledWith(
`${expectedJestCommand} --globals='{\"OWL_CLI_ARGS\":{\"platform\":\"ios\",\"config\":\"./owl.config.json\",\"update\":false}}'`,
expect.anything()
);
});
});
});
4 changes: 4 additions & 0 deletions lib/cli/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ export const runHandler = async (args: CliRunOptions) => {
`--globals='${JSON.stringify({ OWL_CLI_ARGS: args })}'`,
];

if (args.testPathPattern) {
jestCommandArgs.push('--testPathPattern="' + args.testPathPattern + '"');
}

if (config.report) {
const reportDirPath = path.join(cwd, '.owl', 'report');
const outputFile = path.join(reportDirPath, 'jest-report.json');
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;
testPathPattern: string;
}

export type ConfigEnv = {
Expand Down

0 comments on commit 099008a

Please sign in to comment.