Skip to content

Commit 692fb72

Browse files
guyoron1kylehgc
authored andcommitted
fix(playwright): consume the value of a space-separated --reporter flag
'rtk playwright test --reporter list' stripped only the --reporter token, leaving 'list' behind as a positional argument. Playwright treats it as a test filter, so the run silently executes the wrong (usually empty) test set: 0 tests run, exit 1, 'No tests found'. Strip both --reporter=<name> and '--reporter <name>' (flag + value) before injecting the forced --reporter=json.
1 parent b296a81 commit 692fb72

1 file changed

Lines changed: 59 additions & 4 deletions

File tree

‎src/cmds/js/playwright_cmd.rs‎

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,31 @@ fn extract_failures_regex(output: &str) -> Vec<TestFailure> {
236236
failures
237237
}
238238

239+
/// Strip the user's `--reporter` flag so it can't conflict with the injected
240+
/// `--reporter=json`. Handles both `--reporter=<name>` and the space-separated
241+
/// `--reporter <name>` form — the latter must also consume the value, otherwise
242+
/// the bare reporter name (`list`, `dot`, ...) is left behind as a positional
243+
/// test-filter and Playwright silently runs the wrong (usually empty) test set.
244+
fn strip_reporter_args(args: &[String]) -> Vec<String> {
245+
let mut out = Vec::new();
246+
let mut skip_value = false;
247+
for arg in args {
248+
if skip_value {
249+
skip_value = false;
250+
continue;
251+
}
252+
if arg == "--reporter" {
253+
skip_value = true;
254+
continue;
255+
}
256+
if arg.starts_with("--reporter=") {
257+
continue;
258+
}
259+
out.push(arg.clone());
260+
}
261+
out
262+
}
263+
239264
pub fn run(args: &[String], verbose: u8) -> Result<i32> {
240265
let timer = tracking::TimedExecution::start();
241266

@@ -266,10 +291,8 @@ pub fn run(args: &[String], verbose: u8) -> Result<i32> {
266291
cmd.arg("test");
267292
cmd.arg("--reporter=json");
268293
// Strip user's --reporter to avoid conflicts with our forced JSON
269-
for arg in &args[1..] {
270-
if !arg.starts_with("--reporter") {
271-
cmd.arg(arg);
272-
}
294+
for arg in strip_reporter_args(&args[1..]) {
295+
cmd.arg(arg);
273296
}
274297
} else {
275298
for arg in args {
@@ -510,4 +533,36 @@ mod tests {
510533

511534
assert_eq!(filtered, combined);
512535
}
536+
537+
// --- --reporter stripping: space-separated form must consume its value ---
538+
539+
fn strings(args: &[&str]) -> Vec<String> {
540+
args.iter().map(|s| s.to_string()).collect()
541+
}
542+
543+
#[test]
544+
fn test_strip_reporter_space_form_consumes_value() {
545+
// `--reporter list` — the value must not survive as a positional
546+
// test filter (it would silently run the wrong test set).
547+
let result = strip_reporter_args(&strings(&["--reporter", "list", "e2e/login.spec.ts"]));
548+
assert_eq!(result, strings(&["e2e/login.spec.ts"]));
549+
}
550+
551+
#[test]
552+
fn test_strip_reporter_equals_form() {
553+
let result = strip_reporter_args(&strings(&["--reporter=dot", "e2e/login.spec.ts"]));
554+
assert_eq!(result, strings(&["e2e/login.spec.ts"]));
555+
}
556+
557+
#[test]
558+
fn test_strip_reporter_keeps_unrelated_args() {
559+
let result = strip_reporter_args(&strings(&["--workers=2", "--grep", "login"]));
560+
assert_eq!(result, strings(&["--workers=2", "--grep", "login"]));
561+
}
562+
563+
#[test]
564+
fn test_strip_reporter_trailing_flag_without_value() {
565+
let result = strip_reporter_args(&strings(&["spec.ts", "--reporter"]));
566+
assert_eq!(result, strings(&["spec.ts"]));
567+
}
513568
}

0 commit comments

Comments
 (0)