@hughescr/stryker-bun-runner 1.5.2 → 1.6.1
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 +491 -24
- package/dist/index.d.ts +486 -32
- package/dist/index.js +3490 -334
- package/dist/templates/coverage-preload.js +1128 -0
- package/dist/templates/import-scan.js +902 -0
- package/package.json +5 -2
- package/dist/coverage/preload-logic.js +0 -255
- package/dist/templates/coverage-preload.ts +0 -440
package/README.md
CHANGED
|
@@ -8,10 +8,12 @@ coverage so that each mutant runs only the tests that reach it.
|
|
|
8
8
|
[](https://www.npmjs.com/package/@hughescr/stryker-bun-runner) [](LICENSE.md) [](https://bun.sh) [](https://stryker-mutator.io) [](https://dashboard.stryker-mutator.io/reports/github.com/hughescr/stryker-bun-runner/main)
|
|
9
9
|
|
|
10
10
|
- **Per-test coverage**, so each mutant runs only its covering tests, in only their files,
|
|
11
|
-
cheapest file first.
|
|
11
|
+
cheapest file first; a static mutant's whole-suite run starts with the files likeliest to kill it.
|
|
12
12
|
- **Honest scoring**: a crash or a run that proves nothing is an Error, not a kill; a test file
|
|
13
13
|
that a mutant stops from loading is a kill; an infinite loop is stopped early and scored Timeout.
|
|
14
14
|
- **A strict dry run** that fails loudly rather than hand Stryker incomplete coverage.
|
|
15
|
+
- **Only the files your tests load are imported**, so a file that no test loads, such as an app's
|
|
16
|
+
entry point, cannot break the dry run.
|
|
15
17
|
- **Works with** Stryker's incremental mode, `testFiles`, `disableBail`, `ignoreStatic` and the
|
|
16
18
|
TypeScript checker, with a helper that keeps your tests out of the type check.
|
|
17
19
|
|
|
@@ -21,12 +23,24 @@ coverage so that each mutant runs only the tests that reach it.
|
|
|
21
23
|
- [Before you start](#before-you-start) · [Install](#1-install) · [Configure](#2-configure) ·
|
|
22
24
|
[Run](#3-run) · [Reading the output](#reading-the-output) ·
|
|
23
25
|
[Optional: skip mutants that do not compile](#optional-skip-mutants-that-do-not-compile)
|
|
26
|
+
- [Upgrading: the dry run imports only what your tests load](#upgrading-the-dry-run-imports-only-what-your-tests-load)
|
|
27
|
+
- [Upgrading from 1.5](#upgrading-from-15)
|
|
24
28
|
- [Upgrading from 1.4](#upgrading-from-14)
|
|
25
29
|
- [Terms](#terms)
|
|
26
30
|
- [Requirements and compatibility](#requirements-and-compatibility)
|
|
27
31
|
- [Configuration](#configuration)
|
|
28
32
|
- [Example with every option](#example-with-every-option) · [bun.bunArgs](#bunbunargs) ·
|
|
29
33
|
[Choosing the test files](#choosing-the-test-files) · [Your bunfig.toml](#your-bunfigtoml)
|
|
34
|
+
- [Which mutated files the dry run imports](#which-mutated-files-the-dry-run-imports)
|
|
35
|
+
- [Tests run twice](#if-the-dry-run-runs-your-tests-twice) ·
|
|
36
|
+
[A file fails when imported first](#if-a-mutated-file-fails-when-it-is-imported-before-the-tests) ·
|
|
37
|
+
[The plain run fails](#if-the-first-plain-run-of-the-tests-fails) ·
|
|
38
|
+
[A test loads a file late](#if-a-test-loads-a-mutated-file-late) ·
|
|
39
|
+
[A mutant run stops the campaign](#if-a-mutant-run-stops-the-campaign) ·
|
|
40
|
+
[`mock.module()`](#if-a-test-replaces-a-mutated-file-with-mockmodule) ·
|
|
41
|
+
[Workers and child processes](#if-a-test-runs-a-mutated-file-in-a-worker-or-a-child-process) ·
|
|
42
|
+
[A preload's last `afterAll`](#if-one-of-your-preloads-loads-a-mutated-file-at-the-very-end) ·
|
|
43
|
+
[The earlier behaviour](#if-you-want-the-earlier-behaviour)
|
|
30
44
|
- [How it works](#how-it-works)
|
|
31
45
|
- [How results are scored](#how-results-are-scored) · [Timeouts](#timeouts)
|
|
32
46
|
- [Speeding up runs](#speeding-up-runs)
|
|
@@ -163,8 +177,72 @@ export default await withTestFilesExcludedFromTypeCheck({
|
|
|
163
177
|
});
|
|
164
178
|
```
|
|
165
179
|
|
|
180
|
+
## Upgrading: the dry run imports only what your tests load
|
|
181
|
+
|
|
182
|
+
Most projects need no config change.
|
|
183
|
+
|
|
184
|
+
Before the dry run's tests start, the runner imports the mutated files, so that their module-level
|
|
185
|
+
code (constants, top-level setup) runs outside any test. Earlier versions imported every file that
|
|
186
|
+
your `mutate` globs match. The runner now imports only the mutated files that your tests load, and
|
|
187
|
+
leaves the others alone. So a file that no test loads, such as an app's entry point that fails
|
|
188
|
+
when it is imported outside a browser, no longer breaks the dry run
|
|
189
|
+
([#3](https://github.com/hughescr/stryker-bun-runner/issues/3)). How the runner finds the files,
|
|
190
|
+
and what to do in the rare cases where it needs help:
|
|
191
|
+
[Which mutated files the dry run imports](#which-mutated-files-the-dry-run-imports).
|
|
192
|
+
|
|
193
|
+
What can change after you upgrade:
|
|
194
|
+
|
|
195
|
+
- **Some results change.** Mutants in the module-level code of a file that no test loads used to be
|
|
196
|
+
[static mutants](#terms), tested against the whole suite (or skipped with `ignoreStatic`). Now
|
|
197
|
+
they are NoCoverage. Where another file's module-level code depended
|
|
198
|
+
on such a file, results in that other file can change in either direction. To keep importing a
|
|
199
|
+
file as before, list it in `bun.alwaysImport`. To go back to the earlier behaviour for every file,
|
|
200
|
+
set `bun.alwaysImport: 'all'` ([how](#if-you-want-the-earlier-behaviour)).
|
|
201
|
+
- **With `incremental`, run once with `--force`** (`bunx stryker run --force`) after upgrading, and
|
|
202
|
+
again each time you change `bun.alwaysImport`. Stryker reuses saved results for mutants that only
|
|
203
|
+
run while a file loads, and one file's module-level code can change the results of mutants in
|
|
204
|
+
other files, so re-running only the files that you changed is not enough.
|
|
205
|
+
- **The dry run may run your tests twice.** When your code could load a mutated file in a way that
|
|
206
|
+
the runner cannot work out from the import statements, it first runs your tests once with nothing
|
|
207
|
+
imported, to see which files they load ([details](#if-the-dry-run-runs-your-tests-twice)).
|
|
208
|
+
- **A test that passed only because a file was imported first** can now fail, and the dry run
|
|
209
|
+
stops ([what to do](#if-the-first-plain-run-of-the-tests-fails)).
|
|
210
|
+
- **A file that only a package, a worker or a child process loads** is not seen by the runner.
|
|
211
|
+
List it in `bun.alwaysImport`. If a mutant run later finds that a package loaded such a file, it
|
|
212
|
+
stops the Stryker run and names the file ([what to do](#if-a-mutant-run-stops-the-campaign)).
|
|
213
|
+
|
|
214
|
+
## Upgrading from 1.5
|
|
215
|
+
|
|
216
|
+
Most projects need no config change, but these differ from 1.5:
|
|
217
|
+
|
|
218
|
+
- **Faster.** On the repo's benchmark fixture (remeda, 1766 mutants, 4 workers, `coverageAnalysis:
|
|
219
|
+
'perTest'`) a full run takes about 37% less wall time than 1.5.2, with no change in which
|
|
220
|
+
mutants are caught. The main reasons: a much cheaper parent-death watch in every `bun test`
|
|
221
|
+
child; static mutants run their likeliest killing test files first; mutant runs ask bun to print
|
|
222
|
+
only failing tests; and a cheaper dry run on large suites. [bench/README.md](bench/README.md)
|
|
223
|
+
explains how it is measured.
|
|
224
|
+
- **Some verdicts change, toward correctness** ([How results are scored](#how-results-are-scored)).
|
|
225
|
+
A mutant that makes a test, hook or module call `process.exit(0)` before bun prints its summary
|
|
226
|
+
is Error, not Survived (Killed when a failing test was reported first). With `FORCE_COLOR` set,
|
|
227
|
+
failing tests are now read, so `killedBy` is filled in and some Error verdicts become Killed. A
|
|
228
|
+
Killed mutant's reason is now the error bun printed for the test; before, it was often unrelated
|
|
229
|
+
lines. Incremental mode keeps the old verdict of mutants it reuses; run once with `--force` to
|
|
230
|
+
re-score.
|
|
231
|
+
- **Mutant-run file order.** Static mutants (and other planned full-suite runs) run the test
|
|
232
|
+
files most likely to kill them first, judged from the dry run's coverage, then cheapest first.
|
|
233
|
+
The order can differ between mutants, so the runner assumes an order-independent suite
|
|
234
|
+
([Mutant runs](docs/internals.md#mutant-runs)).
|
|
235
|
+
- **Temporary files.** Each run's private temp directory is now removed when the Stryker run
|
|
236
|
+
ends, and the directories of runs that died are swept by later runs after an hour. The
|
|
237
|
+
directory names changed. Directories left by older versions are safe to delete by hand
|
|
238
|
+
([Temporary files](docs/internals.md#temporary-files)).
|
|
239
|
+
- **Profiling.** The new opt-in `STRYKER_BUN_PROFILE=/abs/path.jsonl` writes a per-run phase
|
|
240
|
+
timing profile ([Profiling a run](CONTRIBUTING.md#profiling-a-run)).
|
|
241
|
+
|
|
166
242
|
## Upgrading from 1.4
|
|
167
243
|
|
|
244
|
+
Coming from 1.4, also read [Upgrading from 1.5](#upgrading-from-15) for what changed since.
|
|
245
|
+
|
|
168
246
|
Most projects need no config change, but these differ from 1.4:
|
|
169
247
|
|
|
170
248
|
- **`bun.timeout` now bounds only the dry run** (plus the 30 s drain-handshake allowance). Mutant
|
|
@@ -173,13 +251,14 @@ Most projects need no config change, but these differ from 1.4:
|
|
|
173
251
|
small margin ([Timeouts](#timeouts)). If you raised `bun.timeout` so slow mutant runs would not
|
|
174
252
|
time out, raise `timeoutMS` or `timeoutFactor` instead. `bun.timeout` can now be generous: the
|
|
175
253
|
runner warns above 80% use, and only a hung dry run takes that long to fail.
|
|
176
|
-
- **Mutant runs never randomize.**
|
|
177
|
-
source order. The dry run still follows your bunfig `randomize` and `seed`.
|
|
254
|
+
- **Mutant runs never randomize.** Files run cheapest first (by dry-run time; a static mutant's
|
|
255
|
+
likeliest killers before that), tests in source order. The dry run still follows your bunfig `randomize` and `seed`.
|
|
178
256
|
- **Some verdicts change, toward correctness** ([How results are scored](#how-results-are-scored)).
|
|
179
257
|
A hang that a fast test catches is Killed. An infinite loop stops at Stryker's hit limit and is
|
|
180
258
|
Timeout, reason `Hit limit reached`. A bun crash or failed start with no failing test is Error
|
|
181
259
|
(left out of the score), not Killed. A mutant that stops a test file loading is Killed (1.4
|
|
182
|
-
usually scored it Error).
|
|
260
|
+
usually scored it Error). A mutant that makes a test, hook or module call `process.exit(0)` is
|
|
261
|
+
Error, not Survived. Incremental mode keeps the old verdict of mutants it reuses; run once
|
|
183
262
|
with `--force` to re-score.
|
|
184
263
|
- **The dry run is stricter.** Bun's summary, the inspector's events and the coverage records must
|
|
185
264
|
agree exactly (1.4 tolerated small shortfalls), and missing per-test coverage with
|
|
@@ -226,6 +305,9 @@ Most projects need no config change, but these differ from 1.4:
|
|
|
226
305
|
and finish.
|
|
227
306
|
- **Drain handshake**: at the end of the dry run, the test process waits until the runner confirms
|
|
228
307
|
it has received every test event, so none are lost on a busy machine.
|
|
308
|
+
- **Plain run**: a run of your tests that the dry run sometimes makes first, with no mutated file
|
|
309
|
+
imported before the tests, only to see which mutated files the tests load. Its results are not
|
|
310
|
+
reported to Stryker ([when it happens](#if-the-dry-run-runs-your-tests-twice)).
|
|
229
311
|
|
|
230
312
|
## Requirements and compatibility
|
|
231
313
|
|
|
@@ -254,10 +336,13 @@ Runner options go under `bun` in your Stryker config. Stryker validates them: an
|
|
|
254
336
|
| `bun.env` | `object` of strings | none | Extra environment variables for every `bun test` process (and for the startup `bun --version` check). |
|
|
255
337
|
| `bun.bunArgs` | `string[]` | none | Extra `bun test` flags. Some are rejected, removed or handled specially; see [bun.bunArgs](#bunbunargs). |
|
|
256
338
|
| `bun.testFiles` | `string[]` (non-empty) | none | The test files or directories to run, instead of auto-discovery. See [Choosing the test files](#choosing-the-test-files). |
|
|
339
|
+
| `bun.alwaysImport` | `'all'` or `string[]` of globs | none | Mutated files that the dry run imports before the tests even when no test loads them, so that their module-level code runs before any test. `'all'` imports every file that `mutate` matches, in one run of the tests, as earlier versions did. A glob is matched against the project-relative paths of the files that `mutate` matches (dot files and dot directories included), so it cannot add a file that `mutate` leaves out. Negated (`!`) globs are rejected, and the runner warns about a glob that matches none of the files. See [Which mutated files the dry run imports](#which-mutated-files-the-dry-run-imports). |
|
|
340
|
+
| `bun.importDiscovery` | `'scan'` or `'run'` | `'scan'` | How the dry run finds out which mutated files the tests load. `'scan'`: by reading the import statements of the test files and preloads, with a [plain run](#terms) of the tests first only when the import statements cannot settle it. `'run'`: always with a plain run of the tests first, which also finds files that a package loads, at the cost of a second run of your suite. When the tests' imports and `bun.alwaysImport` together cover every mutated file, there is nothing to find out, and either value gives one run. |
|
|
257
341
|
| `bun.smol` | `boolean` | `false` | Pass Bun's `--smol` to every process: a smaller JavaScriptCore heap at some cost to speed. |
|
|
258
342
|
| `bun.maxChildRss` | `number` (bytes, >= 0) | none | Soft memory ceiling per `bun test` process. One that exceeds it is killed and that run scored Timeout. |
|
|
259
343
|
| `bun.rssCheckIntervalMs` | `number` (ms, >= 0) | `1000` | How often to check `maxChildRss`. |
|
|
260
344
|
| `bun.maxSpawnDepth` | integer (>= 1) | `1` | How deeply `bun test` processes may nest before the runner refuses to start another. Raise it only if your own tests run this runner; see [the troubleshooting entry](#the-dry-run-fails). |
|
|
345
|
+
| `bun.dryRunOutputFile` | `string` (non-empty) | none | A file to write the dry run's complete `bun test` output (stdout and stderr) to when the dry run's data-completeness check fails; without it nothing is written. A relative path resolves against the directory Stryker was started in (your project), not the sandbox, with or without `inPlace`; missing parent directories are created. Each failure replaces the file atomically (written to a new file beside it with mode 0600, then renamed over it; several workers or runs on one path: the last one wins, and the file is always one complete log). A symbolic link in a parent directory is followed; a symbolic link or a directory at the path itself is refused. Saving gets 5 seconds, so a slow disk cannot turn the error into a timeout: after that the error says saving took too long. Removed from it: colour codes, the paths of inspector addresses, the fragment of `debug.bun.sh` links and this run's tokens. Anything else the tests or the command line print, credentials included, is saved as printed, so check the file before sharing it or collecting it in CI. Each stream is kept whole up to 16 Mi (16 777 216) characters, and a longer one is cut in the middle, which the file says. See [the troubleshooting entry](#the-dry-run-fails). |
|
|
261
346
|
|
|
262
347
|
### Example with every option
|
|
263
348
|
|
|
@@ -274,10 +359,13 @@ export default {
|
|
|
274
359
|
env: { NODE_ENV: 'test' },
|
|
275
360
|
bunArgs: ['--randomize'], // the dry run randomizes; mutant runs never do
|
|
276
361
|
testFiles: ['tests'], // a directory: every test file below it (omit to auto-discover)
|
|
362
|
+
alwaysImport: ['src/plugins/**'], // imported before the tests even if no test loads them; 'all' for every mutated file
|
|
363
|
+
importDiscovery: 'scan', // 'run': always make a plain run of the tests first
|
|
277
364
|
smol: true,
|
|
278
365
|
maxChildRss: 1_500_000_000, // about 1.5 GB per bun test process
|
|
279
366
|
rssCheckIntervalMs: 1000,
|
|
280
367
|
maxSpawnDepth: 1,
|
|
368
|
+
dryRunOutputFile: 'reports/bun-dry-run-output.log', // written only when the dry run fails its completeness check
|
|
281
369
|
},
|
|
282
370
|
};
|
|
283
371
|
```
|
|
@@ -330,19 +418,352 @@ the runner warns once when it finds any. Details, including the command-line len
|
|
|
330
418
|
|
|
331
419
|
`bun test --config` replaces your bunfig rather than adding to it, so the runner hands bun a
|
|
332
420
|
sanitized copy of yours. Everything outside `[test]` is kept. In `[test]`, `preload`, `root`,
|
|
333
|
-
`pathIgnorePatterns`, `timeout`, `smol`, `randomize` and `seed` are kept; `coverage`
|
|
334
|
-
`onlyFailures`
|
|
335
|
-
dropped. Mutant runs never randomize the test order
|
|
336
|
-
|
|
421
|
+
`pathIgnorePatterns`, `timeout`, `smol`, `randomize` and `seed` are kept; `coverage` is forced
|
|
422
|
+
off, and `onlyFailures` is forced off for the dry run; `retry` and `rerunEach` are dropped with a
|
|
423
|
+
warning; anything else is dropped. Mutant runs never randomize the test order, and in them bun
|
|
424
|
+
lists only failing tests. Your `[test].preload` files run before the runner's own
|
|
425
|
+
[preload](#terms). Details:
|
|
337
426
|
[the sanitized config](docs/internals.md#your-bunfigtoml-the-sanitized-config).
|
|
338
427
|
|
|
428
|
+
## Which mutated files the dry run imports
|
|
429
|
+
|
|
430
|
+
**In the normal case you need to do nothing.** Before the dry run's tests start, the runner imports
|
|
431
|
+
the mutated files that your tests load, so that their module-level code runs outside any test and
|
|
432
|
+
its mutants are [static mutants](#terms), the same on every run. It does not import a file that no
|
|
433
|
+
test loads, and a mutant there that no test reaches is NoCoverage. That way a file that fails when
|
|
434
|
+
it is imported on its own, such as an app's entry point, does not break the dry run.
|
|
435
|
+
|
|
436
|
+
To find the files, the runner reads the import statements of your test files and preloads
|
|
437
|
+
(`[test].preload` in your bunfig, and `--preload` in `bun.bunArgs`), with a short `bun` process
|
|
438
|
+
that runs none of your code. Then:
|
|
439
|
+
|
|
440
|
+
- If the tests import every mutated file, the runner imports all of them first and runs the tests
|
|
441
|
+
once, as earlier versions did.
|
|
442
|
+
- If some files are left out and nothing in your code could load them, the runner imports the rest
|
|
443
|
+
and runs the tests once, while it checks that the left-out files really do not load.
|
|
444
|
+
- If your code could load a left-out file in a way that the import statements do not show, the
|
|
445
|
+
runner first makes a [plain run](#terms) of the tests with nothing imported, notes which mutated
|
|
446
|
+
files load, and then makes the dry run proper with those files imported first
|
|
447
|
+
([details](#if-the-dry-run-runs-your-tests-twice)).
|
|
448
|
+
|
|
449
|
+
When some files are left out, an info line after the dry run says which ones, for example:
|
|
450
|
+
|
|
451
|
+
> `Dry run: of the <N> files matched by mutate, the runner imports <M> before the tests: <M> that the test files or preloads import statically. It does not import the other <K> itself: <files>. If the tests do load one of those in a way the runner cannot see (through a package, a worker or a child process), add it to bun.alwaysImport.`
|
|
452
|
+
|
|
453
|
+
The two options that change what is imported are `bun.alwaysImport` and `bun.importDiscovery`
|
|
454
|
+
([options table](#configuration)). With Stryker's `incremental` set, every message below that
|
|
455
|
+
names `bun.alwaysImport` ends with:
|
|
456
|
+
`Results saved before the change are reused: run once with --force over the whole mutate scope, not only the files named here.`
|
|
457
|
+
How the runner decides, in full:
|
|
458
|
+
[Which mutated files are imported first](docs/internals.md#which-mutated-files-are-imported-first).
|
|
459
|
+
|
|
460
|
+
The rest of this section walks through the cases where you might need to act.
|
|
461
|
+
|
|
462
|
+
### If the dry run runs your tests twice
|
|
463
|
+
|
|
464
|
+
**The situation.** Your tests, or the code that they load, can reach a mutated file in a way that
|
|
465
|
+
the runner cannot read from the import statements, for example:
|
|
466
|
+
|
|
467
|
+
- an `import()` or `require()` whose path is computed rather than written as a string;
|
|
468
|
+
- `createRequire`, `eval`, `new Function`, or a loader such as `Bun.plugin`;
|
|
469
|
+
- an `import()` or `require()` of a mutated file in your source code rather than in a test file or
|
|
470
|
+
preload (lazy routes, say).
|
|
471
|
+
|
|
472
|
+
Some settings stop the runner from reading the imports at all: in your bunfig, a `[loader]`
|
|
473
|
+
section, any of `jsx`, `jsxImportSource`, `jsxFactory` and `jsxFragment`, a `define` whose value is
|
|
474
|
+
not a literal, or `[test].pathIgnorePatterns`; in `bun.bunArgs`, flags such as `--loader`,
|
|
475
|
+
`--define`, `--conditions` or `--tsconfig-override`. `bun.importDiscovery: 'run'` has the same
|
|
476
|
+
effect on purpose.
|
|
477
|
+
|
|
478
|
+
In each case, unless the tests' imports and `bun.alwaysImport` already cover every mutated file,
|
|
479
|
+
the runner makes a plain run of your tests first, with nothing imported, to see which mutated files
|
|
480
|
+
they load, and then the dry run proper, with those files imported first.
|
|
481
|
+
|
|
482
|
+
**The message.** When some files are left out, the info line says "before the tests of the second
|
|
483
|
+
run":
|
|
484
|
+
|
|
485
|
+
> `Dry run: of the <N> files matched by mutate, the runner imports <M> before the tests of the second run: the <M> that a first run of the tests was seen to load. It does not import the other <K> itself: <files>. If the tests do load one of those in a way the runner cannot see (through a package, a worker or a child process), add it to bun.alwaysImport.`
|
|
486
|
+
|
|
487
|
+
If what is left of Stryker's time budget for the dry run looks too short for the next run, a
|
|
488
|
+
warning says so:
|
|
489
|
+
|
|
490
|
+
> `The dry run has used <x> s and <y> s remain of dryRunTimeoutMinutes (<n>); it now runs the tests again. If the initial test run times out, raise dryRunTimeoutMinutes to at least <m>.`
|
|
491
|
+
|
|
492
|
+
**What it means.** One more run of your suite, in the dry run only, so the dry run takes about
|
|
493
|
+
twice as long. Each run is limited by `bun.timeout`. Mutant runs are unchanged, and the extra run
|
|
494
|
+
does not make their timeouts longer.
|
|
495
|
+
|
|
496
|
+
**What to do.**
|
|
497
|
+
|
|
498
|
+
1. To see why, run `bunx stryker run --logLevel debug` and look for the line that starts
|
|
499
|
+
`Import scan: dynamic` (its `reasons:` name the file and what the runner could not read),
|
|
500
|
+
`The import scan was not started:` (it names the setting) or, at info,
|
|
501
|
+
`The import scan gave no usable answer:`.
|
|
502
|
+
2. If you can, change what the reason names: write the path as a string, or choose the test files
|
|
503
|
+
with `[test].root` or `bun.testFiles` instead of `[test].pathIgnorePatterns`.
|
|
504
|
+
3. Otherwise, the runner makes one run only when every mutated file is either imported by the tests
|
|
505
|
+
or listed in `bun.alwaysImport`. Listing only the file that the computed `import()` loads is not
|
|
506
|
+
enough while other files are still left out. If the files that the info line lists can be
|
|
507
|
+
imported safely before the tests, list them all:
|
|
508
|
+
|
|
509
|
+
```javascript
|
|
510
|
+
bun: {
|
|
511
|
+
alwaysImport: ['src/routes/**', 'src/jobs/**'],
|
|
512
|
+
},
|
|
513
|
+
```
|
|
514
|
+
|
|
515
|
+
Do not list a file that fails when it is imported outside its real environment, such as an
|
|
516
|
+
app's entry point. If no test is meant to cover such a file, you can leave it out of `mutate`
|
|
517
|
+
instead (with a `'!src/main.ts'` entry, say). When the runner cannot read the imports at all
|
|
518
|
+
(the bunfig and `bun.bunArgs` settings above), only a `bun.alwaysImport` that keeps every mutated
|
|
519
|
+
file, such as `'all'`, gives one run.
|
|
520
|
+
4. Or accept the extra run. If the dry run then times out, raise Stryker's `dryRunTimeoutMinutes`.
|
|
521
|
+
Both runs must run the same code, so if you use `--randomize`, also give a `--seed`.
|
|
522
|
+
|
|
523
|
+
### If a mutated file fails when it is imported before the tests
|
|
524
|
+
|
|
525
|
+
**The situation.** This is the problem that the change fixed for files that no test loads
|
|
526
|
+
([#3](https://github.com/hughescr/stryker-bun-runner/issues/3)). It can still happen for a file
|
|
527
|
+
that a test does load, or that you list in `bun.alwaysImport`, when the file needs something that a
|
|
528
|
+
test sets up first: a DOM, a global, an environment variable.
|
|
529
|
+
|
|
530
|
+
**The message.** A warning for each import that threw:
|
|
531
|
+
|
|
532
|
+
> `Importing <file> before the tests failed: <error>. The dry run continued, as earlier versions did without saying so. A test that loads this file afterwards gets the same error.`
|
|
533
|
+
|
|
534
|
+
The tests that load the file then usually fail, and Stryker lists them. When the dry run made a
|
|
535
|
+
plain run first, and that passed, an error names the files that it imported:
|
|
536
|
+
|
|
537
|
+
> `The second run of the dry run failed although the first, a plain run of the same tests, passed. The second run imports the <n> mutated files the plain run loaded before the tests, so that their module-level code is not credited to whichever test loads them first; one of those imports probably broke the tests: <files>. Imports that threw: <file>: <error>. Make that file importable before the tests, or remove it from mutate.`
|
|
538
|
+
|
|
539
|
+
(The `Imports that threw:` sentence appears only when an import threw. If some of the files were
|
|
540
|
+
imported only because `bun.alwaysImport` lists them, the message counts those separately.)
|
|
541
|
+
|
|
542
|
+
If the file fails a little later instead (an error from a timer, or a promise that rejects), the
|
|
543
|
+
dry run fails its [completeness check](#the-dry-run-fails), and the message may name your file from
|
|
544
|
+
a stack frame in one of bun's `Unhandled error between tests` blocks. A named file alone does not
|
|
545
|
+
prove that it caused the error.
|
|
546
|
+
|
|
547
|
+
**What it means.** Importing that file before any test ran broke it, or broke the tests that use
|
|
548
|
+
it.
|
|
549
|
+
|
|
550
|
+
**What to do.**
|
|
551
|
+
|
|
552
|
+
1. If no test loads the file and it is in `bun.alwaysImport`, take it out of `bun.alwaysImport`.
|
|
553
|
+
2. If the file needs a setup that your tests do, move that setup into a preload. Code at the top
|
|
554
|
+
level of a `[test].preload` file runs before the runner imports anything:
|
|
555
|
+
|
|
556
|
+
```toml
|
|
557
|
+
# bunfig.toml
|
|
558
|
+
[test]
|
|
559
|
+
preload = ["./tests/setup-dom.ts"]
|
|
560
|
+
```
|
|
561
|
+
|
|
562
|
+
3. Otherwise, make the file importable on its own (move its side effects into a function that the
|
|
563
|
+
app calls), or leave it out of `mutate`.
|
|
564
|
+
|
|
565
|
+
A related case fixes itself. When a test file names a file in an `import()` or `require()` that
|
|
566
|
+
never runs (a dead branch, a skipped test), the runner imports that file first too. If the dry run
|
|
567
|
+
then fails, the runner makes a plain run, and if that passes, it leaves out the files that the plain
|
|
568
|
+
run did not load and tries again. It warns:
|
|
569
|
+
|
|
570
|
+
> `The first run of the dry run failed while the runner imported first, among others, <n> files that test files or preloads reach only through a literal import() or require(). A plain run of the tests then passed without loading <k> of them, the likely cause: <files>. The runner no longer imports them. This took three runs; remove the import() or require() that never runs, or set bun.importDiscovery to 'run'.`
|
|
571
|
+
|
|
572
|
+
### If the first, plain run of the tests fails
|
|
573
|
+
|
|
574
|
+
**The situation.** The dry run made a [plain run](#terms) of your tests first, and it failed. A
|
|
575
|
+
test that passed only because earlier versions imported every mutated file before the tests fails
|
|
576
|
+
here, because nothing is imported first.
|
|
577
|
+
|
|
578
|
+
**The message.** An error, followed by bun's own output:
|
|
579
|
+
|
|
580
|
+
> `stryker-bun-runner: the first run of the dry run (a plain run of the tests, with no mutated file imported first) did not complete cleanly: <reasons>. The second run was not made.`
|
|
581
|
+
|
|
582
|
+
(After a discarded run it says `the second run` and `The third run was not made.`)
|
|
583
|
+
|
|
584
|
+
**What it means.** The plain run failed a test, raised an error outside any test, exited without
|
|
585
|
+
bun's summary (a test called `process.exit`), was killed (by `bun.timeout` or `bun.maxChildRss`),
|
|
586
|
+
or left no record that it finished. The reasons say which.
|
|
587
|
+
|
|
588
|
+
**What to do.**
|
|
589
|
+
|
|
590
|
+
1. Run `bun test --max-concurrency=1`, which runs the tests one at a time with nothing imported
|
|
591
|
+
first, as the plain run does, and fix what fails.
|
|
592
|
+
2. If a test depends on a mutated file that it never imports (it relies on that file's side
|
|
593
|
+
effects), import the file in the test or in a preload. The runner then sees it in the import
|
|
594
|
+
statements.
|
|
595
|
+
3. Or avoid the plain run with `bun.alwaysImport: 'all'`
|
|
596
|
+
([the earlier behaviour](#if-you-want-the-earlier-behaviour)).
|
|
597
|
+
|
|
598
|
+
### If a test loads a mutated file late
|
|
599
|
+
|
|
600
|
+
**The situation.** A test loads a mutated file inside a test or a hook rather than through the
|
|
601
|
+
imports at the top of a test file. That is fine when the runner can read the load: a literal
|
|
602
|
+
`import('../src/x')` in a test file, or one that leads to a plain run first
|
|
603
|
+
([above](#if-the-dry-run-runs-your-tests-twice)). It needs help when the load goes through code
|
|
604
|
+
that the runner does not read, such as a package (a mocking helper given a path, a framework that
|
|
605
|
+
loads files from a directory).
|
|
606
|
+
|
|
607
|
+
**The message.** If the runner ran the tests once and saw the file load, it warns, throws that run
|
|
608
|
+
away and starts again:
|
|
609
|
+
|
|
610
|
+
> `<file> was loaded during the dry run, but the scan of the test files' imports found no route to it. The run is discarded, and the dry run starts again with a plain run of the tests that observes what they load; if that run is accepted, the runner attempts a third run to publish the results. To avoid that, add the file to bun.alwaysImport or set bun.importDiscovery to 'run'.`
|
|
611
|
+
|
|
612
|
+
If the plain run did not load the file but the dry run proper did, after the runner's imports, the
|
|
613
|
+
dry run stops:
|
|
614
|
+
|
|
615
|
+
> `stryker-bun-runner: <file> was loaded during the second run of the dry run (<where>) but not during the first, so the runner had not imported it before the tests. Add it to bun.alwaysImport. No mutant was scored.`
|
|
616
|
+
|
|
617
|
+
`<where>` is `inside test "<test>"`, `after the imports, outside a test`, or `after the imports`.
|
|
618
|
+
After a discarded run, the message says `third` and `second` instead of `second` and `first`.
|
|
619
|
+
|
|
620
|
+
**What it means.** The first message costs time but nothing else: the runner recovers, with three
|
|
621
|
+
runs of your tests instead of one. The second means that the two runs did not run the same code:
|
|
622
|
+
importing the other files first changed what the tests do, or the tests run in a random order
|
|
623
|
+
without a seed. Its coverage would be credited to whichever test happened to load the file, so the
|
|
624
|
+
runner stops rather than report that.
|
|
625
|
+
|
|
626
|
+
**What to do.**
|
|
627
|
+
|
|
628
|
+
1. Add the file to `bun.alwaysImport`, so that it is imported before the tests:
|
|
629
|
+
|
|
630
|
+
```javascript
|
|
631
|
+
bun: {
|
|
632
|
+
alwaysImport: ['src/plugins/payments.ts'],
|
|
633
|
+
},
|
|
634
|
+
```
|
|
635
|
+
|
|
636
|
+
For the first message you can instead set `bun.importDiscovery: 'run'`, which gives two runs
|
|
637
|
+
instead of three.
|
|
638
|
+
2. If you use `--randomize`, also give a `--seed`.
|
|
639
|
+
3. With `incremental`, run once with `bunx stryker run --force`.
|
|
640
|
+
|
|
641
|
+
### If a mutant run stops the campaign
|
|
642
|
+
|
|
643
|
+
**The situation.** In a mutant run, a test loaded a mutated file that the dry run neither imported
|
|
644
|
+
nor saw load. A package may have loaded it, while in the dry run it did not, because importing the
|
|
645
|
+
other files first changed what the tests did. Or a test replaced the file with `mock.module()`,
|
|
646
|
+
which looks the same in bun's module cache ([see below](#if-a-test-replaces-a-mutated-file-with-mockmodule)).
|
|
647
|
+
Either way, the mutants in that file may have been planned without all of their covering tests, so
|
|
648
|
+
the runner stops the whole Stryker run rather than report results that may be wrong.
|
|
649
|
+
|
|
650
|
+
**The message.** An error, and then Stryker stops with
|
|
651
|
+
`Unexpected error occurred while running Stryker` and exit code 1:
|
|
652
|
+
|
|
653
|
+
> `stryker-bun-runner: <file> was present in bun's module cache in this mutant run (mutant <id>, tests: <tests>) when the mutant first executed, and the dry run neither imported it before the tests nor saw it load. The coverage plan for this run may be incomplete, so the run is stopped: Stryker writes no final report and no incremental file for it (results already reported for earlier mutants, and files from earlier runs, are left as they are). Add <file> to bun.alwaysImport, or set bun.importDiscovery to 'run', and run again; a mock.module() of that file that only some tests make has the same effect and the same remedy.`
|
|
654
|
+
|
|
655
|
+
With `incremental` set, `and run again` is followed by
|
|
656
|
+
`with --force over the whole mutate scope, not only the files named here`.
|
|
657
|
+
|
|
658
|
+
**What it means.** The Stryker run has stopped, with no final report and no incremental file.
|
|
659
|
+
Results that reporters already received for earlier mutants, and files from earlier runs, are as
|
|
660
|
+
they were.
|
|
661
|
+
|
|
662
|
+
**What to do.**
|
|
663
|
+
|
|
664
|
+
1. Add the file to `bun.alwaysImport`, so that the dry run imports it before the tests:
|
|
665
|
+
|
|
666
|
+
```javascript
|
|
667
|
+
bun: {
|
|
668
|
+
alwaysImport: ['src/plugins/payments.ts'],
|
|
669
|
+
},
|
|
670
|
+
```
|
|
671
|
+
|
|
672
|
+
Or set `bun.importDiscovery: 'run'`, so that the dry run always makes a plain run first and sees
|
|
673
|
+
what the tests load, at the cost of a second run of your suite.
|
|
674
|
+
2. With `incremental`, run once with `bunx stryker run --force`: Stryker would otherwise reuse saved
|
|
675
|
+
results for mutants that only run while the file loads.
|
|
676
|
+
3. If a test replaces the file with `mock.module()`, read the next case too.
|
|
677
|
+
|
|
678
|
+
If an error `Could not write the abort marker in <dir> (<error>)` follows the message, the runner
|
|
679
|
+
could not save the note that stops the rest of the Stryker run, so the run may go on: treat its
|
|
680
|
+
results as incomplete.
|
|
681
|
+
|
|
682
|
+
### If a test replaces a mutated file with `mock.module()`
|
|
683
|
+
|
|
684
|
+
**The situation and what it means.** There are two cases.
|
|
685
|
+
|
|
686
|
+
- **The dry run imports the file before the tests**, because the tests load it (the test file
|
|
687
|
+
itself, another test, or the code under test imports it). A `mock.module()` of it at the top of a
|
|
688
|
+
test file or in `beforeAll` then has no effect on code that has already imported it: the test
|
|
689
|
+
sees the real module, and can fail in the dry run. No message says so.
|
|
690
|
+
- **The dry run does not import the file, and some tests mock it.** Bun's module cache shows a
|
|
691
|
+
mocked file as if it were loaded, so a mutant run of one of those tests can stop the Stryker run
|
|
692
|
+
with the message in [the previous case](#if-a-mutant-run-stops-the-campaign).
|
|
693
|
+
|
|
694
|
+
**What to do.**
|
|
695
|
+
|
|
696
|
+
1. Instead of replacing a mutated file with `mock.module()`, pass the dependency in (dependency
|
|
697
|
+
injection), wrap it in a small module of the test's own, or use `spyOn()` on its methods.
|
|
698
|
+
`mock.module()` of modules outside `mutate` (`node:fs`, packages, files that you do not mutate)
|
|
699
|
+
is not affected.
|
|
700
|
+
2. If a mutant run stopped, follow [the previous case](#if-a-mutant-run-stops-the-campaign). Once
|
|
701
|
+
the file is imported before the tests, the first case above applies to it.
|
|
702
|
+
|
|
703
|
+
### If a test runs a mutated file in a worker or a child process
|
|
704
|
+
|
|
705
|
+
**The situation.** A test runs a mutated file only inside a `Worker` or a child process. The runner
|
|
706
|
+
sees only what loads in the test process, so it does not import that file before the tests.
|
|
707
|
+
|
|
708
|
+
**The message.** None. The file's mutants that no test reaches in the test process are NoCoverage.
|
|
709
|
+
|
|
710
|
+
**What to do.** Add the file to `bun.alwaysImport`, which imports it before the tests as earlier
|
|
711
|
+
versions did:
|
|
712
|
+
|
|
713
|
+
```javascript
|
|
714
|
+
bun: {
|
|
715
|
+
alwaysImport: ['src/workers/resize.ts'],
|
|
716
|
+
},
|
|
717
|
+
```
|
|
718
|
+
|
|
719
|
+
### If one of your preloads loads a mutated file at the very end
|
|
720
|
+
|
|
721
|
+
**The situation.** One of your own preloads has an `afterAll` hook that loads a mutated file for
|
|
722
|
+
the first time, and bun runs that hook after the runner's own last `afterAll`. Nothing of the
|
|
723
|
+
runner runs after its own hook, so it never sees the load. Mutant runs do not see it either: they
|
|
724
|
+
check for missed files only at the moment that a mutant first runs, which is normally earlier.
|
|
725
|
+
|
|
726
|
+
**The message.** None. The file is not imported before the tests, and its mutants are NoCoverage.
|
|
727
|
+
|
|
728
|
+
**What to do.** Add the file to `bun.alwaysImport`:
|
|
729
|
+
|
|
730
|
+
```javascript
|
|
731
|
+
bun: {
|
|
732
|
+
alwaysImport: ['src/report-writer.ts'],
|
|
733
|
+
},
|
|
734
|
+
```
|
|
735
|
+
|
|
736
|
+
### If you want the earlier behaviour
|
|
737
|
+
|
|
738
|
+
**The situation.** You want every file that `mutate` matches imported before the tests, as earlier
|
|
739
|
+
versions did, whether or not a test loads it.
|
|
740
|
+
|
|
741
|
+
**What to do.**
|
|
742
|
+
|
|
743
|
+
1. Set `bun.alwaysImport` to `'all'`:
|
|
744
|
+
|
|
745
|
+
```javascript
|
|
746
|
+
export default {
|
|
747
|
+
appendPlugins: ['@hughescr/stryker-bun-runner'],
|
|
748
|
+
testRunner: 'bun',
|
|
749
|
+
bun: { alwaysImport: 'all' },
|
|
750
|
+
};
|
|
751
|
+
```
|
|
752
|
+
|
|
753
|
+
2. With `incremental`, run once with `bunx stryker run --force`.
|
|
754
|
+
|
|
755
|
+
The runner then reads no import statements and runs your tests once. A file that fails when it is
|
|
756
|
+
imported outside its real environment, such as an app's entry point, can break the dry run again.
|
|
757
|
+
|
|
339
758
|
## How it works
|
|
340
759
|
|
|
341
760
|
1. **Startup.** Each Stryker worker checks Bun's version, validates `bun.bunArgs`, writes its
|
|
342
761
|
coverage preload and sanitized bunfig to a private temporary directory, and finds the test files.
|
|
343
762
|
2. **Dry run.** One `bun test` run of the whole suite, one test at a time (`--max-concurrency=1`,
|
|
344
763
|
with `test.concurrent` tests run in turn too), so every mutant reached can be credited to the
|
|
345
|
-
test that reached it.
|
|
764
|
+
test that reached it. Before the tests, the preload imports the mutated files the tests load
|
|
765
|
+
([which ones](#which-mutated-files-the-dry-run-imports); establishing that can take a plain run of
|
|
766
|
+
the tests first). The runner follows each test through Bun's inspector while the preload
|
|
346
767
|
records which mutants each test reached, and how often. Bun's summary, the inspector's events and
|
|
347
768
|
the coverage records must agree exactly, or the dry run fails
|
|
348
769
|
([the completeness gate](docs/internals.md#the-completeness-gate)).
|
|
@@ -356,12 +777,14 @@ More: [Mutant runs](docs/internals.md#mutant-runs), [the dry run in detail](docs
|
|
|
356
777
|
|
|
357
778
|
- **Killed** when a test fails, or when a test file fails to load because of the mutant (bun reports
|
|
358
779
|
a failure count but no failing test).
|
|
359
|
-
- **Survived** when every selected test passes.
|
|
780
|
+
- **Survived** when every selected test passes and bun finishes the run (prints its summary).
|
|
360
781
|
- **Timeout** when the hit limit is exceeded, the time limit is reached, or `bun.maxChildRss` is
|
|
361
782
|
exceeded.
|
|
362
783
|
- **Error** when the run proves nothing either way: the process crashed with no failing test that
|
|
363
784
|
matches a known test, could not be started, exited with an error but no failing test and no failure
|
|
364
|
-
count,
|
|
785
|
+
count, exited 0 before running every selected test (a test, hook or module called
|
|
786
|
+
`process.exit(0)`) with no failing test that matches a known test, or a full-suite fallback ran out of the time Stryker sized
|
|
787
|
+
for the covering tests. An early exit is never Survived: the tests after it never ran.
|
|
365
788
|
|
|
366
789
|
The full table and the reasoning: [How results are scored](docs/internals.md#how-results-are-scored).
|
|
367
790
|
|
|
@@ -561,14 +984,21 @@ Every log message: [Log output](docs/internals.md#log-output).
|
|
|
561
984
|
| Message | Cause | Fix |
|
|
562
985
|
|---|---|---|
|
|
563
986
|
| Stryker lists failing tests | Your suite fails under Stryker, which runs one test at a time. A test that exceeds Bun's `[test].timeout` counts as failed. Each failure message includes the stack from Bun's inspector when Bun reports one. | Run `bun test --max-concurrency=1`. If it fails there too, you have an order-dependent or concurrency-dependent test; fix it. |
|
|
564
|
-
| `
|
|
565
|
-
| `
|
|
987
|
+
| `The second run of the dry run failed although the first, a plain run of the same tests, passed.` (an error line; Stryker then lists the failing tests) | The plain run passed, and importing one of the files before the tests broke them. The message lists the files and the imports that threw. | See [If a mutated file fails when it is imported before the tests](#if-a-mutated-file-fails-when-it-is-imported-before-the-tests). |
|
|
988
|
+
| `Timeout waiting for inspector URL after <N>ms (raise bun.inspectorTimeout if bun is slow to start)` | Bun did not start in time, or exited first; the message ends with bun's last stderr, with the inspector's addresses and the runner's sync token redacted. | Read that stderr (a preload that fails to resolve, say); raise `bun.inspectorTimeout` on a slow machine. |
|
|
989
|
+
| `Failed to connect to Bun inspector: <error>` | Connecting to the inspector did not succeed within `bun.inspectorTimeout`, or bun exited while the runner was connecting; the message ends with bun's last stderr, with the inspector's addresses and the runner's sync token redacted. | If that stderr says why bun exited, fix that; otherwise raise `bun.inspectorTimeout` on a slow or loaded machine, and re-run. |
|
|
566
990
|
| `Failed to start sync server: <error>` | The runner could not open its local socket on `127.0.0.1`. | Re-run; check that loopback networking is available. |
|
|
567
991
|
| `the dry run's sync connection to the runner` ... `before the runner signalled that it is ready to observe the tests` | The test process lost its connection to the runner before the tests started. | Usually follows another error above it; fix that one. |
|
|
568
992
|
| `Dry run timed out: bun.timeout is <N>ms` (and Stryker reports a timeout) | The dry run outgrew `bun.timeout` plus the 30 s drain handshake allowance. | Raise `bun.timeout` above your full suite's run time. |
|
|
569
993
|
| `Bun test process failed with exit code <N>` or `Bun test process terminated by signal <SIGNAL>` | Bun exited abnormally with no failing test (a missing module, a crash). The message includes stderr. | Fix what the stderr shows. |
|
|
570
|
-
| `stryker-bun-runner: dry run data-completeness check failed — <problems>` | Usually something in your suite: a test or hook that calls `process.exit`, or a test file that fails to load (an unresolvable import, say); the problems listed name it. Otherwise test events were lost on a heavily loaded machine. | Fix the cause in your suite; otherwise re-run, and report it if it recurs. See [the completeness gate](docs/internals.md#the-completeness-gate). |
|
|
994
|
+
| `stryker-bun-runner: dry run data-completeness check failed — <problems>` | Usually something in your suite: a test or hook that calls `process.exit`, an error raised outside any test (the message then shows bun's `Unhandled error between tests` blocks), or a test file that fails to load (an unresolvable import, say); the problems listed name it. Otherwise test events were lost on a heavily loaded machine. | The message is bounded; its last line says which option to set (`bun.dryRunOutputFile`) to save everything bun printed on the next run, or, if you set it, names the file it was saved to: open that first. Fix the cause in your suite; otherwise re-run, and report it if it recurs. If the message names a module of yours from a stack frame in one of bun's error blocks, the runner imported that module before any test ran: see [If a mutated file fails when it is imported before the tests](#if-a-mutated-file-fails-when-it-is-imported-before-the-tests). A named module alone does not prove that it caused the error: the message names it only because a stack frame points at it. `Cannot call test() after the test run has completed` (or the same for a hook) means bun had already ended that test file's run when the call was made, so tests registered from that point were not run. See [the completeness gate](docs/internals.md#the-completeness-gate). |
|
|
571
995
|
| `stryker-bun-runner: the dry run produced no mutant coverage data` | The coverage preload never ran, could not write, or the process exited before its final `afterAll` (a test calls `process.exit`). An error with `coverageAnalysis: 'perTest'`, a warning with `'all'`. | Fix the cause the message names, or set `coverageAnalysis` to `'all'` or `'off'` to run without per-test coverage. |
|
|
996
|
+
| `stryker-bun-runner: the first run of the dry run (a plain run of the tests, with no mutated file imported first) did not complete cleanly: <reasons>. The second run was not made.` (or the second and third run, after a discarded one), followed by bun's own output | The [plain run](#terms) of your tests failed. A test that passed only because earlier versions imported a file before the tests fails here. | See [If the first, plain run of the tests fails](#if-the-first-plain-run-of-the-tests-fails). |
|
|
997
|
+
| `stryker-bun-runner: <file> was loaded during the second run of the dry run (<where>) but not during the first, so the runner had not imported it before the tests. Add it to bun.alwaysImport. No mutant was scored.` | The plain run did not load the file, but the dry run proper loaded it after the runner's imports, so the two runs did not run the same code. | See [If a test loads a mutated file late](#if-a-test-loads-a-mutated-file-late). |
|
|
998
|
+
| `stryker-bun-runner: <n> mutants in <files> (ids <ids>) were reached when the tests ran on their own, and not reached when the <m> files the tests load were imported first, in the second run.` (the message goes on to list the files left out) | The plain run reached mutants that the dry run proper, with the tests' files imported first, did not. Either module-level code depends on a file that was left out of the imports, or the tests do not run the same code every time. | Add the left-out file that the message names to `bun.alwaysImport`, or set `bun.alwaysImport: 'all'`. If you use `--randomize`, also give a `--seed`. |
|
|
999
|
+
| `stryker-bun-runner: cannot tell which mutated files the tests load: <problem>.` | The runner could not trust its own record of which mutated files loaded in this run: for example, code replaced `globalThis.__stryker__`, or the record that the test process writes was missing or unreadable. | Set `bun.alwaysImport: 'all'`, which does not need that record. Report it if it recurs. |
|
|
1000
|
+
| `stryker-bun-runner: cannot write the dry-run plan <file> (<error>)`, or the child prints `[Stryker] Cannot read the dry-run plan <file> (<problem>); stopping instead of running the tests with nothing imported first.` | The file that tells the test process which mutated files to import could not be written or read in the run's temporary directory. | Check the temporary directory (space, permissions; see [Temporary files](docs/internals.md#temporary-files)) and re-run. |
|
|
1001
|
+
| `stryker-bun-runner: cannot write <file> (<error>). The mutant runs need it to watch the <n> files matched by mutate that the dry run neither imported before the tests nor saw load, so the dry run stops here.` | The dry run left some mutated files out of its imports, and could not write the file that mutant runs read to check whether a test loads one of them. | Make the temporary directory writable (free space, permissions), or set `bun.alwaysImport: 'all'`. |
|
|
572
1002
|
| `refusing to spawn` ... `at nesting depth` | Your tests themselves run this runner (they run `stryker run` on a fixture, or create a `BunTestRunner`), so `bun test` processes nest. | Give the inner runner `maxSpawnDepth: 2`: in the Stryker config your test runs (`bun: { maxSpawnDepth: 2 }`), or in the options your test passes. Setting it in your own `stryker.conf.mjs` has no effect. |
|
|
573
1003
|
|
|
574
1004
|
### Warnings during the dry run
|
|
@@ -576,7 +1006,7 @@ Every log message: [Log output](docs/internals.md#log-output).
|
|
|
576
1006
|
| Message | Cause | Fix |
|
|
577
1007
|
|---|---|---|
|
|
578
1008
|
| `The dry run took <N>ms, more than 80% of bun.timeout` | The next, slightly slower dry run may be killed. | Raise `bun.timeout`. |
|
|
579
|
-
| `Test discovery found <N> test file(s) under a "dist" or "build" directory` | Compiled copies of your tests run too. | Set `[test].root
|
|
1009
|
+
| `Test discovery found <N> test file(s) under a "dist" or "build" directory` | Compiled copies of your tests run too. | Set `[test].root`, or use `bun.testFiles`. `[test].pathIgnorePatterns` works too, but then the runner cannot read the tests' imports, so the dry run [runs your tests twice](#if-the-dry-run-runs-your-tests-twice). |
|
|
580
1010
|
| `discoverTestFiles: no test files found in <dir>; falling back to Bun discovery` | Auto-discovery found nothing under the project (or `[test].root`). | Check `[test].root` and your test file names, or set `bun.testFiles`. |
|
|
581
1011
|
| `bun.testFiles contains absolute path(s) and the current working directory appears to be a Stryker sandbox` | Absolute paths point at your original, unmutated files. | Use paths relative to the project. |
|
|
582
1012
|
| `Both Stryker's testFiles option and bun.testFiles are set and select different test files` | Two selections disagree; Stryker's wins. | Remove one, or make them agree. |
|
|
@@ -586,6 +1016,17 @@ Every log message: [Log output](docs/internals.md#log-output).
|
|
|
586
1016
|
| `Bun exited with code <N> and its console output reported <N> failed test(s), but no failing test could be identified` | Usually an unhandled error between tests (a rejected promise nobody awaited). | Look for unawaited async work, especially in the file that ran last. |
|
|
587
1017
|
| `mutant coverage was recorded between tests, after '<test>' completed` | Async work from that test kept running after it ended, or a `beforeAll` ran between tests. | `await` the work in the test. Harmless if it is a `beforeAll`. |
|
|
588
1018
|
| `Failed to write dryRun registry file` | Other workers cannot read the dry run's test names. | Check the temporary directory; mutants still run, with less precise test selection. |
|
|
1019
|
+
| `Dry run: of the <N> files matched by mutate, the runner imports <M> before the tests` ... `It does not import the other <K> itself: <files>.` (info) | Which mutated files the dry run imported before the tests, and why. Shown only when some files were left out. | Nothing, unless a test loads one of the files that it does not import in a way that the runner cannot see (through a package, a worker or a child process): add that file to `bun.alwaysImport`. See [Which mutated files the dry run imports](#which-mutated-files-the-dry-run-imports). |
|
|
1020
|
+
| `<file> was loaded during the dry run, but the scan of the test files' imports found no route to it. The run is discarded, and the dry run starts again` ... | The file loaded during the dry run although the test files' import statements do not lead to it (a package loaded it, say). The runner starts again with a plain run first: three runs in all. A variant names a test file that ran but that the runner did not read. | See [If a test loads a mutated file late](#if-a-test-loads-a-mutated-file-late). |
|
|
1021
|
+
| `The first run of the dry run failed while the runner imported first, among others, <n> files that test files or preloads reach only through a literal import() or require().` ... | A test file names a file in an `import()` or `require()` that never runs (a dead branch, a skipped test), and importing that file first may have broken the run. The runner recovered, in three runs. | Remove the `import()` or `require()` that never runs, or set `bun.importDiscovery: 'run'`. See [the related case](#if-a-mutated-file-fails-when-it-is-imported-before-the-tests). |
|
|
1022
|
+
| `The second run of the dry run (a plain run of the tests, with no mutated file imported first, made because the first run failed) did not complete cleanly either: <reasons>. The first run's result is returned.` | As above, but the plain run failed too, so Stryker sees the first run's failing tests. | Fix the failing tests that Stryker lists. |
|
|
1023
|
+
| `<file> was not loaded in the plain run of the tests, but in the run that publishes it was loaded before the tests, while the runner imported its list first (a file imported first, including one only bun.alwaysImport keeps, or a preload can cause this). It ran before the tests, as in earlier versions.` | A file that the plain run did not load was loaded before the tests in the dry run proper, by one of the files imported first or by a preload. | Nothing: it ran before the tests, as before. |
|
|
1024
|
+
| `Importing <file> before the tests failed: <error>. The dry run continued, as earlier versions did without saying so.` | One of the imports before the tests threw. A test that loads the file afterwards gets the same error. | See [If a mutated file fails when it is imported before the tests](#if-a-mutated-file-fails-when-it-is-imported-before-the-tests). |
|
|
1025
|
+
| `<N> more imports before the tests failed (listed at debug)` | More than ten of the imports before the tests threw. | As above; `--logLevel debug` lists them all. |
|
|
1026
|
+
| `bun test child exceeded maxChildRss (<N> bytes observed) during the dry run's plain run of the tests — killing it` | The plain run of the tests went over `bun.maxChildRss`; the dry run then fails. | Raise `bun.maxChildRss` above what one run of your suite needs. |
|
|
1027
|
+
| `The dry run has used <x> s and <y> s remain of dryRunTimeoutMinutes (<n>); it now runs the tests again.` | The dry run needs another run of the tests, which may not fit in Stryker's time budget for the dry run. | If the dry run then times out, raise `dryRunTimeoutMinutes` to the value that the message suggests. See [If the dry run runs your tests twice](#if-the-dry-run-runs-your-tests-twice). |
|
|
1028
|
+
| `bun.alwaysImport pattern "<pattern>" matches none of the <N> files matched by mutate` | A glob in `bun.alwaysImport` keeps no file. It is matched against the project-relative paths of the files that `mutate` matches, and cannot add other files. | Fix the glob, or remove it. |
|
|
1029
|
+
| `The import scan gave no usable answer: <reason>.` (info) | The short `bun` process that reads the tests' imports failed or timed out, so the runner makes a plain run of the tests first. | Nothing; report it if it recurs. |
|
|
589
1030
|
|
|
590
1031
|
Inspector diagnostics such as `Inspector data looks abnormal` need no action unless the dry run
|
|
591
1032
|
also fails; see [Inspector diagnostics](docs/internals.md#inspector-diagnostics).
|
|
@@ -597,22 +1038,46 @@ also fails; see [Inspector diagnostics](docs/internals.md#inspector-diagnostics)
|
|
|
597
1038
|
| `Mutant <id>: bun test terminated by <SIGNAL>` ... `scoring as Error rather than Killed` | The process crashed (SIGSEGV, an out-of-memory kill) without a failing test. | A few can be a real crash in your suite; many mean memory pressure: lower `concurrency`, set `bun.maxChildRss`. |
|
|
598
1039
|
| `Mutant <id>: could not start bun test: <error>` | Bun could not be started. | Check `bun.bunPath`, `PATH` and system limits. |
|
|
599
1040
|
| `Mutant <id>: bun test exited with code <N> but reported no failing test and no fail/error count` | Bun failed before running tests (a missing preload, an unreadable bunfig). | Read the output in the warning. |
|
|
1041
|
+
| `Mutant <id>: bun exited 0 before running every selected test` ... `scoring as Error rather than Survived` | The mutant made a test, hook or module call `process.exit(0)`, so bun stopped without its summary. | Usually nothing: the mutant changed behaviour. If many mutants do this, look for a `process.exit` in the code under test. |
|
|
600
1042
|
| `Mutant <id>: inconclusive timeout, scoring as Error rather than Timeout` | A full-suite fallback did not finish within the time Stryker sized for the covering tests. | Raise Stryker's `timeoutMS` or `timeoutFactor`. |
|
|
601
1043
|
| `Mutant <id>: --test-name-pattern matched 0 tests` | The mutant changed a test's name (often an interpolated `it.each` title); the runner retries with the full suite. | Usually nothing; spot-check that the mutant changes a title. |
|
|
602
|
-
| `no exact-name registry available` or `missing from exact-name registry` | A worker could not match test ids to bun's exact names; tests whose titles contain ` > ` may have been skipped in that run. | Check for an earlier registry warning; re-run. |
|
|
1044
|
+
| `no exact-name registry available` or `missing from exact-name registry` | A worker could not match test ids to bun's exact names; tests whose titles contain ` > ` may have been skipped in that run. | Check for an earlier `Failed to write dryRun registry file` warning; re-run. |
|
|
603
1045
|
| `could not be resolved to dry-run test ids` or `no killing test identifiable — emitting empty killedBy` | A killed mutant whose killing test is unknown; it re-runs on every incremental run. | Usually a test whose output imitates bun's; harmless otherwise. |
|
|
604
1046
|
| `bun test child exceeded maxChildRss` | A run went over `bun.maxChildRss`; scored Timeout. | Expected for runaway mutants; raise the limit if many hit it. |
|
|
1047
|
+
| `stryker-bun-runner: <file> was present in bun's module cache in this mutant run (mutant <id>, tests: <tests>) when the mutant first executed, and the dry run neither imported it before the tests nor saw it load.` ..., then Stryker stops with `Unexpected error occurred while running Stryker` and exit code 1 | A test loaded a mutated file that the dry run left out (a package loaded it, say), or replaced it with `mock.module()`. The runner stops the whole Stryker run, which saves no final report and no incremental file. | See [If a mutant run stops the campaign](#if-a-mutant-run-stops-the-campaign). |
|
|
1048
|
+
| `A mutant run could not use its watch list (<problem>), so it could not check for files the dry run missed; its result stands.` | The runner could not read the list of mutated files that the dry run left out, so this mutant run could not check whether a test loaded one of them. | Check the temporary directory; re-run if it recurs. |
|
|
1049
|
+
| `Could not write the abort marker in <dir> (<error>)` | A mutant run found a file that the dry run missed (the message above it), but the runner could not save the note that stops the rest of the Stryker run, so the run may go on. | Treat the run's results as incomplete; fix the temporary directory and act on the message above it. |
|
|
605
1050
|
| Many mutants Timeout | Stryker's timeout is tight for your suite, or many mutants loop forever. Infinite loops stopped by the hit limit carry the reason `Hit limit reached (count/limit)`: open the mutant in the HTML report, or read `statusReason` in Stryker's JSON report. | For the others, raise `timeoutMS` or `timeoutFactor`. |
|
|
606
1051
|
| Every mutant runs the whole suite | No per-test coverage: `coverageAnalysis` is not `'perTest'`, or coverage was missing. | Use `'perTest'` and check the dry-run warnings. |
|
|
607
|
-
| The score changed after upgrading this plugin | Scoring has changed over time (for example, a crash without a matching failing test is now Error, and a test file that a mutant stops from loading is Killed). | Expected. See [Upgrading from 1.4](#upgrading-from-14), [How results are scored](#how-results-are-scored), and the [commit history](https://github.com/hughescr/stryker-bun-runner/commits/main) for what changed. |
|
|
1052
|
+
| The score changed after upgrading this plugin | Scoring has changed over time (for example, a crash without a matching failing test is now Error, and a test file that a mutant stops from loading is Killed). | Expected. See [Upgrading: the dry run imports only what your tests load](#upgrading-the-dry-run-imports-only-what-your-tests-load), [Upgrading from 1.5](#upgrading-from-15), [Upgrading from 1.4](#upgrading-from-14), [How results are scored](#how-results-are-scored), and the [commit history](https://github.com/hughescr/stryker-bun-runner/commits/main) for what changed. |
|
|
608
1053
|
|
|
609
1054
|
## Limitations
|
|
610
1055
|
|
|
611
1056
|
- **One test at a time.** Tests run sequentially, `test.concurrent` included, so per-test coverage
|
|
612
1057
|
is exact. Mutation runs are slower than a parallel `bun test`.
|
|
613
|
-
- **`mock.module()` of a mutated file** has no effect
|
|
614
|
-
the dry run imports
|
|
615
|
-
|
|
1058
|
+
- **`mock.module()` of a mutated file** that the tests load has no effect in the dry run, because
|
|
1059
|
+
the dry run imports that file before the tests run. Use dependency injection or spy on methods
|
|
1060
|
+
instead ([details](#if-a-test-replaces-a-mutated-file-with-mockmodule)).
|
|
1061
|
+
- **Files that load where the runner cannot see them** are not imported before the tests, and a
|
|
1062
|
+
mutant there that no test reaches is NoCoverage. In each case, list the file in
|
|
1063
|
+
`bun.alwaysImport`:
|
|
1064
|
+
- a file that runs only in a worker or a child process;
|
|
1065
|
+
- a file that only a package loads, and only when the other files are not imported first
|
|
1066
|
+
(importing them first can change what the tests do). `bun.importDiscovery: 'run'` also helps
|
|
1067
|
+
here. If a mutant run later sees such a file loaded, it stops the Stryker run and names the file
|
|
1068
|
+
([what to do](#if-a-mutant-run-stops-the-campaign)); otherwise nothing says so;
|
|
1069
|
+
- a file that `mutate` matches but in which Stryker made no mutants, when it is unloaded again,
|
|
1070
|
+
or still loading, at the end of the dry run;
|
|
1071
|
+
- a file that one of your preloads first loads in an `afterAll` hook that bun runs after the
|
|
1072
|
+
runner's own last one ([details](#if-one-of-your-preloads-loads-a-mutated-file-at-the-very-end)).
|
|
1073
|
+
Nothing warns about this one.
|
|
1074
|
+
- **Mutants credited to a different test.** Where a file's module-level code depends on a file that
|
|
1075
|
+
no test loads, its mutants can be credited to a different test than when every file was imported
|
|
1076
|
+
first. Listing the file that the code depends on in `bun.alwaysImport` restores the earlier
|
|
1077
|
+
result.
|
|
1078
|
+
- **Some mutant runs cannot check for missed files.** When one of your preloads has already run a
|
|
1079
|
+
mutant's code before the tests start, that mutant's run does not check for files that the dry run
|
|
1080
|
+
missed, because it cannot tell a load that the mutant caused from one that the tests made.
|
|
616
1081
|
- **Cross-file order dependence.** Mutant runs order files by cost, not as in the dry run, so a
|
|
617
1082
|
global change one test file leaves behind (an unrestored `mock.module()`) can change results.
|
|
618
1083
|
- **No randomized order in mutant runs**, and `retry`/`rerunEach` are not supported.
|
|
@@ -626,13 +1091,15 @@ also fails; see [Inspector diagnostics](docs/internals.md#inspector-diagnostics)
|
|
|
626
1091
|
|
|
627
1092
|
[docs/internals.md](docs/internals.md) covers how the runner works in detail:
|
|
628
1093
|
|
|
629
|
-
- [Mutant runs](docs/internals.md#mutant-runs): test selection,
|
|
1094
|
+
- [Mutant runs](docs/internals.md#mutant-runs): test selection, test-file ordering, fallbacks
|
|
630
1095
|
- [How results are scored](docs/internals.md#how-results-are-scored) and
|
|
631
1096
|
[the hit limit](docs/internals.md#infinite-loops-the-hit-limit)
|
|
632
|
-
- [The dry run in detail](docs/internals.md#the-dry-run-in-detail):
|
|
633
|
-
the completeness gate, coverage checks
|
|
1097
|
+
- [The dry run in detail](docs/internals.md#the-dry-run-in-detail): which mutated files are imported
|
|
1098
|
+
first, the start and drain handshakes, the completeness gate, coverage checks; and
|
|
1099
|
+
[how mutant runs check for files that the dry run missed](docs/internals.md#the-witness-in-mutant-runs)
|
|
634
1100
|
- [Log output](docs/internals.md#log-output): start and end summaries, repeated warnings
|
|
635
|
-
- [Temporary files](docs/internals.md#temporary-files): the private per-run directory
|
|
1101
|
+
- [Temporary files](docs/internals.md#temporary-files): the private per-run directory, removed when
|
|
1102
|
+
the run ends
|
|
636
1103
|
- [Child processes](docs/internals.md#child-processes): process groups, orphan prevention,
|
|
637
1104
|
recursion containment
|
|
638
1105
|
- [Memory](docs/internals.md#memory) and
|