diff --git a/scripts/test-group-report.mjs b/scripts/test-group-report.mjs index 9e3dfe4fd470..c17b312e2029 100644 --- a/scripts/test-group-report.mjs +++ b/scripts/test-group-report.mjs @@ -57,6 +57,14 @@ function usage() { ].join("\n"); } +function readRequiredValue(argv, index, flag) { + const value = argv[index + 1]; + if (!value || value.startsWith("--")) { + throw new Error(`${flag} requires a value`); + } + return value; +} + /** * Parses report, compare, and Vitest-run options for grouped test reports. */ @@ -102,30 +110,30 @@ export function parseTestGroupReportArgs(argv) { continue; } if (arg === "--config") { - args.configs.push(argv[index + 1] ?? ""); + args.configs.push(readRequiredValue(argv, index, "--config")); index += 1; continue; } if (arg === "--compare") { args.compare = { - before: argv[index + 1] ?? "", - after: argv[index + 2] ?? "", + before: readRequiredValue(argv, index, "--compare"), + after: readRequiredValue(argv, index + 1, "--compare"), }; index += 2; continue; } if (arg === "--report") { - args.reports.push(argv[index + 1] ?? ""); + args.reports.push(readRequiredValue(argv, index, "--report")); index += 1; continue; } if (arg === "--group-by") { - args.groupBy = argv[index + 1] ?? args.groupBy; + args.groupBy = readRequiredValue(argv, index, "--group-by"); index += 1; continue; } if (arg === "--output") { - args.output = argv[index + 1] ?? args.output; + args.output = readRequiredValue(argv, index, "--output"); index += 1; continue; } diff --git a/test/scripts/test-group-report.test.ts b/test/scripts/test-group-report.test.ts index 5e1358d49eea..9ff48d596d5a 100644 --- a/test/scripts/test-group-report.test.ts +++ b/test/scripts/test-group-report.test.ts @@ -389,6 +389,20 @@ describe("scripts/test-group-report arg parsing", () => { ); } }); + + it("rejects missing report path and config option values", () => { + for (const flag of ["--config", "--report", "--group-by", "--output"]) { + expect(() => parseTestGroupReportArgs([flag, "--limit", "5"])).toThrow( + `${flag} requires a value`, + ); + } + expect(() => parseTestGroupReportArgs(["--compare", "before.json", "--limit"])).toThrow( + "--compare requires a value", + ); + expect(() => parseTestGroupReportArgs(["--compare", "--limit", "5"])).toThrow( + "--compare requires a value", + ); + }); }); describe("scripts/test-group-report child process guard", () => {