Skip to content

Commit 9b7c9b6

Browse files
authored
feat(core): support custom runCLI argv (#1500)
1 parent 3d51880 commit 9b7c9b6

3 files changed

Lines changed: 13 additions & 5 deletions

File tree

packages/core/src/cli/commands.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,7 @@ export function createCli(): CAC {
11501150
return cli;
11511151
}
11521152

1153-
export function setupCommands(): void {
1153+
export function setupCommands(argv: string[]): void {
11541154
const cli = createCli();
1155-
cli.parse(process.argv);
1155+
cli.parse(argv);
11561156
}

packages/core/src/cli/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@ import { prepareCli } from './prepare';
44

55
export { initCli } from './init';
66

7-
export function runCLI(): void {
7+
export type RunCLIOptions = {
8+
/**
9+
* The command-line arguments to parse, matching the shape of Node.js `process.argv`
10+
* @default process.argv
11+
*/
12+
argv?: string[];
13+
};
14+
15+
export function runCLI({ argv = process.argv }: RunCLIOptions = {}): void {
816
prepareCli();
917

1018
try {
11-
setupCommands();
19+
setupCommands(argv);
1220
} catch (err) {
1321
logger.error('Failed to start Rstest CLI.');
1422
logger.error(err);

packages/core/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type {
88
RstestConfig,
99
} from './types';
1010

11-
export { initCli, runCLI } from './cli';
11+
export { initCli, runCLI, type RunCLIOptions } from './cli';
1212
export { loadConfig, mergeProjectConfig, mergeRstestConfig } from './config';
1313
export { createRstest } from './core';
1414
export * from './runtime/api/public';

0 commit comments

Comments
 (0)