@hughescr/stryker-bun-runner 1.6.0 → 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 CHANGED
@@ -12,6 +12,8 @@ coverage so that each mutant runs only the tests that reach 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,6 +23,7 @@ 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)
24
27
  - [Upgrading from 1.5](#upgrading-from-15)
25
28
  - [Upgrading from 1.4](#upgrading-from-14)
26
29
  - [Terms](#terms)
@@ -28,6 +31,16 @@ coverage so that each mutant runs only the tests that reach it.
28
31
  - [Configuration](#configuration)
29
32
  - [Example with every option](#example-with-every-option) · [bun.bunArgs](#bunbunargs) ·
30
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)
31
44
  - [How it works](#how-it-works)
32
45
  - [How results are scored](#how-results-are-scored) · [Timeouts](#timeouts)
33
46
  - [Speeding up runs](#speeding-up-runs)
@@ -164,6 +177,40 @@ export default await withTestFilesExcludedFromTypeCheck({
164
177
  });
165
178
  ```
166
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
+
167
214
  ## Upgrading from 1.5
168
215
 
169
216
  Most projects need no config change, but these differ from 1.5:
@@ -258,6 +305,9 @@ Most projects need no config change, but these differ from 1.4:
258
305
  and finish.
259
306
  - **Drain handshake**: at the end of the dry run, the test process waits until the runner confirms
260
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)).
261
311
 
262
312
  ## Requirements and compatibility
263
313
 
@@ -286,10 +336,13 @@ Runner options go under `bun` in your Stryker config. Stryker validates them: an
286
336
  | `bun.env` | `object` of strings | none | Extra environment variables for every `bun test` process (and for the startup `bun --version` check). |
287
337
  | `bun.bunArgs` | `string[]` | none | Extra `bun test` flags. Some are rejected, removed or handled specially; see [bun.bunArgs](#bunbunargs). |
288
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. |
289
341
  | `bun.smol` | `boolean` | `false` | Pass Bun's `--smol` to every process: a smaller JavaScriptCore heap at some cost to speed. |
290
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. |
291
343
  | `bun.rssCheckIntervalMs` | `number` (ms, >= 0) | `1000` | How often to check `maxChildRss`. |
292
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). |
293
346
 
294
347
  ### Example with every option
295
348
 
@@ -306,10 +359,13 @@ export default {
306
359
  env: { NODE_ENV: 'test' },
307
360
  bunArgs: ['--randomize'], // the dry run randomizes; mutant runs never do
308
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
309
364
  smol: true,
310
365
  maxChildRss: 1_500_000_000, // about 1.5 GB per bun test process
311
366
  rssCheckIntervalMs: 1000,
312
367
  maxSpawnDepth: 1,
368
+ dryRunOutputFile: 'reports/bun-dry-run-output.log', // written only when the dry run fails its completeness check
313
369
  },
314
370
  };
315
371
  ```
@@ -369,13 +425,345 @@ lists only failing tests. Your `[test].preload` files run before the runner's ow
369
425
  [preload](#terms). Details:
370
426
  [the sanitized config](docs/internals.md#your-bunfigtoml-the-sanitized-config).
371
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
+
372
758
  ## How it works
373
759
 
374
760
  1. **Startup.** Each Stryker worker checks Bun's version, validates `bun.bunArgs`, writes its
375
761
  coverage preload and sanitized bunfig to a private temporary directory, and finds the test files.
376
762
  2. **Dry run.** One `bun test` run of the whole suite, one test at a time (`--max-concurrency=1`,
377
763
  with `test.concurrent` tests run in turn too), so every mutant reached can be credited to the
378
- test that reached it. The runner follows each test through Bun's inspector while the preload
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
379
767
  records which mutants each test reached, and how often. Bun's summary, the inspector's events and
380
768
  the coverage records must agree exactly, or the dry run fails
381
769
  ([the completeness gate](docs/internals.md#the-completeness-gate)).
@@ -596,14 +984,21 @@ Every log message: [Log output](docs/internals.md#log-output).
596
984
  | Message | Cause | Fix |
597
985
  |---|---|---|
598
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. |
599
- | `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. | Read that stderr (a preload that fails to resolve, say); raise `bun.inspectorTimeout` on a slow machine. |
600
- | `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. | If that stderr says why bun exited, fix that; otherwise raise `bun.inspectorTimeout` on a slow or loaded machine, and re-run. |
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. |
601
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. |
602
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. |
603
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. |
604
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. |
605
- | `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). |
606
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'`. |
607
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. |
608
1003
 
609
1004
  ### Warnings during the dry run
@@ -611,7 +1006,7 @@ Every log message: [Log output](docs/internals.md#log-output).
611
1006
  | Message | Cause | Fix |
612
1007
  |---|---|---|
613
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`. |
614
- | `Test discovery found <N> test file(s) under a "dist" or "build" directory` | Compiled copies of your tests run too. | Set `[test].root` or `[test].pathIgnorePatterns`, or use `bun.testFiles`. |
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). |
615
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`. |
616
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. |
617
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. |
@@ -621,6 +1016,17 @@ Every log message: [Log output](docs/internals.md#log-output).
621
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. |
622
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`. |
623
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. |
624
1030
 
625
1031
  Inspector diagnostics such as `Inspector data looks abnormal` need no action unless the dry run
626
1032
  also fails; see [Inspector diagnostics](docs/internals.md#inspector-diagnostics).
@@ -635,20 +1041,43 @@ also fails; see [Inspector diagnostics](docs/internals.md#inspector-diagnostics)
635
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. |
636
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`. |
637
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. |
638
- | `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. |
639
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. |
640
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. |
641
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`. |
642
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. |
643
- | 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.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. |
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. |
644
1053
 
645
1054
  ## Limitations
646
1055
 
647
1056
  - **One test at a time.** Tests run sequentially, `test.concurrent` included, so per-test coverage
648
1057
  is exact. Mutation runs are slower than a parallel `bun test`.
649
- - **`mock.module()` of a mutated file** has no effect when the module was already imported, because
650
- the dry run imports every mutated file before the tests run. Use dependency injection or spy on
651
- methods instead. [Details](docs/internals.md#test-names-and-coverage-attribution).
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.
652
1081
  - **Cross-file order dependence.** Mutant runs order files by cost, not as in the dry run, so a
653
1082
  global change one test file leaves behind (an unrestored `mock.module()`) can change results.
654
1083
  - **No randomized order in mutant runs**, and `retry`/`rerunEach` are not supported.
@@ -665,8 +1094,9 @@ also fails; see [Inspector diagnostics](docs/internals.md#inspector-diagnostics)
665
1094
  - [Mutant runs](docs/internals.md#mutant-runs): test selection, test-file ordering, fallbacks
666
1095
  - [How results are scored](docs/internals.md#how-results-are-scored) and
667
1096
  [the hit limit](docs/internals.md#infinite-loops-the-hit-limit)
668
- - [The dry run in detail](docs/internals.md#the-dry-run-in-detail): the start and drain handshakes,
669
- 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)
670
1100
  - [Log output](docs/internals.md#log-output): start and end summaries, repeated warnings
671
1101
  - [Temporary files](docs/internals.md#temporary-files): the private per-run directory, removed when
672
1102
  the run ends