1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//! E2E tests for the TypeScript mutation rule (#202): drive the built CLI binary
//! end-to-end (no mocks) against the fixture projects and assert the exit code.
//!
//! The binary spawns the bundled Node mutation adapter (#246); in production the npm
//! launcher appends its path as `--ts-mutation-adapter`, so these tests pass the freshly-built
//! adapter ([`common::ts_adapter`]) the same way on each invocation. The fixtures are
//! **runner-only** (vitest): the tool bundles and drives Stryker; the project provides only its
//! own test runner. Requires the built node adapter and the fixtures' vitest (`npm ci` in
//! `tests/fixtures/unit_mutation/typescript`).
//!
//! The gate is **on by default and binary** — parity with the Rust arm: an un-exempted
//! surviving mutant fails the run, and the only way to pass with a survivor present is a
//! reason-required `mutation` exemption. The fixtures are the standard pair: `killed`
//! (every mutant caught) and `survivors` (a coverage-passing but assertion-light suite
//! whose mutants all survive). Each test runs against its own staged copy so the
//! parallel Stryker runs never collide in a shared project dir.
mod common;
use std::path::{Path, PathBuf};
use std::process::Command;
use common::{ts_adapter, Staged};
fn fixtures() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/unit_mutation")
}
/// Exit code of `testing-conventions unit mutation --language typescript [--config <cfg>] <project>`,
/// passing the bundled adapter path as `--ts-mutation-adapter`, exactly as the npm launcher does.
fn unit_mutation_exit(project: &Path, config: Option<&str>) -> i32 {
let mut command = Command::new(env!("CARGO_BIN_EXE_testing-conventions"));
command
.args(["unit", "mutation", "--language", "typescript"])
.arg("--ts-mutation-adapter")
.arg(ts_adapter());
if let Some(config) = config {
command.arg("--config").arg(fixtures().join(config));
}
command
.arg(project)
.status()
.expect("the built binary should run")
.code()
.expect("the process should exit with a code")
}
#[test]
fn run_without_the_adapter_arg_fails_clean() {
// The npm launcher appends `--ts-mutation-adapter`; run directly without it, the TS arm
// must fail (exit 1) with a clear error naming the argument — never guess at a Node entry
// on disk.
let project = Staged::new("survivors");
let out = Command::new(env!("CARGO_BIN_EXE_testing-conventions"))
.args(["unit", "mutation", "--language", "typescript"])
.arg(project.path())
.output()
.expect("the built binary should run");
let stderr = String::from_utf8_lossy(&out.stderr);
assert_eq!(
out.status.code(),
Some(1),
"a missing adapter argument should fail the run; stderr: {stderr}"
);
assert!(
stderr.contains("--ts-mutation-adapter"),
"the error should name the adapter argument; got: {stderr}"
);
}
#[test]
fn a_broken_adapter_path_fails_clean() {
// The argument points at a Node entry that doesn't exist (node can't find the module):
// the run must fail (exit 1) with the adapter's captured output surfaced, not hang or
// pass. Covers the non-zero-exit path of the adapter spawn.
let project = Staged::new("survivors");
let out = Command::new(env!("CARGO_BIN_EXE_testing-conventions"))
.args(["unit", "mutation", "--language", "typescript"])
.arg("--ts-mutation-adapter")
.arg("/nonexistent/testing-conventions-adapter.js")
.arg(project.path())
.output()
.expect("the built binary should run");
let stderr = String::from_utf8_lossy(&out.stderr);
assert_eq!(
out.status.code(),
Some(1),
"a broken adapter path should fail the run; stderr: {stderr}"
);
assert!(
stderr.contains("adapter failed"),
"the error should report the adapter failure; got: {stderr}"
);
}
#[test]
fn killed_project_passes_with_no_survivors() {
// Every mutant is caught, so the project clears the gate.
let project = Staged::new("killed");
assert_eq!(unit_mutation_exit(project.path(), None), 0);
}
#[test]
fn survivors_fail_the_gate_by_default() {
// The gate is on by default and binary: an un-exempted surviving mutant fails the
// run, no config required.
let project = Staged::new("survivors");
assert_eq!(unit_mutation_exit(project.path(), None), 1);
}
#[test]
fn an_exempted_survivor_passes_the_gate() {
// The survivor's file carries a `mutation` exemption, so the gate clears it (an
// equivalent / deliberately-defensive mutation, lifted with a reason) — the only
// way to pass with a survivor present.
let project = Staged::new("survivors");
assert_eq!(
unit_mutation_exit(project.path(), Some("mutation_exempt_ts.toml")),
0
);
}