supercov 4.28.0 → 4.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -16
- package/docs/cli.md +322 -2
- package/docs/getting-started.md +18 -0
- package/docs/mutation.md +539 -0
- package/docs/supported-suites.md +109 -60
- package/package.json +11 -10
- package/runtime/javascript/atomic.mjs +6 -2
- package/runtime/javascript/ava.mjs +12 -0
- package/runtime/javascript/bunTest.mjs +17 -0
- package/runtime/javascript/jest.cjs +67 -0
- package/runtime/javascript/jest.config.mjs +46 -6
- package/runtime/javascript/jestReporter.mjs +5 -2
- package/runtime/javascript/mocha.mjs +79 -5
- package/runtime/javascript/nodeTest.mjs +28 -0
- package/runtime/javascript/playwright.mjs +33 -0
- package/runtime/javascript/playwrightStrong.mjs +477 -0
- package/runtime/javascript/playwrightStrongReporter.mjs +377 -0
- package/runtime/javascript/runnerEntry.mjs +62 -0
- package/runtime/javascript/runtime.mjs +752 -13
- package/runtime/javascript/snapshots.mjs +16 -1
- package/runtime/javascript/strongJestHost.mjs +103 -0
- package/runtime/javascript/strongJob.mjs +78 -0
- package/runtime/javascript/strongJobs.mjs +809 -0
- package/runtime/javascript/strongMochaHost.mjs +166 -0
- package/runtime/javascript/strongWasmOut.cjs +96 -0
- package/runtime/javascript/tap.mjs +43 -1
- package/runtime/javascript/transport.mjs +5 -0
- package/runtime/javascript/vitest.mjs +74 -2
- package/runtime/javascript/vitestBrowser.mjs +34 -2
- package/runtime/javascript/vitestStrong.mjs +234 -0
- package/runtime/javascript/vitestStrongReporter.mjs +2268 -0
- package/runtime/javascript/vitestStrongSpawner.mjs +248 -0
package/README.md
CHANGED
|
@@ -157,6 +157,28 @@ Answers are reused across runs whenever the question is the same, so after a
|
|
|
157
157
|
commit only what changed is asked again. Every language Supercov measures. See
|
|
158
158
|
[assertion coverage](docs/assertions.md).
|
|
159
159
|
|
|
160
|
+
## Check that the tests catch bugs
|
|
161
|
+
|
|
162
|
+
Mutation testing makes small changes to the code, such as `<` to `<=` or a
|
|
163
|
+
call removed, and checks that a test fails on each. A change every test passes
|
|
164
|
+
with is a check no test makes, even on a covered line:
|
|
165
|
+
|
|
166
|
+
```sh
|
|
167
|
+
npx supercov mutants -- npm test # every mutant, run against the tests that reach it
|
|
168
|
+
npx supercov mutants --diff origin/main # only the change's mutants, for a pull request
|
|
169
|
+
npx supercov runs latest mutants --diff origin/main --fail-on not-infected,not-reached
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Each language uses its established tool's mutants, and its verdicts were
|
|
173
|
+
compared with that tool's on public projects: StrykerJS for JavaScript and
|
|
174
|
+
TypeScript, under Vitest, Playwright, Jest, `node:test`, Mocha, AVA,
|
|
175
|
+
node-tap, `bun:test` and Vitest Browser Mode; and in preview, mutmut for
|
|
176
|
+
Python, cargo-mutants for Rust, Gremlins for Go and mutant for Ruby. The run already knows which tests reach
|
|
177
|
+
each mutant and which never change its value, so a mutant no test reaches or
|
|
178
|
+
infects is decided without running anything, and the rest run only against
|
|
179
|
+
the tests that can kill them. A plain run costs nothing more. See
|
|
180
|
+
[Mutation testing](docs/mutation.md).
|
|
181
|
+
|
|
160
182
|
## Give Supercov a job
|
|
161
183
|
|
|
162
184
|
Paste one of these prompts into Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, or any coding agent that can run terminal commands.
|
|
@@ -183,11 +205,12 @@ gemini extensions install https://github.com/supercorp-ai/supercov
|
|
|
183
205
|
|
|
184
206
|
For Cursor, GitHub Copilot and other agents that read skills: `npx skills add supercorp-ai/supercov`.
|
|
185
207
|
|
|
186
|
-
The Claude Code plugin and the Gemini CLI extension also add
|
|
208
|
+
The Claude Code plugin and the Gemini CLI extension also add five commands you can type:
|
|
187
209
|
|
|
188
210
|
| Command | What it does |
|
|
189
211
|
| --- | --- |
|
|
190
212
|
| `/supercov:coverage [test command]` | Writes one test for code no test reaches, and reports coverage before and after |
|
|
213
|
+
| `/supercov:mutants [--diff base]` | Runs the tests against mutants and writes a test for one that survives |
|
|
191
214
|
| `/supercov:security [patch]` | Scans the repository, or a change, for security vulnerabilities |
|
|
192
215
|
| `/supercov:quality [patch]` | Ranks files by code smells, or checks what a change introduced |
|
|
193
216
|
| `/supercov:review [--base ref]` | Checks a branch or uncommitted change for security and quality problems |
|
|
@@ -300,21 +323,24 @@ JavaScript, TypeScript, Python, Ruby, Rust, Go, Java and Kotlin suites are verif
|
|
|
300
323
|
|
|
301
324
|
Supercov uses exact per-test attribution where an adapter is available. For other supported runners, it reports aggregate structural coverage instead of guessing which test covered a path.
|
|
302
325
|
|
|
303
|
-
| Runner | Coverage attribution |
|
|
304
|
-
| --- | --- |
|
|
305
|
-
| Playwright | Exact per test, worker, retry, outcome, action, and assertion phase |
|
|
306
|
-
| Vitest | Exact per test, with setup execution kept separate |
|
|
307
|
-
| Jest | Exact per test, including parameterized tests |
|
|
308
|
-
| `node:test` | Exact per test |
|
|
309
|
-
| Mocha | Exact per test and retry, `--parallel` included |
|
|
310
|
-
| AVA | Exact per test, concurrent tests included |
|
|
311
|
-
| node-tap 15 and newer | Exact per subtest |
|
|
312
|
-
| Cargo's standard libtest runner | Exact test, attempt, and passing-assertion identity |
|
|
313
|
-
| rustdoc doctests | Exact per doctest |
|
|
314
|
-
| cargo-nextest | Exact test, attempt, retry, and binary identity |
|
|
315
|
-
|
|
|
316
|
-
|
|
|
317
|
-
|
|
|
326
|
+
| Runner | Coverage attribution | Mutation testing |
|
|
327
|
+
| --- | --- | --- |
|
|
328
|
+
| Playwright | Exact per test, worker, retry, outcome, action, and assertion phase | StrykerJS's mutants |
|
|
329
|
+
| Vitest | Exact per test, with setup execution kept separate | StrykerJS's mutants |
|
|
330
|
+
| Jest | Exact per test, including parameterized tests | StrykerJS's mutants |
|
|
331
|
+
| `node:test` | Exact per test | StrykerJS's mutants |
|
|
332
|
+
| Mocha | Exact per test and retry, `--parallel` included | StrykerJS's mutants |
|
|
333
|
+
| AVA | Exact per test, concurrent tests included | StrykerJS's mutants |
|
|
334
|
+
| node-tap 15 and newer | Exact per subtest | StrykerJS's mutants |
|
|
335
|
+
| Cargo's standard libtest runner | Exact test, attempt, and passing-assertion identity | Preview: cargo-mutants' mutants |
|
|
336
|
+
| rustdoc doctests | Exact per doctest | Preview: cargo-mutants' mutants |
|
|
337
|
+
| cargo-nextest | Exact test, attempt, retry, and binary identity | Preview: cargo-mutants' mutants |
|
|
338
|
+
| pytest and `python -m unittest` | Exact test and setup/call/teardown phase identity | Preview: mutmut's mutants |
|
|
339
|
+
| `go test` | Exact per test | Preview: Gremlins' mutants |
|
|
340
|
+
| JUnit 5, JUnit 4, Kotest, Spock and TestNG | Exact per test | Not yet |
|
|
341
|
+
| RSpec | Exact example and before/example/after phase identity | Preview: mutant's mutants |
|
|
342
|
+
| Minitest and test-unit | Exact test and setup/test/teardown identity | Preview: mutant's mutants |
|
|
343
|
+
| Cucumber | Exact scenario and hook-phase identity | Preview: mutant's mutants |
|
|
318
344
|
|
|
319
345
|
Supercov works with Vite, Next, Turbopack, Webpack, esbuild, SWC, and projects with no build step. One command can collect evidence from several supported runners into a single run.
|
|
320
346
|
|
|
@@ -387,6 +413,7 @@ npx supercov runs clean # remove all runs and the build cache
|
|
|
387
413
|
- [Understanding quality](https://supercov.com/docs/quality)
|
|
388
414
|
- [Agent workflow](https://supercov.com/docs/agent-loop)
|
|
389
415
|
- [Understanding assertions](docs/assertions.md)
|
|
416
|
+
- [Mutation testing](docs/mutation.md)
|
|
390
417
|
- [Troubleshooting](https://supercov.com/docs/troubleshooting)
|
|
391
418
|
- [CLI reference](https://supercov.com/docs/cli)
|
|
392
419
|
- [Supported languages and test suites](https://supercov.com/docs/supported-suites)
|
package/docs/cli.md
CHANGED
|
@@ -23,6 +23,8 @@ npx supercov --help
|
|
|
23
23
|
| See each test's answer for one statement | `npx supercov runs latest assertions <path>:<line>` |
|
|
24
24
|
| See what one test is judged to catch | `npx supercov runs latest assertions --test <name>` |
|
|
25
25
|
| List what is asserted on a weak answer | `npx supercov runs latest assertions --weak` |
|
|
26
|
+
| See how far the tests got toward killing each mutant | `npx supercov runs latest mutants` |
|
|
27
|
+
| Run the tests against the mutants they infected | `npx supercov runs latest mutants test` |
|
|
26
28
|
| Read matching current source code | `npx supercov runs latest source <path>` |
|
|
27
29
|
| Compare two runs | `npx supercov diff <older> <newer>` |
|
|
28
30
|
| Open an interactive report | `npx supercov report` |
|
|
@@ -176,6 +178,7 @@ npx supercov runs <run-id> [query] [options]
|
|
|
176
178
|
| `runners` | Group coverage by test runner |
|
|
177
179
|
| `scope` | See what is source and what is not, by directory and reason; `--files` lists every file |
|
|
178
180
|
| `assertions` | Read the share of executed statements the tests assert, and the ones they do not; `assertions assess` works it out |
|
|
181
|
+
| `mutants [path[:line]]` | See, for each mutant the language's established tool would make (StrykerJS; in preview mutmut, cargo-mutants, Gremlins and mutant), whether a test reached it and changed its value |
|
|
179
182
|
| `source <path>` | Read matching current project source with line numbers |
|
|
180
183
|
| `minimize` | Find a small test subset that preserves a coverage target |
|
|
181
184
|
|
|
@@ -289,6 +292,284 @@ assessment; its answers are kept, so a later `assess` asks only what is left.
|
|
|
289
292
|
`assertions --tag @e2e` reads what those tests assert: a statement that only
|
|
290
293
|
other tests catch is not asserted there.
|
|
291
294
|
|
|
295
|
+
### Mutants
|
|
296
|
+
|
|
297
|
+
```sh supercov-example
|
|
298
|
+
npx supercov runs <run-id> mutants
|
|
299
|
+
npx supercov runs <run-id> mutants app/checkout.ts
|
|
300
|
+
npx supercov runs <run-id> mutants app/checkout.ts:42
|
|
301
|
+
npx supercov runs <run-id> mutants --status not-infected,not-reached
|
|
302
|
+
npx supercov runs <run-id> mutants --mutator EqualityOperator --json
|
|
303
|
+
npx supercov runs <run-id> mutants --stryker reports/mutation/mutation.json
|
|
304
|
+
npx supercov runs <run-id> mutants --format jsonl --output mutants.jsonl
|
|
305
|
+
npx supercov runs <run-id> mutants --diff origin/main
|
|
306
|
+
npx supercov runs <run-id> mutants --diff origin/main --format markdown --output mutants.md
|
|
307
|
+
npx supercov runs <run-id> mutants --diff origin/main --fail-on not-infected,not-reached
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
`mutants` reads weak mutation from the run: for each mutant StrykerJS 10.1.1
|
|
311
|
+
(JavaScript, TypeScript) would make, or in preview mutmut 3.8.1 (Python),
|
|
312
|
+
cargo-mutants 27.1.0 (Rust), Gremlins 0.6.0 (Go) or mutant 0.17.1 (Ruby) would
|
|
313
|
+
make (see [Mutation testing](mutation.md)), whether a test
|
|
314
|
+
ran the mutated code and whether the mutant's value would have differed there.
|
|
315
|
+
Nothing runs again. A plain run does nothing for mutants and costs nothing
|
|
316
|
+
more for them: a run lists its mutants from its sources the first time they are asked for (by `mutants`,
|
|
317
|
+
`mutants test` or `supercov mutants`), and keeps them beside the run. A source
|
|
318
|
+
changed since the run is left out until the run is measured again.
|
|
319
|
+
`supercov mutants` does all of it: it measures a run of the checkout with the
|
|
320
|
+
mutants' probes where the latest run is of other sources or is a plain one,
|
|
321
|
+
lists the mutants, and runs `mutants test`; while the checkout is unchanged it
|
|
322
|
+
reads that run again. Listed this way, a mutant whose verdict
|
|
323
|
+
needs the values its expression took is `unknown`, and `mutants test` runs it;
|
|
324
|
+
a run measured with `SUPERCOV_MUTANTS=1` records those values (the mutants'
|
|
325
|
+
probes) and decides more of them without running anything.
|
|
326
|
+
|
|
327
|
+
Each mutant has one status:
|
|
328
|
+
|
|
329
|
+
| Status | Meaning |
|
|
330
|
+
| --- | --- |
|
|
331
|
+
| `not-reached` | No test ran the mutated code |
|
|
332
|
+
| `not-infected` | A test ran it, and every evaluation gave the mutant the original's value: these tests cannot kill it |
|
|
333
|
+
| `infected` | Some evaluation gave the mutant another value: a candidate kill, not a kill |
|
|
334
|
+
| `unknown` | The run cannot tell, such as code that ran where values are not recorded |
|
|
335
|
+
| `equivalent` | No input can make it differ, shown by a static rule from the code alone, whatever the tests did |
|
|
336
|
+
|
|
337
|
+
The weak score is `infected / (infected + not-infected + not-reached)`, with
|
|
338
|
+
unknown and equivalent mutants left out, and beside it the same over reached
|
|
339
|
+
mutants alone. They are shown beside coverage and never change it.
|
|
340
|
+
|
|
341
|
+
A not-infected boundary comparison (`<` and `<=`, `>` and `>=`) with an
|
|
342
|
+
operand that is a clock reading (`Date.now()`, `new Date()`,
|
|
343
|
+
`performance.now()`, and arithmetic, `.getTime()` or date-fns `add*`/`sub*` of
|
|
344
|
+
one, through up to two consts or local functions) or a `Math.random()` reading
|
|
345
|
+
is listed with `(clock boundary)` or `(random boundary)`: only one exact
|
|
346
|
+
reading would make it differ, so a test can hardly reach it. It stays not
|
|
347
|
+
infected, and the summary counts these beside the not-infected ones
|
|
348
|
+
(`211 not infected (12 at a clock or random boundary)`).
|
|
349
|
+
|
|
350
|
+
Without a file, `mutants` shows a table of files, a page at a time, ordered by
|
|
351
|
+
how many mutants a test reaches and does not infect, which only this report
|
|
352
|
+
shows, then by how many no test reaches, then by name. Files no test ran at all
|
|
353
|
+
come last, however many mutants they hold, and a line counts them. With a file
|
|
354
|
+
it lists the file's mutants by line, as `line:column Mutator original →
|
|
355
|
+
replacement status reason`; with `file:line`, that line's mutants each with its
|
|
356
|
+
reason and id. A mutant whose code is on several lines or too long to show is
|
|
357
|
+
shown by the part it changes, with `…` for what it shares with the original:
|
|
358
|
+
`….slice(0, maxUsers) → …` for a chain without its last call. `--status` and `--mutator` pick mutants, across files when no
|
|
359
|
+
file is given. The scores are of the mutants asked about: the run, a file or a
|
|
360
|
+
line, and one mutator with `--mutator`. The run summary shows one line,
|
|
361
|
+
`Mutants 15 · weak score 53.3% · 1 not infected · 6 not reached · 0 unknown ·
|
|
362
|
+
0 equivalent`, and `data.mutants` in its JSON.
|
|
363
|
+
|
|
364
|
+
`--kind`, `--runner`, `--tag`, `--title` and `--test-file` read the verdicts of
|
|
365
|
+
those tests alone: a mutant only other tests infect is not infected there.
|
|
366
|
+
`--filter passed` and `--filter failed` are not supported.
|
|
367
|
+
|
|
368
|
+
In `--json` the reply is `coverage.mutants`: `mutantSet`, `levels`
|
|
369
|
+
(`weak: true`, `strong: false`), `summary` with the counts by status,
|
|
370
|
+
`untestable` (the not-infected mutants at a clock or random boundary),
|
|
371
|
+
`weakScore`, `weakScoreReached` and `mutationScore` (null until tests run
|
|
372
|
+
against mutants), and a page of `mutants`, each with its `id`
|
|
373
|
+
(`file:line:column-line:column:Mutator:descriptor`), `span`, `original`,
|
|
374
|
+
`replacement`, `changed` (`from`, `to`: the part shown, where it is shown
|
|
375
|
+
instead), `status`, `weak` (`reach`, `infection`, `code`, `reason`; `rule` for
|
|
376
|
+
an equivalent mutant; `untestable` and `untestableReason` for a clock or
|
|
377
|
+
random boundary), `strong` (null) and `stryker`. Mutants are listed by file path, and within a
|
|
378
|
+
file by position, whatever the table's order.
|
|
379
|
+
|
|
380
|
+
`--format jsonl` writes every mutant asked about, one JSON object per line,
|
|
381
|
+
each as `--json` lists it, with nothing paged; `--output <file>` writes them
|
|
382
|
+
to a file instead of standard output. A file, `--status`, `--mutator`,
|
|
383
|
+
`--stryker` and the options that narrow the tests apply as they do to the
|
|
384
|
+
query.
|
|
385
|
+
|
|
386
|
+
`--stryker` joins StrykerJS's own reports by mutant id. It takes several
|
|
387
|
+
reports, as a glob gives them (`--stryker reports/*.json`), and directories of
|
|
388
|
+
them, whose every `.json` file is read, recursively; a file to query goes
|
|
389
|
+
before it. Give `--stryker-root <dir>` when a report's paths are relative to
|
|
390
|
+
another directory than the project root. The commands the reply suggests repeat
|
|
391
|
+
what `--stryker` was given, or `<56 reports>` for more than three. Each mutant
|
|
392
|
+
then shows StrykerJS's status, and a `stryker` block counts the mutants
|
|
393
|
+
matched, those only Supercov or only StrykerJS made (by mutator), and how many
|
|
394
|
+
of StrykerJS's survivors this run says no test infects or reaches. A mutant
|
|
395
|
+
this run says is not infected, not reached or equivalent that StrykerJS killed
|
|
396
|
+
is a soundness violation: each is listed, and the command exits `1`.
|
|
397
|
+
|
|
398
|
+
The HTML report (`supercov report`) shows a run's mutants of every language
|
|
399
|
+
where it shows its coverage (see [Mutation testing in the HTML
|
|
400
|
+
report](reports.md#mutation-testing)): the weak and the strong score side by
|
|
401
|
+
side with every status counted, why the mutants without a verdict have none,
|
|
402
|
+
each language, the mutants left alive by file, a Mutants column with each
|
|
403
|
+
file's score, and each line's mutants with both levels' verdicts and the test
|
|
404
|
+
that killed one. `supercov report --diff <base>` shows only a change's
|
|
405
|
+
mutants. A run without mutants shows none.
|
|
406
|
+
|
|
407
|
+
#### Mutants on a pull request
|
|
408
|
+
|
|
409
|
+
`--diff <base>` keeps the mutants on lines a change added or modified since it
|
|
410
|
+
left `<base>`, a git ref such as `origin/main`. The change is the commit the
|
|
411
|
+
run measured against its merge base with `<base>`; a run measured with
|
|
412
|
+
uncommitted changes, or one that records no commit, is compared as the working
|
|
413
|
+
tree, untracked files added whole, and the output says so. Everything else
|
|
414
|
+
composes with it: a file or line, `--status`, `--mutator`, the test filters,
|
|
415
|
+
`--json`, `--format`, `--stryker`, and the scores, which are of the change's
|
|
416
|
+
mutants. A base git does not know (a shallow checkout's) fails with exit `2`.
|
|
417
|
+
|
|
418
|
+
The output names the base, the merge base and how many changed lines hold a
|
|
419
|
+
mutant, then lists the mutants the tests leave alive, not infected first and
|
|
420
|
+
then not reached, each with the part it changes and why, and counts the rest
|
|
421
|
+
in one line. `--json` lists every mutant of the change, survivors first, with
|
|
422
|
+
`diff` (`base`, `mergeBase`, `commit`, `changedLines`, `linesWithMutants`).
|
|
423
|
+
|
|
424
|
+
`--format markdown` writes a table for a pull request's comment: the counts in
|
|
425
|
+
one line, then up to 25 not-infected and not-reached mutants (or those
|
|
426
|
+
`--status` names) with where they are (`file:line:column`), what they change,
|
|
427
|
+
their status and why, and the command that lists the rest. Once `mutants test`
|
|
428
|
+
gave verdicts, a second line has the mutation score, with how many mutants it
|
|
429
|
+
is over (or, with none, why there is no score), and every verdict counted
|
|
430
|
+
(killed, timed out, survived, no coverage, unviable, error, not run for want
|
|
431
|
+
of a driver, and those with none yet), and the table lists the survivors: the
|
|
432
|
+
mutants that survived or that no test covers, then those weak mutation shows
|
|
433
|
+
no test can kill, each with its weak status, its strong verdict and why.
|
|
434
|
+
|
|
435
|
+
#### Mutation reports other tools read
|
|
436
|
+
|
|
437
|
+
```sh supercov-example
|
|
438
|
+
npx supercov runs latest mutants --format stryker --output reports/mutation/mutation.json
|
|
439
|
+
npx supercov runs latest mutants --format pit --output target/pit-reports/mutations.xml
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
`--format stryker` writes StrykerJS's `mutation.json`: the mutation testing
|
|
443
|
+
report schema's version 2, which mutation-testing-elements' HTML report, the
|
|
444
|
+
Stryker Dashboard and CI integrations read. Each file carries its language and
|
|
445
|
+
its source as the checkout holds it, which the schema requires: a file the
|
|
446
|
+
checkout no longer has is left out and named on stderr. `--format pit` writes
|
|
447
|
+
PIT's `mutations.xml`, which PIT's report aggregator and Sonar's PIT plugin
|
|
448
|
+
read. Both hold the mutants asked about (a file, `--diff`, `--mutator` and the
|
|
449
|
+
test filters narrow them), each with its strong verdict where `mutants test`
|
|
450
|
+
gave one:
|
|
451
|
+
|
|
452
|
+
| Supercov | `stryker` | `pit` |
|
|
453
|
+
| --- | --- | --- |
|
|
454
|
+
| `killed` | `Killed` | `KILLED` |
|
|
455
|
+
| `timeout` | `Timeout` | `TIMED_OUT` |
|
|
456
|
+
| `survived` | `Survived` | `SURVIVED` |
|
|
457
|
+
| `no-coverage` | `NoCoverage` | `NO_COVERAGE` |
|
|
458
|
+
| `unviable` | `CompileError` | `NON_VIABLE` |
|
|
459
|
+
| `error` | `RuntimeError` | `NOT_STARTED` |
|
|
460
|
+
| not run: no driver for its language | `Pending` | `NOT_STARTED` |
|
|
461
|
+
| `equivalent` | `Ignored` | left out |
|
|
462
|
+
| no verdict, not reached | `NoCoverage` | `NO_COVERAGE` |
|
|
463
|
+
| no verdict, not infected | `Survived` | `SURVIVED` |
|
|
464
|
+
| no verdict, infected or unknown | `Pending` | `NOT_STARTED` |
|
|
465
|
+
|
|
466
|
+
A mutant no test reaches or infects is the one the strong pass itself decides
|
|
467
|
+
without running it, as no-coverage or survived, so the two formats say the
|
|
468
|
+
same before a pass ran. A StrykerJS mutant's `statusReason` and a PIT
|
|
469
|
+
mutant's `description` say why, in the words the HTML report uses; a killed
|
|
470
|
+
mutant names its test in `killedBy` and `killingTest`. Supercov mutates
|
|
471
|
+
source, not bytecode: a PIT mutant's class is its file's path after a `java`
|
|
472
|
+
or `kotlin` source root (`com.shop.Cart`), its method is left empty, and its
|
|
473
|
+
index is its place in its file.
|
|
474
|
+
|
|
475
|
+
`--fail-on <statuses>` exits `1` when any mutant asked about has one of them,
|
|
476
|
+
`--diff`'s mutants with it: a gate CI can hold a change to. Without it the exit
|
|
477
|
+
codes are as before. In GitHub Actions, after the tests are measured:
|
|
478
|
+
|
|
479
|
+
```yaml
|
|
480
|
+
- uses: actions/checkout@v6
|
|
481
|
+
with:
|
|
482
|
+
fetch-depth: 0 # the base and the merge base
|
|
483
|
+
- run: npx supercov -- npm test
|
|
484
|
+
- run: npx supercov runs latest mutants --diff origin/${{ github.base_ref }} --format markdown --output mutants.md
|
|
485
|
+
- run: gh pr comment ${{ github.event.number }} --body-file mutants.md --edit-last --create-if-none
|
|
486
|
+
env:
|
|
487
|
+
GH_TOKEN: ${{ github.token }}
|
|
488
|
+
- run: npx supercov runs latest mutants --diff origin/${{ github.base_ref }} --fail-on not-infected
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
### Strong mutation: run the tests against the mutants
|
|
492
|
+
|
|
493
|
+
```bash
|
|
494
|
+
npx supercov runs latest mutants test # every mutant the run's tests infected
|
|
495
|
+
npx supercov runs latest mutants test --diff origin/main # only the change's mutants
|
|
496
|
+
npx supercov runs latest mutants test --file src/billing.ts
|
|
497
|
+
npx supercov runs latest mutants test --plan --json # what would run, nothing run
|
|
498
|
+
npx supercov runs latest mutants test --critical "src/auth/**" --fail-on survived
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
`mutants test` reruns the measured run's command (or the one after `--`) with
|
|
502
|
+
every mutant behind a switch and saves StrykerJS's verdicts into the run:
|
|
503
|
+
`killed`, `survived`, `timeout`, `no-coverage`, and `error` for a mutant that
|
|
504
|
+
could not be switched on. The pass's summary ends with the mutants the tests
|
|
505
|
+
let survive (`file:line`, the mutator and the change, the first ten and how
|
|
506
|
+
many more). `mutants` then shows each mutant's verdict beside its weak status,
|
|
507
|
+
and the mutation score with the verdicts' counts; `mutants --status survived`
|
|
508
|
+
(or `killed`, `timeout`, `no-coverage`, `error`, `unviable`) lists the mutants
|
|
509
|
+
with that verdict, and `--format markdown` lists the survivors under the
|
|
510
|
+
mutation score.
|
|
511
|
+
|
|
512
|
+
It runs far less than StrykerJS: no dry run (the measured run is one), no
|
|
513
|
+
mutant no test infected (decided `survived`) or reached (`no-coverage`), and
|
|
514
|
+
each mutant only against the tests whose own evidence shows they infected it.
|
|
515
|
+
Vitest suites run in rounds through one resident Vitest: each test file can
|
|
516
|
+
carry its own mutant, several copies of a file run side by side, a mutant is
|
|
517
|
+
switched on before the test file's imports, and it stops at its first failing
|
|
518
|
+
test. Playwright suites carry each attempt's mutant with its requests, so one
|
|
519
|
+
server serves different mutants to different workers; mutants of a server's
|
|
520
|
+
start-up run with the server restarted for them. Jest, node:test, Mocha, AVA,
|
|
521
|
+
node-tap, bun:test and Vitest's Browser Mode run one test file per start of the
|
|
522
|
+
command, with the mutant switched on in every process from its start (in the
|
|
523
|
+
page, under Browser Mode) and only that file's candidate tests, stopping at
|
|
524
|
+
the first failure; Jest and Mocha keep resident runners for it. Python, Rust,
|
|
525
|
+
Go and Ruby are in preview. Rust mutants
|
|
526
|
+
run through cargo's tests, or through the JavaScript tests that load the
|
|
527
|
+
crate compiled to wasm. Go mutants run each package's test binary, built once.
|
|
528
|
+
Ruby mutants run in a fork of the loaded suite under RSpec, Minitest, test-unit
|
|
529
|
+
or Cucumber. Python suites under pytest or unittest (`python -m
|
|
530
|
+
unittest`) collect their tests once; each mutant then runs in a fork of that
|
|
531
|
+
process, its function switched to mutmut's copy of it, against its candidate
|
|
532
|
+
tests in collection order, stopping at the first failure. A mutant whose code
|
|
533
|
+
ran while the test modules loaded runs in a fresh interpreter of the command
|
|
534
|
+
with the mutant on from its start. A mutant no driver runs the tests of is an
|
|
535
|
+
`error`, which the score leaves out as every error, and the summary says how
|
|
536
|
+
many in a line per runner (`12 mutant(s) not run: no strong driver for
|
|
537
|
+
phpunit`). See `docs/design/strong-mutation.md`,
|
|
538
|
+
`docs/design/python-mutants.md` and `docs/design/mutation-drivers.md`.
|
|
539
|
+
|
|
540
|
+
- `--shard k/n` runs one of n shares of the mutants, for parallel jobs.
|
|
541
|
+
- `--critical <glob>` (repeatable): every mutant there must be killed or
|
|
542
|
+
accepted, or the command fails.
|
|
543
|
+
- `--fail-on survived,timeout,no-coverage,error`: fail on any asked mutant with
|
|
544
|
+
one of these.
|
|
545
|
+
- Accepted equivalents: `supercov.accepted.json` at the project root, a list of
|
|
546
|
+
`{ "id": "<mutant id>", "reason": "<why no test can tell it apart>" }`. An
|
|
547
|
+
accepted mutant still runs, shows as accepted, and never fails the command;
|
|
548
|
+
an entry whose mutant is killed or gone is listed as stale.
|
|
549
|
+
- A second `mutants test` over the same run runs only what has no verdict yet.
|
|
550
|
+
The pass saves each verdict as it comes: one that stops early (a test worker
|
|
551
|
+
that never ended, Ctrl-C, a killed job) keeps what it decided, and the next
|
|
552
|
+
pass runs the rest. Ctrl-C stops every process the pass started.
|
|
553
|
+
- After an edit, `supercov mutants` measures the checkout again and keeps an
|
|
554
|
+
earlier run's verdict for each mutant whose file is as it was and whose
|
|
555
|
+
candidate tests, and their test files, nothing changed could reach (as
|
|
556
|
+
`tests affected` reads a change: a test file's edit reaches its tests, a
|
|
557
|
+
source's edit the tests that ran the changed code). The rest run; the
|
|
558
|
+
summary says how many verdicts were kept, and from which run.
|
|
559
|
+
- `--diff` and `--file` answer about the mutants they ask for: the summary's
|
|
560
|
+
counts and score are theirs, and its first line says how many of the run's
|
|
561
|
+
mutants that is. `--format markdown` (with `--output <file>`) writes the
|
|
562
|
+
answer as a pull request's comment, as `mutants --format markdown` does.
|
|
563
|
+
- A run that recorded no test is refused with exit `2`; where its command ran
|
|
564
|
+
mutants' code (a runner Supercov has no adapter for, such as tape), it says
|
|
565
|
+
how many and names the runner. A pass over a run whose command failed
|
|
566
|
+
answers, then exits `2`: a failing test kills nothing, so the verdicts are
|
|
567
|
+
the passing tests' alone and cannot gate. So does a pass in which no mutant
|
|
568
|
+
could be run. A mutant only work outside any test ran is `no-coverage`.
|
|
569
|
+
- The command's own output goes to a log beside the pass's results; stdout is
|
|
570
|
+
the answer alone. When the pass ends, its directory under `.supercov/strong`
|
|
571
|
+
keeps only those logs, and the next pass removes it.
|
|
572
|
+
|
|
292
573
|
## Fail CI below a coverage floor
|
|
293
574
|
|
|
294
575
|
```sh supercov-example
|
|
@@ -428,6 +709,11 @@ condition and the vectors observed. `--metric`, `--filter`, `--kind`,
|
|
|
428
709
|
`gaps`, and nothing is paged, so a tool or an agent reads a run's every gap in
|
|
429
710
|
one pass instead of a page at a time.
|
|
430
711
|
|
|
712
|
+
`runs <id> mutants --format jsonl` exports a run's mutants the same way, one
|
|
713
|
+
mutant per line, and `--format stryker` and `--format pit` as the mutation
|
|
714
|
+
reports StrykerJS's and PIT's tools read (see [Mutation reports other tools
|
|
715
|
+
read](#mutation-reports-other-tools-read)).
|
|
716
|
+
|
|
431
717
|
```sh supercov-example
|
|
432
718
|
npx supercov runs report --format lcov --output coverage/lcov.info
|
|
433
719
|
npx supercov runs report --format cobertura --output coverage/cobertura.xml
|
|
@@ -449,6 +735,10 @@ npx supercov runs report --format html --output coverage/report
|
|
|
449
735
|
| `jacoco` | JaCoCo XML | GitLab merge requests, SonarQube's Java analysis, Qlty |
|
|
450
736
|
| `sonar` | SonarQube's generic coverage XML | SonarQube and SonarCloud, for any language (`sonar.coverageReportPaths`) |
|
|
451
737
|
|
|
738
|
+
These formats carry coverage only: none has a place for a mutant, so a run's
|
|
739
|
+
mutants are in `mutants --format stryker` and `--format pit` instead, and in
|
|
740
|
+
the `html` page.
|
|
741
|
+
|
|
452
742
|
All are written from the same view `check` and `patch` read, so a viewer,
|
|
453
743
|
hosted service or CI integration sees the totals Supercov enforced. `--kind`,
|
|
454
744
|
`--runner`, `--tag`, `--title` and `--test-file` write the coverage of only
|
|
@@ -461,7 +751,9 @@ npx supercov runs report --format lcov --kind e2e --output coverage/e2e.info
|
|
|
461
751
|
repository-relative with forward slashes, ordering is stable, and the file is
|
|
462
752
|
written atomically; an existing file is kept unless you pass `--force`. Without
|
|
463
753
|
`--output` the report goes to stdout and diagnostics to stderr, so a redirect
|
|
464
|
-
captures only the report
|
|
754
|
+
captures only the report; an HTML report asked for in a terminal is written to
|
|
755
|
+
`.supercov/reports/coverage-report.html` instead, replaced each time, and its
|
|
756
|
+
path said.
|
|
465
757
|
|
|
466
758
|
Supercov records that a line ran, not how many times, so `DA:`, `hits`,
|
|
467
759
|
Istanbul's counts and Clover's `count` state `1` or `0`. They are not execution
|
|
@@ -512,6 +804,21 @@ applicable** (nothing eligible), **partly measured** (Supercov declined some
|
|
|
512
804
|
obligations, which are excluded from every count) and **stale** (the run no
|
|
513
805
|
longer matches the checkout). A failed suite says so beside its numbers.
|
|
514
806
|
|
|
807
|
+
For a run whose mutants are listed it also shows its mutation testing, as
|
|
808
|
+
`supercov report` does (see [Mutation testing](reports.md#mutation-testing)):
|
|
809
|
+
a Mutation testing card with the weak and the strong score, every status
|
|
810
|
+
counted, why mutants have no verdict, each language, and the survivors by
|
|
811
|
+
file, each linking to its line; a sortable Mutants column with each file's
|
|
812
|
+
score and survivors; and, under each line of the source, its mutants with
|
|
813
|
+
what they change, both levels and the test that killed one, a survivor set
|
|
814
|
+
apart. `--diff <base>` keeps the mutants on lines a change added or changed
|
|
815
|
+
since its merge base with `<base>`, and the card says so; with another
|
|
816
|
+
format `--diff` is refused, as those formats carry no mutants.
|
|
817
|
+
|
|
818
|
+
```sh supercov-example
|
|
819
|
+
npx supercov runs latest report --format html --diff origin/main --output coverage/report
|
|
820
|
+
```
|
|
821
|
+
|
|
515
822
|
Source text is embedded only when the run still matches the checkout; otherwise
|
|
516
823
|
the report shows line numbers and explains why. Embedding makes a report
|
|
517
824
|
portable and also means it contains your code — worth knowing before uploading
|
|
@@ -650,6 +957,11 @@ npx supercov report --output artifacts/supercov-report.html --no-open
|
|
|
650
957
|
only those tests' coverage, in every run it holds; a run with none of them is
|
|
651
958
|
left out, and the report names the tests it shows.
|
|
652
959
|
|
|
960
|
+
`--diff <base>` shows only the mutants on lines a change added or changed
|
|
961
|
+
since its merge base with `<base>`, as `runs <id> mutants --diff` reads them,
|
|
962
|
+
and the report says so; coverage is not narrowed. See [Mutation
|
|
963
|
+
testing](reports.md#mutation-testing) for what the report shows of mutants.
|
|
964
|
+
|
|
653
965
|
A report includes the five newest runs; `--runs N` includes up to 20. A large
|
|
654
966
|
project's report can pass GitHub's 25 MB attachment limit; `--runs 1` makes
|
|
655
967
|
the smallest. See [Portable HTML reports](reports.md) for
|
|
@@ -883,6 +1195,12 @@ without one resolves its dependencies anew in each job, and `merge` leaves
|
|
|
883
1195
|
every run out as `the dependencies have changed`: resolve the lockfile once in
|
|
884
1196
|
a first job, pass it to the others as an artifact, and `npm ci` it there.
|
|
885
1197
|
|
|
1198
|
+
A merged run lists the mutants of every file a run listed (see
|
|
1199
|
+
[Mutants](#mutants)), once. Runs that listed different mutants of a file
|
|
1200
|
+
recorded with the same bytes are not merged. A run that listed no mutants
|
|
1201
|
+
adds none, and where its tests ran a mutant, a verdict that needs values they
|
|
1202
|
+
did not record is `unknown`.
|
|
1203
|
+
|
|
886
1204
|
`assertions assess` assesses a merged run across every suite merged into it,
|
|
887
1205
|
reusing the answers saved when its parts were assessed. `tests affected` of a
|
|
888
1206
|
merged run is answered from the runs it was merged from, which hold the record
|
|
@@ -975,6 +1293,8 @@ terminal or offline environment after the package has been downloaded.
|
|
|
975
1293
|
| `SUPERCOV_RUN_ID` | Set by Supercov, not by you: in every process a measured command starts, the run's id, so a test or harness can tell it is measured |
|
|
976
1294
|
| `SUPERCOV_RUN_ID_FILE` | A file to write the recorded run's id to, for a script to query that run rather than `latest` |
|
|
977
1295
|
| `SUPERCOV_KEEP_WORKSPACE` | Set to `1` to leave the instrumented copy of the project in `.supercov/workspaces/` after the run, to inspect what the command ran |
|
|
1296
|
+
| `SUPERCOV_MUTANTS` | Set to `1` to measure a run with the probes that record the values its mutants' verdicts read, and list its mutants as it runs (see [Mutants](#mutants)); a plain run lists none and places no probe |
|
|
1297
|
+
| `SUPERCOV_STRONG_WORKERS` | How many test processes a JavaScript or Python strong pass runs at once (default: about one per CPU) |
|
|
978
1298
|
| `SUPERCOV_COMMAND_TIMEOUT_MS` | Stop the test command after this many milliseconds: what is still running is asked to stop, then made to five seconds later, what ran is recorded, and Supercov exits `124`. No deadline by default |
|
|
979
1299
|
|
|
980
1300
|
Examples:
|
|
@@ -992,7 +1312,7 @@ SUPERCOV_TEST_KIND=e2e npx supercov -- npx playwright test
|
|
|
992
1312
|
| Wrapped command's code | The test command failed and Supercov preserved its status |
|
|
993
1313
|
| `127`, `126` | The test command could not start: no such program, or one that may not be run, as a shell reports it |
|
|
994
1314
|
| `124` | The test command ran past `SUPERCOV_COMMAND_TIMEOUT_MS` and was stopped |
|
|
995
|
-
| `1` | A valid measurement failed a policy you set, such as a coverage floor |
|
|
1315
|
+
| `1` | A valid measurement failed a policy you set, such as a coverage floor, or `mutants --stryker` found a soundness violation |
|
|
996
1316
|
| `2` | Supercov could not complete the request, or the evidence cannot answer it |
|
|
997
1317
|
|
|
998
1318
|
`quality` and `security` exit `0` for a complete report in which some files
|
package/docs/getting-started.md
CHANGED
|
@@ -124,6 +124,23 @@ just the percentage.
|
|
|
124
124
|
For a recorded example and prompts for longer runs, see
|
|
125
125
|
[Agent workflow](agent-loop.md).
|
|
126
126
|
|
|
127
|
+
## 5. Check that the tests catch bugs
|
|
128
|
+
|
|
129
|
+
Coverage shows the new test ran the code. To see whether it would fail if
|
|
130
|
+
that code were wrong, the agent runs the tests against mutants: small changes
|
|
131
|
+
to the source, such as `<` to `<=`, each of which a good test fails on.
|
|
132
|
+
|
|
133
|
+
```sh supercov-example
|
|
134
|
+
npx supercov mutants -- npm test
|
|
135
|
+
npx supercov runs latest mutants app/checkout/session.ts
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
A mutant that every test passes with survived: its line names a check no test
|
|
139
|
+
makes. On a pull request, `npx supercov mutants --diff origin/main` keeps the
|
|
140
|
+
mutants on the lines the change touched. Mutation testing reruns the tests, so
|
|
141
|
+
it takes longer than a measured run; a plain run costs nothing more for it.
|
|
142
|
+
See [Mutation testing](mutation.md).
|
|
143
|
+
|
|
127
144
|
## Environment requirements
|
|
128
145
|
|
|
129
146
|
These requirements apply wherever the agent runs commands: your machine,
|
|
@@ -184,4 +201,5 @@ before changing the project.
|
|
|
184
201
|
- [Agent workflow](agent-loop.md) — run a safe, repeatable coverage loop.
|
|
185
202
|
- [Supported suites](supported-suites.md) — check languages, runners, and limits.
|
|
186
203
|
- [Coverage model](coverage-model.md) — understand gaps, metrics, and measurement limits.
|
|
204
|
+
- [Mutation testing](mutation.md) — check that the tests fail when the code is wrong.
|
|
187
205
|
- [CLI reference](cli.md) — find every command and filter.
|