Skip to content
Open
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
24 changes: 24 additions & 0 deletions e2e/cli/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,30 @@ describe.concurrent('test exit code', () => {
await expectExecSuccess();
});

it('should support --pool shorthand with nested pool options', async ({
onTestFinished,
}) => {
const { expectExecSuccess } = await runRstestCli({
command: 'rstest',
args: [
'run',
'success.test.ts',
'--pool',
'forks',
'--pool.maxWorkers',
'1',
],
onTestFinished,
options: {
nodeOptions: {
cwd: __dirname,
},
},
});

await expectExecSuccess();
});

it('should return code 1 and print error correctly when test config error', async ({
onTestFinished,
}) => {
Expand Down
28 changes: 25 additions & 3 deletions packages/core/src/cli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,34 @@ const normalizeCoverageCliArgs = (argv: string[]): string[] => {
});
};

const allowMixedCoverageCliOptions = (cli: CAC): void => {
const normalizePoolCliArgs = (argv: string[]): string[] => {
const hasPoolNestedOption = argv.some((arg) => arg.startsWith('--pool.'));

if (!hasPoolNestedOption) {
return argv;
}

return argv.map((arg) => {
if (arg === '--pool') {
return '--pool.type';
}
if (arg.startsWith('--pool=')) {
return `--pool.type=${arg.slice('--pool='.length)}`;
}

return arg;
});
};

const normalizeCliArgs = (argv: string[]): string[] =>
normalizePoolCliArgs(normalizeCoverageCliArgs(argv));

const normalizeMixedCliOptions = (cli: CAC): void => {
const originalParse = cli.parse.bind(cli);

cli.parse = ((argv, options) =>
originalParse(
normalizeCoverageCliArgs(argv ?? process.argv),
normalizeCliArgs(argv ?? process.argv),
options,
)) as CAC['parse'];
};
Expand Down Expand Up @@ -861,7 +883,7 @@ export function createCli(): CAC {
}
});

allowMixedCoverageCliOptions(cli);
normalizeMixedCliOptions(cli);

return cli;
}
Expand Down
12 changes: 12 additions & 0 deletions packages/core/tests/cli/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ describe('CLI help output', () => {
changed: 'HEAD',
});
});

it('allows --pool shorthand to be mixed with nested pool options', () => {
const parsed = createCli().parse(
['node', 'rstest', 'run', '--pool', 'forks', '--pool.maxWorkers', '1'],
{ run: false },
);

expect(parsed.options.pool).toEqual({
type: 'forks',
maxWorkers: 1,
});
});
});

describe('normalizeCliFilters', () => {
Expand Down
Loading