Skip to content

Commit eaf1d2d

Browse files
authored
feat(core): make --reporters the canonical CLI flag (#1299)
1 parent 0a3dd16 commit eaf1d2d

22 files changed

Lines changed: 93 additions & 74 deletions

File tree

e2e/projects/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ describe('test projects', () => {
197197
'run',
198198
'-c',
199199
'rstest.projectConfig.config.mts',
200-
'--reporter',
200+
'--reporters',
201201
'verbose',
202202
],
203203
options: {
@@ -230,7 +230,7 @@ describe('test projects', () => {
230230
'run',
231231
'-c',
232232
'rstest.slowTest.config.mts',
233-
'--reporter',
233+
'--reporters',
234234
'verbose',
235235
],
236236
options: {

e2e/reporter/githubActions.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ it.skipIf(!process.env.CI)('github-actions', async () => {
1515

1616
const { cli } = await runRstestCli({
1717
command: 'rstest',
18-
args: ['run', 'githubActions', '--reporter', 'github-actions'],
18+
args: ['run', 'githubActions', '--reporters', 'github-actions'],
1919
options: {
2020
nodeOptions: {
2121
cwd: __dirname,
@@ -93,7 +93,7 @@ it.skipIf(!process.env.CI)(
9393
async () => {
9494
const { cli } = await runRstestCli({
9595
command: 'rstest',
96-
args: ['run', 'githubActions', '--reporter', 'github-actions'],
96+
args: ['run', 'githubActions', '--reporters', 'github-actions'],
9797
options: {
9898
nodeOptions: {
9999
cwd: __dirname,
@@ -133,7 +133,7 @@ it.skipIf(!process.env.CI)('github-actions summary on pass', async () => {
133133
'run',
134134
'-c',
135135
'./rstest.agentMd.pass.config.mts',
136-
'--reporter',
136+
'--reporters',
137137
'github-actions',
138138
],
139139
options: {
@@ -198,7 +198,7 @@ it.skipIf(!process.env.CI)(
198198
'run',
199199
'-c',
200200
'./rstest.githubActions.flaky.config.mts',
201-
'--reporter',
201+
'--reporters',
202202
'github-actions',
203203
],
204204
options: {
@@ -255,7 +255,7 @@ it.skipIf(!process.env.CI)(
255255
'run',
256256
'-c',
257257
'./rstest.githubActions.namedProject.config.mts',
258-
'--reporter',
258+
'--reporters',
259259
'github-actions',
260260
],
261261
options: {
@@ -303,7 +303,7 @@ it.skipIf(!process.env.CI)(
303303
try {
304304
const { cli } = await runRstestCli({
305305
command: 'rstest',
306-
args: ['run', 'githubActions', '--reporter', 'github-actions'],
306+
args: ['run', 'githubActions', '--reporters', 'github-actions'],
307307
options: {
308308
nodeOptions: {
309309
cwd: __dirname,
@@ -348,7 +348,7 @@ it.skipIf(!process.env.CI)(
348348
'run',
349349
'-c',
350350
'./rstest.agentMd.pass.config.mts',
351-
'--reporter',
351+
'--reporters',
352352
'github-actions',
353353
],
354354
options: {
@@ -368,7 +368,7 @@ it.skipIf(!process.env.CI)(
368368

369369
const failingRun = await runRstestCli({
370370
command: 'rstest',
371-
args: ['run', 'githubActions', '--reporter', 'github-actions'],
371+
args: ['run', 'githubActions', '--reporters', 'github-actions'],
372372
options: {
373373
nodeOptions: {
374374
cwd: __dirname,

e2e/reporter/index.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe.concurrent('reporters', () => {
4545
it('verbose', async ({ onTestFinished }) => {
4646
const { cli } = await runRstestCli({
4747
command: 'rstest',
48-
args: ['run', 'fixtures/index.test.ts', '--reporter=verbose'],
48+
args: ['run', 'fixtures/index.test.ts', '--reporters=verbose'],
4949
onTestFinished,
5050
options: {
5151
nodeOptions: {
@@ -62,7 +62,7 @@ describe.concurrent('reporters', () => {
6262
it('dot', async ({ onTestFinished }) => {
6363
const { cli } = await runRstestCli({
6464
command: 'rstest',
65-
args: ['run', 'fixtures/index.test.ts', '--reporter=dot'],
65+
args: ['run', 'fixtures/index.test.ts', '--reporters=dot'],
6666
onTestFinished,
6767
options: {
6868
nodeOptions: {
@@ -110,7 +110,7 @@ describe.concurrent('reporters', () => {
110110
args: [
111111
'run',
112112
'fixtures/silent.test.ts',
113-
'--reporter=dot',
113+
'--reporters=dot',
114114
'--silent=passed-only',
115115
],
116116
onTestFinished,
@@ -237,7 +237,7 @@ describe.concurrent('reporters', () => {
237237
args: [
238238
'run',
239239
'fixtures/index.test.ts',
240-
'--reporter=verbose',
240+
'--reporters=verbose',
241241
'--hideSkippedTests',
242242
],
243243
onTestFinished,

e2e/reporter/json.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('json reporter', () => {
2020
it('should print structured JSON to stdout', async () => {
2121
const { cli } = await runRstestCli({
2222
command: 'rstest',
23-
args: ['run', 'junit', '--reporter', 'json'],
23+
args: ['run', 'junit', '--reporters', 'json'],
2424
options: {
2525
nodeOptions: {
2626
cwd: __dirname,

e2e/reporter/junit.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { runRstestCli } from '../scripts';
44
it('junit', async () => {
55
const { cli, expectLog } = await runRstestCli({
66
command: 'rstest',
7-
args: ['run', 'junit', '--reporter', 'junit'],
7+
args: ['run', 'junit', '--reporters', 'junit'],
88
options: {
99
nodeOptions: {
1010
cwd: __dirname,

e2e/reporter/mergeReports.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('merge-reports', () => {
2121
// Run shard 1/2 with blob reporter
2222
const { expectExecSuccess: shard1Success } = await runRstestCli({
2323
command: 'rstest',
24-
args: ['run', '--shard', '1/2', '--reporter=blob'],
24+
args: ['run', '--shard', '1/2', '--reporters=blob'],
2525
options: {
2626
nodeOptions: {
2727
cwd: fixturesDir,
@@ -38,7 +38,7 @@ describe('merge-reports', () => {
3838
// Run shard 2/2 with blob reporter
3939
const { expectExecSuccess: shard2Success } = await runRstestCli({
4040
command: 'rstest',
41-
args: ['run', '--shard', '2/2', '--reporter=blob'],
41+
args: ['run', '--shard', '2/2', '--reporters=blob'],
4242
options: {
4343
nodeOptions: {
4444
cwd: fixturesDir,
@@ -93,7 +93,7 @@ describe('merge-reports', () => {
9393
'run',
9494
'--shard',
9595
'1/2',
96-
'--reporter=blob',
96+
'--reporters=blob',
9797
'-c',
9898
'rstest.coverage.config.mts',
9999
],
@@ -118,7 +118,7 @@ describe('merge-reports', () => {
118118
'run',
119119
'--shard',
120120
'2/2',
121-
'--reporter=blob',
121+
'--reporters=blob',
122122
'-c',
123123
'rstest.coverage.config.mts',
124124
],

packages/core/src/cli/commands.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ const runtimeOptionDefinitions: OptionDefinition[] = [
8686
'--slowTestThreshold <value>',
8787
'The number of milliseconds after which a test or suite is considered slow',
8888
],
89-
['--reporter <reporter>', 'Specify the reporter to use'],
89+
['--reporters, --reporter <name>', 'Specify the reporter(s) to use'],
9090
[
9191
'-t, --testNamePattern <value>',
9292
'Run only tests with a name that matches the regex',
@@ -170,7 +170,7 @@ const mergeReportsOptionDefinitions: OptionDefinition[] = [
170170
'Specify the project root directory, can be an absolute path or a path relative to cwd',
171171
],
172172
['--coverage', 'Enable code coverage collection'],
173-
['--reporter <reporter>', 'Specify the reporter to use'],
173+
['--reporters, --reporter <name>', 'Specify the reporter(s) to use'],
174174
['--cleanup', 'Remove blob reports directory after merging'],
175175
];
176176

@@ -226,6 +226,7 @@ const valueTakingOptions = new Set([
226226
'--pool.type',
227227
'--project',
228228
'--reporter',
229+
'--reporters',
229230
'--retry',
230231
'--root',
231232
'--shard',

packages/core/src/cli/init.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export type CommonOptions = {
5151
isolate?: boolean;
5252
include?: string[];
5353
exclude?: string[];
54-
reporter?: string[];
54+
reporters?: string | string[];
5555
project?: string[];
5656
/**
5757
* Coverage options.
@@ -163,8 +163,8 @@ function mergeWithCLIOptions(
163163
config.passWithNoTests ??= true;
164164
}
165165

166-
if (options.reporter) {
167-
config.reporters = castArray(options.reporter) as typeof config.reporters;
166+
if (options.reporters) {
167+
config.reporters = castArray(options.reporters) as typeof config.reporters;
168168
}
169169

170170
if (options.shard) {
@@ -528,10 +528,10 @@ export async function initCli(options: CommonOptions): Promise<{
528528
});
529529

530530
// In agent environments, default to markdown output when the user didn't
531-
// explicitly set reporters (no `reporters` in config and no `--reporter`).
531+
// explicitly set reporters (no `reporters` in config and no `--reporters`).
532532
if (
533533
determineAgent().isAgent &&
534-
!options.reporter &&
534+
!options.reporters &&
535535
config.reporters == null
536536
) {
537537
config.reporters = ['md'];

packages/core/src/core/mergeReports.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function loadBlobFiles(blobDir: string): BlobData[] {
2222
if (!existsSync(blobDir)) {
2323
throw new Error(
2424
`Blob reports directory not found: ${color.cyan(blobDir)}\n` +
25-
'Run tests with --reporter=blob first to generate shard reports.',
25+
'Run tests with --reporters=blob first to generate shard reports.',
2626
);
2727
}
2828

@@ -33,7 +33,7 @@ function loadBlobFiles(blobDir: string): BlobData[] {
3333
if (files.length === 0) {
3434
throw new Error(
3535
`No blob report files found in: ${color.cyan(blobDir)}\n` +
36-
'Run tests with --reporter=blob first to generate shard reports.',
36+
'Run tests with --reporters=blob first to generate shard reports.',
3737
);
3838
}
3939

packages/core/tests/cli/commands.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,24 @@ describe('CLI help output', () => {
214214
name: 'chromium',
215215
});
216216
});
217+
218+
it('accepts --reporters and populates options.reporters', () => {
219+
const parsed = createCli().parse(
220+
['node', 'rstest', 'run', '--reporters', 'verbose'],
221+
{ run: false },
222+
);
223+
224+
expect(parsed.options.reporters).toBe('verbose');
225+
});
226+
227+
it('accepts legacy --reporter as an alias for --reporters', () => {
228+
const parsed = createCli().parse(
229+
['node', 'rstest', 'run', '--reporter', 'verbose', '--reporter=junit'],
230+
{ run: false },
231+
);
232+
233+
expect(parsed.options.reporters).toEqual(['verbose', 'junit']);
234+
});
217235
});
218236

219237
describe('normalizeCliFilters', () => {

0 commit comments

Comments
 (0)