Skip to content

Commit 099008a

Browse files
authored
feat: Add testPathPattern option for running specific tests (#180)
1 parent eb595a4 commit 099008a

File tree

5 files changed

+47
-0
lines changed

5 files changed

+47
-0
lines changed

.changeset/rude-mayflies-sit.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'react-native-owl': minor
3+
---
4+
5+
implements a new `testPathPattern` option for the CLI, allowing users to run tests for specific path patterns.

lib/cli/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ const updateOption: Options = {
2828
default: false,
2929
};
3030

31+
const testPathPatternOption: Options = {
32+
alias: 't',
33+
describe: 'Run Test for a matching path pattern',
34+
type: 'string',
35+
default: '',
36+
};
37+
3138
const builderOptionsRun = {
3239
config: configOption,
3340
platform: plaformOption,
@@ -37,6 +44,7 @@ const builderOptionsTest = {
3744
config: configOption,
3845
platform: plaformOption,
3946
update: updateOption,
47+
testPathPattern: testPathPatternOption,
4048
};
4149

4250
argv

lib/cli/run.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,5 +302,34 @@ describe('run.ts', () => {
302302
await expect(mockGenerateReport).not.toHaveBeenCalled();
303303
}
304304
});
305+
306+
it('runs with a specific testPathPattern', async () => {
307+
jest.spyOn(configHelpers, 'getConfig').mockResolvedValueOnce(config);
308+
const mockRunIOS = jest.spyOn(run, 'runIOS').mockResolvedValueOnce();
309+
310+
const testPathPattern = '*';
311+
await run.runHandler({ ...args, testPathPattern });
312+
313+
await expect(mockRunIOS).toHaveBeenCalled();
314+
await expect(commandSyncMock).toHaveBeenCalledTimes(1);
315+
await expect(commandSyncMock).toHaveBeenCalledWith(
316+
`${expectedJestCommand} --globals='{\"OWL_CLI_ARGS\":{\"platform\":\"ios\",\"config\":\"./owl.config.json\",\"update\":false,\"testPathPattern\":\"${testPathPattern}\"}}' --testPathPattern="${testPathPattern}"`,
317+
expect.anything()
318+
);
319+
});
320+
321+
it('runs without a testPathPattern', async () => {
322+
jest.spyOn(configHelpers, 'getConfig').mockResolvedValueOnce(config);
323+
const mockRunIOS = jest.spyOn(run, 'runIOS').mockResolvedValueOnce();
324+
325+
await run.runHandler(args);
326+
327+
await expect(mockRunIOS).toHaveBeenCalled();
328+
await expect(commandSyncMock).toHaveBeenCalledTimes(1);
329+
await expect(commandSyncMock).toHaveBeenCalledWith(
330+
`${expectedJestCommand} --globals='{\"OWL_CLI_ARGS\":{\"platform\":\"ios\",\"config\":\"./owl.config.json\",\"update\":false}}'`,
331+
expect.anything()
332+
);
333+
});
305334
});
306335
});

lib/cli/run.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ export const runHandler = async (args: CliRunOptions) => {
123123
`--globals='${JSON.stringify({ OWL_CLI_ARGS: args })}'`,
124124
];
125125

126+
if (args.testPathPattern) {
127+
jestCommandArgs.push('--testPathPattern="' + args.testPathPattern + '"');
128+
}
129+
126130
if (config.report) {
127131
const reportDirPath = path.join(cwd, '.owl', 'report');
128132
const outputFile = path.join(reportDirPath, 'jest-report.json');

lib/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface CliRunOptions extends Arguments {
1111
platform: Platform;
1212
config: string;
1313
update: boolean;
14+
testPathPattern: string;
1415
}
1516

1617
export type ConfigEnv = {

0 commit comments

Comments
 (0)