Skip to content

Commit 6438a6b

Browse files
committed
feat(rstack): add help for Rstest commands
1 parent ebece5e commit 6438a6b

3 files changed

Lines changed: 293 additions & 0 deletions

File tree

packages/rstack/src/cli/commands.ts

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,139 @@ const renderPreviewHelp = (): string =>
110110
],
111111
});
112112

113+
const renderTestHelp = (): string =>
114+
renderHelp({
115+
usage: 'rs test [command] [...filters] [options]',
116+
sections: [
117+
{
118+
title: 'Commands',
119+
items: [
120+
['[...filters]', 'Run tests (default)'],
121+
['run [...filters]', 'Run tests once'],
122+
['watch [...filters]', 'Run tests in watch mode'],
123+
['list [...filters]', 'List matching tests'],
124+
['merge-reports [path]', 'Merge blob reports'],
125+
['init [project]', 'Initialize Rstest configuration'],
126+
],
127+
},
128+
{
129+
content: `For command-specific options, run:
130+
$ rs test <command> -h`,
131+
dim: true,
132+
},
133+
{
134+
title: 'Options',
135+
items: [
136+
['-w, --watch', 'Enable watch mode'],
137+
['-u, --update', 'Update snapshot files'],
138+
['--coverage', 'Enable code coverage'],
139+
['--project <name>', 'Filter test projects by name'],
140+
['-t, --test-name-pattern <pattern>', 'Run tests with names matching the pattern'],
141+
['-c, --config <path>', 'Specify Rstack config file path'],
142+
['-h, --help', 'Display this help message'],
143+
],
144+
},
145+
],
146+
});
147+
148+
const renderTestRunHelp = (): string =>
149+
renderHelp({
150+
usage: 'rs test run [...filters] [options]',
151+
description: 'Run tests once',
152+
sections: [
153+
{
154+
title: 'Options',
155+
items: [
156+
['--related', 'Run tests related to source files'],
157+
['--changed [commit]', 'Run tests related to changed files'],
158+
['--shard <index/count>', 'Split tests into shards'],
159+
['-u, --update', 'Update snapshot files'],
160+
['--coverage', 'Enable code coverage'],
161+
['--project <name>', 'Filter test projects by name'],
162+
['-t, --test-name-pattern <pattern>', 'Run tests with names matching the pattern'],
163+
['-c, --config <path>', 'Specify Rstack config file path'],
164+
['-h, --help', 'Display this help message'],
165+
],
166+
},
167+
],
168+
});
169+
170+
const renderTestWatchHelp = (): string =>
171+
renderHelp({
172+
usage: 'rs test watch [...filters] [options]',
173+
description: 'Run tests in watch mode',
174+
sections: [
175+
{
176+
title: 'Options',
177+
items: [
178+
['-u, --update', 'Update snapshot files'],
179+
['--coverage', 'Enable code coverage'],
180+
['--project <name>', 'Filter test projects by name'],
181+
['-t, --test-name-pattern <pattern>', 'Run tests with names matching the pattern'],
182+
['-c, --config <path>', 'Specify Rstack config file path'],
183+
['-h, --help', 'Display this help message'],
184+
],
185+
},
186+
],
187+
});
188+
189+
const renderTestListHelp = (): string =>
190+
renderHelp({
191+
usage: 'rs test list [...filters] [options]',
192+
description: 'List matching tests',
193+
sections: [
194+
{
195+
title: 'Options',
196+
items: [
197+
['--related', 'List tests related to source files'],
198+
['--changed [commit]', 'List tests related to changed files'],
199+
['--files-only', 'List matching test files only'],
200+
['--json [path]', 'Print JSON or write it to a file'],
201+
['--include-suites', 'Include test suites'],
202+
['--print-location', 'Print test locations'],
203+
['--summary', 'Print a summary'],
204+
['--project <name>', 'Filter test projects by name'],
205+
['-t, --test-name-pattern <pattern>', 'List tests with names matching the pattern'],
206+
['-c, --config <path>', 'Specify Rstack config file path'],
207+
['-h, --help', 'Display this help message'],
208+
],
209+
},
210+
],
211+
});
212+
213+
const renderTestMergeReportsHelp = (): string =>
214+
renderHelp({
215+
usage: 'rs test merge-reports [path] [options]',
216+
description: 'Merge blob reports',
217+
sections: [
218+
{
219+
title: 'Options',
220+
items: [
221+
['--coverage', 'Generate coverage reports'],
222+
['--reporters, --reporter <name>', 'Specify test reporters'],
223+
['--cleanup', 'Remove blob reports after merging'],
224+
['-c, --config <path>', 'Specify Rstack config file path'],
225+
['-h, --help', 'Display this help message'],
226+
],
227+
},
228+
],
229+
});
230+
231+
const renderTestInitHelp = (): string =>
232+
renderHelp({
233+
usage: 'rs test init [project] [options]',
234+
description: 'Initialize Rstest configuration',
235+
sections: [
236+
{
237+
title: 'Options',
238+
items: [
239+
['--yes', 'Use default options without prompts'],
240+
['-h, --help', 'Display this help message'],
241+
],
242+
},
243+
],
244+
});
245+
113246
const renderLibHelp = (): string =>
114247
renderHelp({
115248
usage: 'rs lib [command] [options]',
@@ -214,6 +347,29 @@ async function runRsbuildCLI(args: string[]): Promise<void> {
214347
}
215348

216349
async function runRstestCLI(args: string[]): Promise<void> {
350+
if (hasHelpFlag(args)) {
351+
switch (args[0]) {
352+
case 'run':
353+
console.log(renderTestRunHelp());
354+
return;
355+
case 'watch':
356+
console.log(renderTestWatchHelp());
357+
return;
358+
case 'list':
359+
console.log(renderTestListHelp());
360+
return;
361+
case 'merge-reports':
362+
console.log(renderTestMergeReportsHelp());
363+
return;
364+
case 'init':
365+
console.log(renderTestInitHelp());
366+
return;
367+
default:
368+
console.log(renderTestHelp());
369+
return;
370+
}
371+
}
372+
217373
const argv = [
218374
process.execPath,
219375
'rstest',

packages/rstack/tests/cli/__snapshots__/help.test.ts.snap

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,127 @@ Options:
121121
"
122122
`;
123123
124+
exports[`displays test help 1`] = `
125+
"Rstack v<version>
126+
127+
Usage:
128+
$ rs test [command] [...filters] [options]
129+
130+
Commands:
131+
[...filters] Run tests (default)
132+
run [...filters] Run tests once
133+
watch [...filters] Run tests in watch mode
134+
list [...filters] List matching tests
135+
merge-reports [path] Merge blob reports
136+
init [project] Initialize Rstest configuration
137+
138+
For command-specific options, run:
139+
$ rs test <command> -h
140+
141+
Options:
142+
-w, --watch Enable watch mode
143+
-u, --update Update snapshot files
144+
--coverage Enable code coverage
145+
--project <name> Filter test projects by name
146+
-t, --test-name-pattern <pattern> Run tests with names matching the pattern
147+
-c, --config <path> Specify Rstack config file path
148+
-h, --help Display this help message
149+
"
150+
`;
151+
152+
exports[`displays test init help 1`] = `
153+
"Rstack v<version>
154+
155+
Usage:
156+
$ rs test init [project] [options]
157+
158+
Initialize Rstest configuration
159+
160+
Options:
161+
--yes Use default options without prompts
162+
-h, --help Display this help message
163+
"
164+
`;
165+
166+
exports[`displays test list help 1`] = `
167+
"Rstack v<version>
168+
169+
Usage:
170+
$ rs test list [...filters] [options]
171+
172+
List matching tests
173+
174+
Options:
175+
--related List tests related to source files
176+
--changed [commit] List tests related to changed files
177+
--files-only List matching test files only
178+
--json [path] Print JSON or write it to a file
179+
--include-suites Include test suites
180+
--print-location Print test locations
181+
--summary Print a summary
182+
--project <name> Filter test projects by name
183+
-t, --test-name-pattern <pattern> List tests with names matching the pattern
184+
-c, --config <path> Specify Rstack config file path
185+
-h, --help Display this help message
186+
"
187+
`;
188+
189+
exports[`displays test merge-reports help 1`] = `
190+
"Rstack v<version>
191+
192+
Usage:
193+
$ rs test merge-reports [path] [options]
194+
195+
Merge blob reports
196+
197+
Options:
198+
--coverage Generate coverage reports
199+
--reporters, --reporter <name> Specify test reporters
200+
--cleanup Remove blob reports after merging
201+
-c, --config <path> Specify Rstack config file path
202+
-h, --help Display this help message
203+
"
204+
`;
205+
206+
exports[`displays test run help 1`] = `
207+
"Rstack v<version>
208+
209+
Usage:
210+
$ rs test run [...filters] [options]
211+
212+
Run tests once
213+
214+
Options:
215+
--related Run tests related to source files
216+
--changed [commit] Run tests related to changed files
217+
--shard <index/count> Split tests into shards
218+
-u, --update Update snapshot files
219+
--coverage Enable code coverage
220+
--project <name> Filter test projects by name
221+
-t, --test-name-pattern <pattern> Run tests with names matching the pattern
222+
-c, --config <path> Specify Rstack config file path
223+
-h, --help Display this help message
224+
"
225+
`;
226+
227+
exports[`displays test watch help 1`] = `
228+
"Rstack v<version>
229+
230+
Usage:
231+
$ rs test watch [...filters] [options]
232+
233+
Run tests in watch mode
234+
235+
Options:
236+
-u, --update Update snapshot files
237+
--coverage Enable code coverage
238+
--project <name> Filter test projects by name
239+
-t, --test-name-pattern <pattern> Run tests with names matching the pattern
240+
-c, --config <path> Specify Rstack config file path
241+
-h, --help Display this help message
242+
"
243+
`;
244+
124245
exports[`displays top-level help 1`] = `
125246
"Rstack v<version>
126247

packages/rstack/tests/cli/help.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,19 @@ for (const command of ['lib', 'lib build', 'lib inspect', 'lib mf-dev']) {
2929
expect(normalizeHelpOutput(output)).toMatchSnapshot();
3030
});
3131
}
32+
33+
for (const command of [
34+
'test',
35+
'test run',
36+
'test watch',
37+
'test list',
38+
'test merge-reports',
39+
'test init',
40+
]) {
41+
test(`displays ${command} help`, ({ execCli, expect }) => {
42+
const output = execCli(`${command} --help`);
43+
44+
expect(execCli(`${command} -h`)).toBe(output);
45+
expect(normalizeHelpOutput(output)).toMatchSnapshot();
46+
});
47+
}

0 commit comments

Comments
 (0)