@hughescr/stryker-bun-runner 1.6.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +502 -15
- package/dist/index.d.ts +388 -22
- package/dist/index.js +2540 -225
- package/dist/templates/coverage-preload.js +722 -64
- package/dist/templates/import-scan.js +902 -0
- package/package.json +2 -1
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,13 +23,25 @@ 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)
|
|
27
30
|
- [Requirements and compatibility](#requirements-and-compatibility)
|
|
28
31
|
- [Configuration](#configuration)
|
|
29
32
|
- [Example with every option](#example-with-every-option) · [bun.bunArgs](#bunbunargs) ·
|
|
30
|
-
[Choosing the test files](#choosing-the-test-files) · [Your bunfig.toml](#your-bunfigtoml)
|
|
33
|
+
[Choosing the test files](#choosing-the-test-files) · [Your bunfig.toml](#your-bunfigtoml) ·
|
|
34
|
+
[coverageAnalysis](#coverageanalysis)
|
|
35
|
+
- [Which mutated files the dry run imports](#which-mutated-files-the-dry-run-imports)
|
|
36
|
+
- [Tests run twice](#if-the-dry-run-runs-your-tests-twice) ·
|
|
37
|
+
[A file fails when imported first](#if-a-mutated-file-fails-when-it-is-imported-before-the-tests) ·
|
|
38
|
+
[The plain run fails](#if-the-first-plain-run-of-the-tests-fails) ·
|
|
39
|
+
[A test loads a file late](#if-a-test-loads-a-mutated-file-late) ·
|
|
40
|
+
[A mutant run stops the campaign](#if-a-mutant-run-stops-the-campaign) ·
|
|
41
|
+
[`mock.module()`](#if-a-test-replaces-a-mutated-file-with-mockmodule) ·
|
|
42
|
+
[Workers and child processes](#if-a-test-runs-a-mutated-file-in-a-worker-or-a-child-process) ·
|
|
43
|
+
[A preload's last `afterAll`](#if-one-of-your-preloads-loads-a-mutated-file-at-the-very-end) ·
|
|
44
|
+
[The earlier behaviour](#if-you-want-the-earlier-behaviour)
|
|
31
45
|
- [How it works](#how-it-works)
|
|
32
46
|
- [How results are scored](#how-results-are-scored) · [Timeouts](#timeouts)
|
|
33
47
|
- [Speeding up runs](#speeding-up-runs)
|
|
@@ -164,6 +178,48 @@ export default await withTestFilesExcludedFromTypeCheck({
|
|
|
164
178
|
});
|
|
165
179
|
```
|
|
166
180
|
|
|
181
|
+
## Upgrading: the dry run imports only what your tests load
|
|
182
|
+
|
|
183
|
+
Most projects need no config change.
|
|
184
|
+
|
|
185
|
+
Before the dry run's tests start, the runner imports the mutated files, so that their module-level
|
|
186
|
+
code (constants, top-level setup) runs outside any test. Earlier versions imported every file that
|
|
187
|
+
your `mutate` globs match. The runner now imports only the mutated files that your tests load, and
|
|
188
|
+
leaves the others alone. So a file that no test loads, such as an app's entry point that fails
|
|
189
|
+
when it is imported outside a browser, no longer breaks the dry run
|
|
190
|
+
([#3](https://github.com/hughescr/stryker-bun-runner/issues/3)). How the runner finds the files,
|
|
191
|
+
and what to do in the rare cases where it needs help:
|
|
192
|
+
[Which mutated files the dry run imports](#which-mutated-files-the-dry-run-imports).
|
|
193
|
+
|
|
194
|
+
What can change after you upgrade:
|
|
195
|
+
|
|
196
|
+
- **Some results change.** Mutants in the module-level code of a file that no test loads used to be
|
|
197
|
+
[static mutants](#terms), tested against the whole suite (or skipped with `ignoreStatic`). Now
|
|
198
|
+
they are NoCoverage. Where another file's module-level code depended
|
|
199
|
+
on such a file, results in that other file can change in either direction. To keep importing a
|
|
200
|
+
file as before, list it in `bun.alwaysImport`. To go back to the earlier behaviour for every file,
|
|
201
|
+
set `bun.alwaysImport: 'all'` ([how](#if-you-want-the-earlier-behaviour)).
|
|
202
|
+
- **With `incremental`, run once with `--force`** (`bunx stryker run --force`) after upgrading, and
|
|
203
|
+
again each time you change `bun.alwaysImport`. Stryker reuses saved results for mutants that only
|
|
204
|
+
run while a file loads, and one file's module-level code can change the results of mutants in
|
|
205
|
+
other files, so re-running only the files that you changed is not enough.
|
|
206
|
+
- **The dry run may run your tests twice.** When your code could load a mutated file in a way that
|
|
207
|
+
the runner cannot work out from the import statements, it first runs your tests once with nothing
|
|
208
|
+
imported, to see which files they load ([details](#if-the-dry-run-runs-your-tests-twice)).
|
|
209
|
+
- **A test that passed only because a file was imported first** can now fail, and the dry run
|
|
210
|
+
stops ([what to do](#if-the-first-plain-run-of-the-tests-fails)).
|
|
211
|
+
- **A file that only a package, a worker or a child process loads** is not seen by the runner.
|
|
212
|
+
List it in `bun.alwaysImport`. If a mutant run later finds that a package loaded such a file, it
|
|
213
|
+
stops the Stryker run and names the file ([what to do](#if-a-mutant-run-stops-the-campaign)).
|
|
214
|
+
- **`coverageAnalysis: 'all'` and `'off'` now do what Stryker says they do**
|
|
215
|
+
([coverageAnalysis](#coverageanalysis)). Before, the runner gave Stryker per-test coverage
|
|
216
|
+
whatever the value, so they behaved like `'perTest'`. Now, with `'all'`, each mutant that some
|
|
217
|
+
test reaches runs your whole suite; with `'off'`, every mutant does, and a mutant no test reaches
|
|
218
|
+
is Survived instead of NoCoverage. If you set either one, the mutant runs get slower; to keep the
|
|
219
|
+
earlier speed, set `'perTest'` (or remove the setting: it is Stryker's default). With
|
|
220
|
+
`incremental`, run once with `--force` after upgrading; after that, see
|
|
221
|
+
[coverageAnalysis](#coverageanalysis) for when to use it again.
|
|
222
|
+
|
|
167
223
|
## Upgrading from 1.5
|
|
168
224
|
|
|
169
225
|
Most projects need no config change, but these differ from 1.5:
|
|
@@ -258,6 +314,9 @@ Most projects need no config change, but these differ from 1.4:
|
|
|
258
314
|
and finish.
|
|
259
315
|
- **Drain handshake**: at the end of the dry run, the test process waits until the runner confirms
|
|
260
316
|
it has received every test event, so none are lost on a busy machine.
|
|
317
|
+
- **Plain run**: a run of your tests that the dry run sometimes makes first, with no mutated file
|
|
318
|
+
imported before the tests, only to see which mutated files the tests load. Its results are not
|
|
319
|
+
reported to Stryker ([when it happens](#if-the-dry-run-runs-your-tests-twice)).
|
|
261
320
|
|
|
262
321
|
## Requirements and compatibility
|
|
263
322
|
|
|
@@ -286,10 +345,13 @@ Runner options go under `bun` in your Stryker config. Stryker validates them: an
|
|
|
286
345
|
| `bun.env` | `object` of strings | none | Extra environment variables for every `bun test` process (and for the startup `bun --version` check). |
|
|
287
346
|
| `bun.bunArgs` | `string[]` | none | Extra `bun test` flags. Some are rejected, removed or handled specially; see [bun.bunArgs](#bunbunargs). |
|
|
288
347
|
| `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). |
|
|
348
|
+
| `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). |
|
|
349
|
+
| `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
350
|
| `bun.smol` | `boolean` | `false` | Pass Bun's `--smol` to every process: a smaller JavaScriptCore heap at some cost to speed. |
|
|
290
351
|
| `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
352
|
| `bun.rssCheckIntervalMs` | `number` (ms, >= 0) | `1000` | How often to check `maxChildRss`. |
|
|
292
353
|
| `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). |
|
|
354
|
+
| `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
355
|
|
|
294
356
|
### Example with every option
|
|
295
357
|
|
|
@@ -306,10 +368,13 @@ export default {
|
|
|
306
368
|
env: { NODE_ENV: 'test' },
|
|
307
369
|
bunArgs: ['--randomize'], // the dry run randomizes; mutant runs never do
|
|
308
370
|
testFiles: ['tests'], // a directory: every test file below it (omit to auto-discover)
|
|
371
|
+
alwaysImport: ['src/plugins/**'], // imported before the tests even if no test loads them; 'all' for every mutated file
|
|
372
|
+
importDiscovery: 'scan', // 'run': always make a plain run of the tests first
|
|
309
373
|
smol: true,
|
|
310
374
|
maxChildRss: 1_500_000_000, // about 1.5 GB per bun test process
|
|
311
375
|
rssCheckIntervalMs: 1000,
|
|
312
376
|
maxSpawnDepth: 1,
|
|
377
|
+
dryRunOutputFile: 'reports/bun-dry-run-output.log', // written only when the dry run fails its completeness check
|
|
313
378
|
},
|
|
314
379
|
};
|
|
315
380
|
```
|
|
@@ -369,13 +434,391 @@ lists only failing tests. Your `[test].preload` files run before the runner's ow
|
|
|
369
434
|
[preload](#terms). Details:
|
|
370
435
|
[the sanitized config](docs/internals.md#your-bunfigtoml-the-sanitized-config).
|
|
371
436
|
|
|
437
|
+
### coverageAnalysis
|
|
438
|
+
|
|
439
|
+
**Leave it at `'perTest'`, Stryker's default, unless you have a reason not to.** Stryker's
|
|
440
|
+
`coverageAnalysis` option decides how much the dry run tells Stryker about which tests reach which
|
|
441
|
+
mutants, and so how many tests each mutant runs:
|
|
442
|
+
|
|
443
|
+
| Value | What the runner records in the dry run | What each mutant runs |
|
|
444
|
+
|---|---|---|
|
|
445
|
+
| `'perTest'` (default) | which tests reach each mutant | only the tests that reach it ([static mutants](#terms): every test); a mutant no test reaches is NoCoverage |
|
|
446
|
+
| `'all'` | only whether some test reaches each mutant | every test, for each mutant that some test reaches; a mutant no test reaches is NoCoverage |
|
|
447
|
+
| `'off'` | nothing about mutants | every test, for every mutant; no mutant is NoCoverage (one no test reaches is Survived) |
|
|
448
|
+
|
|
449
|
+
What differs between the three values is which tests each mutant runs. With `'all'` and `'off'`
|
|
450
|
+
each mutant that some test reaches runs your whole suite, so the mutant runs take longer, often
|
|
451
|
+
much longer, and `'off'` runs the whole suite for the mutants no test reaches too. Some results
|
|
452
|
+
differ with `'off'` as well:
|
|
453
|
+
|
|
454
|
+
- No mutant is NoCoverage: one that no test reaches is run against every test, and is Survived.
|
|
455
|
+
- Stryker sets no hit limit, so a mutant that loops forever is stopped by its timeout instead of
|
|
456
|
+
after a number of hits. It is still Timeout, but each one takes the whole timeout to find.
|
|
457
|
+
|
|
458
|
+
**With `incremental`, use `--force` whenever you need fresh results.** With `'all'` or `'off'`
|
|
459
|
+
Stryker cannot see that a new or changed test now reaches a mutant, so it keeps the earlier result
|
|
460
|
+
of a mutant that was Survived or NoCoverage. With these values, run with `--force` (or set
|
|
461
|
+
`incremental: false`) each time you need results that reflect your current tests, not only once.
|
|
462
|
+
|
|
463
|
+
With `'all'`, Stryker may warn that static mutants take most of the time and suggest
|
|
464
|
+
`ignoreStatic`. With `'all'` every mutant that some test reaches is a [static mutant](#terms) to
|
|
465
|
+
Stryker, and Stryker itself rejects `ignoreStatic` with any value but `'perTest'`, so the
|
|
466
|
+
suggestion does not apply. Set `warnings: { slow: false }` in your Stryker config to silence it.
|
|
467
|
+
|
|
468
|
+
`'off'` is also the simplest dry run: one run of your tests, with no mutated file imported first and
|
|
469
|
+
no coverage recorded, so `bun.alwaysImport` and `bun.importDiscovery` have no effect with it. Use it
|
|
470
|
+
as the way out if per-test tracking ever gets a result wrong, or the dry run fails one of its
|
|
471
|
+
coverage checks and you cannot fix the cause; please also
|
|
472
|
+
[open an issue](https://github.com/hughescr/stryker-bun-runner/issues). Details:
|
|
473
|
+
[coverageAnalysis](docs/internals.md#coverageanalysis).
|
|
474
|
+
|
|
475
|
+
```javascript
|
|
476
|
+
export default {
|
|
477
|
+
appendPlugins: ['@hughescr/stryker-bun-runner'],
|
|
478
|
+
testRunner: 'bun',
|
|
479
|
+
coverageAnalysis: 'off', // every mutant runs every test
|
|
480
|
+
};
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
## Which mutated files the dry run imports
|
|
484
|
+
|
|
485
|
+
**In the normal case you need to do nothing.** Before the dry run's tests start, the runner imports
|
|
486
|
+
the mutated files that your tests load, so that their module-level code runs outside any test and
|
|
487
|
+
its mutants are [static mutants](#terms), the same on every run. It does not import a file that no
|
|
488
|
+
test loads, and a mutant there that no test reaches is NoCoverage. That way a file that fails when
|
|
489
|
+
it is imported on its own, such as an app's entry point, does not break the dry run.
|
|
490
|
+
|
|
491
|
+
To find the files, the runner reads the import statements of your test files and preloads
|
|
492
|
+
(`[test].preload` in your bunfig, and `--preload` in `bun.bunArgs`), with a short `bun` process
|
|
493
|
+
that runs none of your code. Then:
|
|
494
|
+
|
|
495
|
+
- If the tests import every mutated file, the runner imports all of them first and runs the tests
|
|
496
|
+
once, as earlier versions did.
|
|
497
|
+
- If some files are left out and nothing in your code could load them, the runner imports the rest
|
|
498
|
+
and runs the tests once, while it checks that the left-out files really do not load.
|
|
499
|
+
- If your code could load a left-out file in a way that the import statements do not show, the
|
|
500
|
+
runner first makes a [plain run](#terms) of the tests with nothing imported, notes which mutated
|
|
501
|
+
files load, and then makes the dry run proper with those files imported first
|
|
502
|
+
([details](#if-the-dry-run-runs-your-tests-twice)).
|
|
503
|
+
|
|
504
|
+
When some files are left out, an info line after the dry run says which ones, for example:
|
|
505
|
+
|
|
506
|
+
> `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.`
|
|
507
|
+
|
|
508
|
+
The two options that change what is imported are `bun.alwaysImport` and `bun.importDiscovery`
|
|
509
|
+
([options table](#configuration)). With Stryker's `incremental` set, every message below that
|
|
510
|
+
names `bun.alwaysImport` ends with:
|
|
511
|
+
`Results saved before the change are reused: run once with --force over the whole mutate scope, not only the files named here.`
|
|
512
|
+
How the runner decides, in full:
|
|
513
|
+
[Which mutated files are imported first](docs/internals.md#which-mutated-files-are-imported-first).
|
|
514
|
+
|
|
515
|
+
The rest of this section walks through the cases where you might need to act.
|
|
516
|
+
|
|
517
|
+
### If the dry run runs your tests twice
|
|
518
|
+
|
|
519
|
+
**The situation.** Your tests, or the code that they load, can reach a mutated file in a way that
|
|
520
|
+
the runner cannot read from the import statements, for example:
|
|
521
|
+
|
|
522
|
+
- an `import()` or `require()` whose path is computed rather than written as a string;
|
|
523
|
+
- `createRequire`, `eval`, `new Function`, or a loader such as `Bun.plugin`;
|
|
524
|
+
- an `import()` or `require()` of a mutated file in your source code rather than in a test file or
|
|
525
|
+
preload (lazy routes, say).
|
|
526
|
+
|
|
527
|
+
Some settings stop the runner from reading the imports at all: in your bunfig, a `[loader]`
|
|
528
|
+
section, any of `jsx`, `jsxImportSource`, `jsxFactory` and `jsxFragment`, a `define` whose value is
|
|
529
|
+
not a literal, or `[test].pathIgnorePatterns`; in `bun.bunArgs`, flags such as `--loader`,
|
|
530
|
+
`--define`, `--conditions` or `--tsconfig-override`. `bun.importDiscovery: 'run'` has the same
|
|
531
|
+
effect on purpose.
|
|
532
|
+
|
|
533
|
+
In each case, unless the tests' imports and `bun.alwaysImport` already cover every mutated file,
|
|
534
|
+
the runner makes a plain run of your tests first, with nothing imported, to see which mutated files
|
|
535
|
+
they load, and then the dry run proper, with those files imported first.
|
|
536
|
+
|
|
537
|
+
**The message.** When some files are left out, the info line says "before the tests of the second
|
|
538
|
+
run":
|
|
539
|
+
|
|
540
|
+
> `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.`
|
|
541
|
+
|
|
542
|
+
If what is left of Stryker's time budget for the dry run looks too short for the next run, a
|
|
543
|
+
warning says so:
|
|
544
|
+
|
|
545
|
+
> `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>.`
|
|
546
|
+
|
|
547
|
+
**What it means.** One more run of your suite, in the dry run only, so the dry run takes about
|
|
548
|
+
twice as long. Each run is limited by `bun.timeout`. Mutant runs are unchanged, and the extra run
|
|
549
|
+
does not make their timeouts longer.
|
|
550
|
+
|
|
551
|
+
**What to do.**
|
|
552
|
+
|
|
553
|
+
1. To see why, run `bunx stryker run --logLevel debug` and look for the line that starts
|
|
554
|
+
`Import scan: dynamic` (its `reasons:` name the file and what the runner could not read),
|
|
555
|
+
`The import scan was not started:` (it names the setting) or, at info,
|
|
556
|
+
`The import scan gave no usable answer:`.
|
|
557
|
+
2. If you can, change what the reason names: write the path as a string, or choose the test files
|
|
558
|
+
with `[test].root` or `bun.testFiles` instead of `[test].pathIgnorePatterns`.
|
|
559
|
+
3. Otherwise, the runner makes one run only when every mutated file is either imported by the tests
|
|
560
|
+
or listed in `bun.alwaysImport`. Listing only the file that the computed `import()` loads is not
|
|
561
|
+
enough while other files are still left out. If the files that the info line lists can be
|
|
562
|
+
imported safely before the tests, list them all:
|
|
563
|
+
|
|
564
|
+
```javascript
|
|
565
|
+
bun: {
|
|
566
|
+
alwaysImport: ['src/routes/**', 'src/jobs/**'],
|
|
567
|
+
},
|
|
568
|
+
```
|
|
569
|
+
|
|
570
|
+
Do not list a file that fails when it is imported outside its real environment, such as an
|
|
571
|
+
app's entry point. If no test is meant to cover such a file, you can leave it out of `mutate`
|
|
572
|
+
instead (with a `'!src/main.ts'` entry, say). When the runner cannot read the imports at all
|
|
573
|
+
(the bunfig and `bun.bunArgs` settings above), only a `bun.alwaysImport` that keeps every mutated
|
|
574
|
+
file, such as `'all'`, gives one run.
|
|
575
|
+
4. Or accept the extra run. If the dry run then times out, raise Stryker's `dryRunTimeoutMinutes`.
|
|
576
|
+
Both runs must run the same code, so if you use `--randomize`, also give a `--seed`.
|
|
577
|
+
|
|
578
|
+
### If a mutated file fails when it is imported before the tests
|
|
579
|
+
|
|
580
|
+
**The situation.** This is the problem that the change fixed for files that no test loads
|
|
581
|
+
([#3](https://github.com/hughescr/stryker-bun-runner/issues/3)). It can still happen for a file
|
|
582
|
+
that a test does load, or that you list in `bun.alwaysImport`, when the file needs something that a
|
|
583
|
+
test sets up first: a DOM, a global, an environment variable.
|
|
584
|
+
|
|
585
|
+
**The message.** A warning for each import that threw:
|
|
586
|
+
|
|
587
|
+
> `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.`
|
|
588
|
+
|
|
589
|
+
The tests that load the file then usually fail, and Stryker lists them. When the dry run made a
|
|
590
|
+
plain run first, and that passed, an error names the files that it imported:
|
|
591
|
+
|
|
592
|
+
> `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.`
|
|
593
|
+
|
|
594
|
+
(The `Imports that threw:` sentence appears only when an import threw. If some of the files were
|
|
595
|
+
imported only because `bun.alwaysImport` lists them, the message counts those separately.)
|
|
596
|
+
|
|
597
|
+
If the file fails a little later instead (an error from a timer, or a promise that rejects), the
|
|
598
|
+
dry run fails its [completeness check](#the-dry-run-fails), and the message may name your file from
|
|
599
|
+
a stack frame in one of bun's `Unhandled error between tests` blocks. A named file alone does not
|
|
600
|
+
prove that it caused the error.
|
|
601
|
+
|
|
602
|
+
**What it means.** Importing that file before any test ran broke it, or broke the tests that use
|
|
603
|
+
it.
|
|
604
|
+
|
|
605
|
+
**What to do.**
|
|
606
|
+
|
|
607
|
+
1. If no test loads the file and it is in `bun.alwaysImport`, take it out of `bun.alwaysImport`.
|
|
608
|
+
2. If the file needs a setup that your tests do, move that setup into a preload. Code at the top
|
|
609
|
+
level of a `[test].preload` file runs before the runner imports anything:
|
|
610
|
+
|
|
611
|
+
```toml
|
|
612
|
+
# bunfig.toml
|
|
613
|
+
[test]
|
|
614
|
+
preload = ["./tests/setup-dom.ts"]
|
|
615
|
+
```
|
|
616
|
+
|
|
617
|
+
3. Otherwise, make the file importable on its own (move its side effects into a function that the
|
|
618
|
+
app calls), or leave it out of `mutate`.
|
|
619
|
+
|
|
620
|
+
A related case fixes itself. When a test file names a file in an `import()` or `require()` that
|
|
621
|
+
never runs (a dead branch, a skipped test), the runner imports that file first too. If the dry run
|
|
622
|
+
then fails, the runner makes a plain run, and if that passes, it leaves out the files that the plain
|
|
623
|
+
run did not load and tries again. It warns:
|
|
624
|
+
|
|
625
|
+
> `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'.`
|
|
626
|
+
|
|
627
|
+
### If the first, plain run of the tests fails
|
|
628
|
+
|
|
629
|
+
**The situation.** The dry run made a [plain run](#terms) of your tests first, and it failed. A
|
|
630
|
+
test that passed only because earlier versions imported every mutated file before the tests fails
|
|
631
|
+
here, because nothing is imported first.
|
|
632
|
+
|
|
633
|
+
**The message.** An error, followed by bun's own output:
|
|
634
|
+
|
|
635
|
+
> `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.`
|
|
636
|
+
|
|
637
|
+
(After a discarded run it says `the second run` and `The third run was not made.`)
|
|
638
|
+
|
|
639
|
+
**What it means.** The plain run failed a test, raised an error outside any test, exited without
|
|
640
|
+
bun's summary (a test called `process.exit`), was killed (by `bun.timeout` or `bun.maxChildRss`),
|
|
641
|
+
or left no record that it finished. The reasons say which.
|
|
642
|
+
|
|
643
|
+
**What to do.**
|
|
644
|
+
|
|
645
|
+
1. Run `bun test --max-concurrency=1`, which runs the tests one at a time with nothing imported
|
|
646
|
+
first, as the plain run does, and fix what fails.
|
|
647
|
+
2. If a test depends on a mutated file that it never imports (it relies on that file's side
|
|
648
|
+
effects), import the file in the test or in a preload. The runner then sees it in the import
|
|
649
|
+
statements.
|
|
650
|
+
3. Or avoid the plain run with `bun.alwaysImport: 'all'`
|
|
651
|
+
([the earlier behaviour](#if-you-want-the-earlier-behaviour)).
|
|
652
|
+
|
|
653
|
+
### If a test loads a mutated file late
|
|
654
|
+
|
|
655
|
+
**The situation.** A test loads a mutated file inside a test or a hook rather than through the
|
|
656
|
+
imports at the top of a test file. That is fine when the runner can read the load: a literal
|
|
657
|
+
`import('../src/x')` in a test file, or one that leads to a plain run first
|
|
658
|
+
([above](#if-the-dry-run-runs-your-tests-twice)). It needs help when the load goes through code
|
|
659
|
+
that the runner does not read, such as a package (a mocking helper given a path, a framework that
|
|
660
|
+
loads files from a directory).
|
|
661
|
+
|
|
662
|
+
**The message.** If the runner ran the tests once and saw the file load, it warns, throws that run
|
|
663
|
+
away and starts again:
|
|
664
|
+
|
|
665
|
+
> `<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'.`
|
|
666
|
+
|
|
667
|
+
If the plain run did not load the file but the dry run proper did, after the runner's imports, the
|
|
668
|
+
dry run stops:
|
|
669
|
+
|
|
670
|
+
> `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.`
|
|
671
|
+
|
|
672
|
+
`<where>` is `inside test "<test>"`, `after the imports, outside a test`, or `after the imports`.
|
|
673
|
+
After a discarded run, the message says `third` and `second` instead of `second` and `first`.
|
|
674
|
+
|
|
675
|
+
**What it means.** The first message costs time but nothing else: the runner recovers, with three
|
|
676
|
+
runs of your tests instead of one. The second means that the two runs did not run the same code:
|
|
677
|
+
importing the other files first changed what the tests do, or the tests run in a random order
|
|
678
|
+
without a seed. Its coverage would be credited to whichever test happened to load the file, so the
|
|
679
|
+
runner stops rather than report that.
|
|
680
|
+
|
|
681
|
+
**What to do.**
|
|
682
|
+
|
|
683
|
+
1. Add the file to `bun.alwaysImport`, so that it is imported before the tests:
|
|
684
|
+
|
|
685
|
+
```javascript
|
|
686
|
+
bun: {
|
|
687
|
+
alwaysImport: ['src/plugins/payments.ts'],
|
|
688
|
+
},
|
|
689
|
+
```
|
|
690
|
+
|
|
691
|
+
For the first message you can instead set `bun.importDiscovery: 'run'`, which gives two runs
|
|
692
|
+
instead of three.
|
|
693
|
+
2. If you use `--randomize`, also give a `--seed`.
|
|
694
|
+
3. With `incremental`, run once with `bunx stryker run --force`.
|
|
695
|
+
|
|
696
|
+
### If a mutant run stops the campaign
|
|
697
|
+
|
|
698
|
+
**The situation.** In a mutant run, a test loaded a mutated file that the dry run neither imported
|
|
699
|
+
nor saw load. A package may have loaded it, while in the dry run it did not, because importing the
|
|
700
|
+
other files first changed what the tests did. Or a test replaced the file with `mock.module()`,
|
|
701
|
+
which looks the same in bun's module cache ([see below](#if-a-test-replaces-a-mutated-file-with-mockmodule)).
|
|
702
|
+
Either way, the mutants in that file may have been planned without all of their covering tests, so
|
|
703
|
+
the runner stops the whole Stryker run rather than report results that may be wrong.
|
|
704
|
+
|
|
705
|
+
**The message.** An error, and then Stryker stops with
|
|
706
|
+
`Unexpected error occurred while running Stryker` and exit code 1:
|
|
707
|
+
|
|
708
|
+
> `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.`
|
|
709
|
+
|
|
710
|
+
With `incremental` set, `and run again` is followed by
|
|
711
|
+
`with --force over the whole mutate scope, not only the files named here`.
|
|
712
|
+
|
|
713
|
+
**What it means.** The Stryker run has stopped, with no final report and no incremental file.
|
|
714
|
+
Results that reporters already received for earlier mutants, and files from earlier runs, are as
|
|
715
|
+
they were.
|
|
716
|
+
|
|
717
|
+
**What to do.**
|
|
718
|
+
|
|
719
|
+
1. Add the file to `bun.alwaysImport`, so that the dry run imports it before the tests:
|
|
720
|
+
|
|
721
|
+
```javascript
|
|
722
|
+
bun: {
|
|
723
|
+
alwaysImport: ['src/plugins/payments.ts'],
|
|
724
|
+
},
|
|
725
|
+
```
|
|
726
|
+
|
|
727
|
+
Or set `bun.importDiscovery: 'run'`, so that the dry run always makes a plain run first and sees
|
|
728
|
+
what the tests load, at the cost of a second run of your suite.
|
|
729
|
+
2. With `incremental`, run once with `bunx stryker run --force`: Stryker would otherwise reuse saved
|
|
730
|
+
results for mutants that only run while the file loads.
|
|
731
|
+
3. If a test replaces the file with `mock.module()`, read the next case too.
|
|
732
|
+
|
|
733
|
+
If an error `Could not write the abort marker in <dir> (<error>)` follows the message, the runner
|
|
734
|
+
could not save the note that stops the rest of the Stryker run, so the run may go on: treat its
|
|
735
|
+
results as incomplete.
|
|
736
|
+
|
|
737
|
+
### If a test replaces a mutated file with `mock.module()`
|
|
738
|
+
|
|
739
|
+
**The situation and what it means.** There are two cases.
|
|
740
|
+
|
|
741
|
+
- **The dry run imports the file before the tests**, because the tests load it (the test file
|
|
742
|
+
itself, another test, or the code under test imports it). A `mock.module()` of it at the top of a
|
|
743
|
+
test file or in `beforeAll` then has no effect on code that has already imported it: the test
|
|
744
|
+
sees the real module, and can fail in the dry run. No message says so.
|
|
745
|
+
- **The dry run does not import the file, and some tests mock it.** Bun's module cache shows a
|
|
746
|
+
mocked file as if it were loaded, so a mutant run of one of those tests can stop the Stryker run
|
|
747
|
+
with the message in [the previous case](#if-a-mutant-run-stops-the-campaign).
|
|
748
|
+
|
|
749
|
+
**What to do.**
|
|
750
|
+
|
|
751
|
+
1. Instead of replacing a mutated file with `mock.module()`, pass the dependency in (dependency
|
|
752
|
+
injection), wrap it in a small module of the test's own, or use `spyOn()` on its methods.
|
|
753
|
+
`mock.module()` of modules outside `mutate` (`node:fs`, packages, files that you do not mutate)
|
|
754
|
+
is not affected.
|
|
755
|
+
2. If a mutant run stopped, follow [the previous case](#if-a-mutant-run-stops-the-campaign). Once
|
|
756
|
+
the file is imported before the tests, the first case above applies to it.
|
|
757
|
+
|
|
758
|
+
### If a test runs a mutated file in a worker or a child process
|
|
759
|
+
|
|
760
|
+
**The situation.** A test runs a mutated file only inside a `Worker` or a child process. The runner
|
|
761
|
+
sees only what loads in the test process, so it does not import that file before the tests.
|
|
762
|
+
|
|
763
|
+
**The message.** None. The file's mutants that no test reaches in the test process are NoCoverage.
|
|
764
|
+
|
|
765
|
+
**What to do.** Add the file to `bun.alwaysImport`, which imports it before the tests as earlier
|
|
766
|
+
versions did:
|
|
767
|
+
|
|
768
|
+
```javascript
|
|
769
|
+
bun: {
|
|
770
|
+
alwaysImport: ['src/workers/resize.ts'],
|
|
771
|
+
},
|
|
772
|
+
```
|
|
773
|
+
|
|
774
|
+
### If one of your preloads loads a mutated file at the very end
|
|
775
|
+
|
|
776
|
+
**The situation.** One of your own preloads has an `afterAll` hook that loads a mutated file for
|
|
777
|
+
the first time, and bun runs that hook after the runner's own last `afterAll`. Nothing of the
|
|
778
|
+
runner runs after its own hook, so it never sees the load. Mutant runs do not see it either: they
|
|
779
|
+
check for missed files only at the moment that a mutant first runs, which is normally earlier.
|
|
780
|
+
|
|
781
|
+
**The message.** None. The file is not imported before the tests, and its mutants are NoCoverage.
|
|
782
|
+
|
|
783
|
+
**What to do.** Add the file to `bun.alwaysImport`:
|
|
784
|
+
|
|
785
|
+
```javascript
|
|
786
|
+
bun: {
|
|
787
|
+
alwaysImport: ['src/report-writer.ts'],
|
|
788
|
+
},
|
|
789
|
+
```
|
|
790
|
+
|
|
791
|
+
### If you want the earlier behaviour
|
|
792
|
+
|
|
793
|
+
**The situation.** You want every file that `mutate` matches imported before the tests, as earlier
|
|
794
|
+
versions did, whether or not a test loads it.
|
|
795
|
+
|
|
796
|
+
**What to do.**
|
|
797
|
+
|
|
798
|
+
1. Set `bun.alwaysImport` to `'all'`:
|
|
799
|
+
|
|
800
|
+
```javascript
|
|
801
|
+
export default {
|
|
802
|
+
appendPlugins: ['@hughescr/stryker-bun-runner'],
|
|
803
|
+
testRunner: 'bun',
|
|
804
|
+
bun: { alwaysImport: 'all' },
|
|
805
|
+
};
|
|
806
|
+
```
|
|
807
|
+
|
|
808
|
+
2. With `incremental`, run once with `bunx stryker run --force`.
|
|
809
|
+
|
|
810
|
+
The runner then reads no import statements and runs your tests once. A file that fails when it is
|
|
811
|
+
imported outside its real environment, such as an app's entry point, can break the dry run again.
|
|
812
|
+
|
|
372
813
|
## How it works
|
|
373
814
|
|
|
374
815
|
1. **Startup.** Each Stryker worker checks Bun's version, validates `bun.bunArgs`, writes its
|
|
375
816
|
coverage preload and sanitized bunfig to a private temporary directory, and finds the test files.
|
|
376
817
|
2. **Dry run.** One `bun test` run of the whole suite, one test at a time (`--max-concurrency=1`,
|
|
377
818
|
with `test.concurrent` tests run in turn too), so every mutant reached can be credited to the
|
|
378
|
-
test that reached it.
|
|
819
|
+
test that reached it. Before the tests, the preload imports the mutated files the tests load
|
|
820
|
+
([which ones](#which-mutated-files-the-dry-run-imports); establishing that can take a plain run of
|
|
821
|
+
the tests first). The runner follows each test through Bun's inspector while the preload
|
|
379
822
|
records which mutants each test reached, and how often. Bun's summary, the inspector's events and
|
|
380
823
|
the coverage records must agree exactly, or the dry run fails
|
|
381
824
|
([the completeness gate](docs/internals.md#the-completeness-gate)).
|
|
@@ -596,14 +1039,23 @@ Every log message: [Log output](docs/internals.md#log-output).
|
|
|
596
1039
|
| Message | Cause | Fix |
|
|
597
1040
|
|---|---|---|
|
|
598
1041
|
| 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
|
-
| `
|
|
600
|
-
| `
|
|
1042
|
+
| `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). |
|
|
1043
|
+
| `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. |
|
|
1044
|
+
| `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
1045
|
| `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
1046
|
| `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
1047
|
| `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
1048
|
| `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). |
|
|
606
|
-
| `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'
|
|
1049
|
+
| `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). |
|
|
1050
|
+
| `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'` or `'all'`. | Fix the cause the message names, or set `coverageAnalysis` to `'off'` to run without coverage. |
|
|
1051
|
+
| `stryker-bun-runner: the dry run's record of which test file ran each test, <file>, was missing, unreadable or empty` (a warning, with `coverageAnalysis: 'off'`) | The same causes as the row above. Each test is then named after the file bun reports for it, so a test that a shared helper file defines is credited to that file. | Fix the cause the message names. |
|
|
1052
|
+
| `stryker-bun-runner: cannot write <file> (<error>), so <registry> still holds an earlier dry run's test names, ...` | The dry run could not replace the file that hands its test names to the other workers, and an earlier run's copy is still there. | Check the temporary directory (space, permissions; see [Temporary files](docs/internals.md#temporary-files)), or remove the file it names, and re-run. |
|
|
1053
|
+
| `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). |
|
|
1054
|
+
| `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). |
|
|
1055
|
+
| `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`. |
|
|
1056
|
+
| `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. |
|
|
1057
|
+
| `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. |
|
|
1058
|
+
| `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
1059
|
| `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
1060
|
|
|
609
1061
|
### Warnings during the dry run
|
|
@@ -611,7 +1063,7 @@ Every log message: [Log output](docs/internals.md#log-output).
|
|
|
611
1063
|
| Message | Cause | Fix |
|
|
612
1064
|
|---|---|---|
|
|
613
1065
|
| `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
|
|
1066
|
+
| `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
1067
|
| `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
1068
|
| `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
1069
|
| `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 +1073,17 @@ Every log message: [Log output](docs/internals.md#log-output).
|
|
|
621
1073
|
| `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
1074
|
| `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
1075
|
| `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. |
|
|
1076
|
+
| `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). |
|
|
1077
|
+
| `<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). |
|
|
1078
|
+
| `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). |
|
|
1079
|
+
| `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. |
|
|
1080
|
+
| `<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. |
|
|
1081
|
+
| `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). |
|
|
1082
|
+
| `<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. |
|
|
1083
|
+
| `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. |
|
|
1084
|
+
| `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). |
|
|
1085
|
+
| `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. |
|
|
1086
|
+
| `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
1087
|
|
|
625
1088
|
Inspector diagnostics such as `Inspector data looks abnormal` need no action unless the dry run
|
|
626
1089
|
also fails; see [Inspector diagnostics](docs/internals.md#inspector-diagnostics).
|
|
@@ -635,20 +1098,43 @@ also fails; see [Inspector diagnostics](docs/internals.md#inspector-diagnostics)
|
|
|
635
1098
|
| `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
1099
|
| `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
1100
|
| `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. |
|
|
1101
|
+
| `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
1102
|
| `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
1103
|
| `bun test child exceeded maxChildRss` | A run went over `bun.maxChildRss`; scored Timeout. | Expected for runaway mutants; raise the limit if many hit it. |
|
|
1104
|
+
| `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). |
|
|
1105
|
+
| `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. |
|
|
1106
|
+
| `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
1107
|
| 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
|
-
| Every mutant runs the whole suite | No per-test coverage: `coverageAnalysis` is
|
|
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. |
|
|
1108
|
+
| Every mutant runs the whole suite | No per-test coverage: `coverageAnalysis` is `'all'` or `'off'` ([coverageAnalysis](#coverageanalysis)). | Use `'perTest'`. |
|
|
1109
|
+
| 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
1110
|
|
|
645
1111
|
## Limitations
|
|
646
1112
|
|
|
647
1113
|
- **One test at a time.** Tests run sequentially, `test.concurrent` included, so per-test coverage
|
|
648
1114
|
is exact. Mutation runs are slower than a parallel `bun test`.
|
|
649
|
-
- **`mock.module()` of a mutated file** has no effect
|
|
650
|
-
the dry run imports
|
|
651
|
-
|
|
1115
|
+
- **`mock.module()` of a mutated file** that the tests load has no effect in the dry run, because
|
|
1116
|
+
the dry run imports that file before the tests run. Use dependency injection or spy on methods
|
|
1117
|
+
instead ([details](#if-a-test-replaces-a-mutated-file-with-mockmodule)).
|
|
1118
|
+
- **Files that load where the runner cannot see them** are not imported before the tests, and a
|
|
1119
|
+
mutant there that no test reaches is NoCoverage. In each case, list the file in
|
|
1120
|
+
`bun.alwaysImport`:
|
|
1121
|
+
- a file that runs only in a worker or a child process;
|
|
1122
|
+
- a file that only a package loads, and only when the other files are not imported first
|
|
1123
|
+
(importing them first can change what the tests do). `bun.importDiscovery: 'run'` also helps
|
|
1124
|
+
here. If a mutant run later sees such a file loaded, it stops the Stryker run and names the file
|
|
1125
|
+
([what to do](#if-a-mutant-run-stops-the-campaign)); otherwise nothing says so;
|
|
1126
|
+
- a file that `mutate` matches but in which Stryker made no mutants, when it is unloaded again,
|
|
1127
|
+
or still loading, at the end of the dry run;
|
|
1128
|
+
- a file that one of your preloads first loads in an `afterAll` hook that bun runs after the
|
|
1129
|
+
runner's own last one ([details](#if-one-of-your-preloads-loads-a-mutated-file-at-the-very-end)).
|
|
1130
|
+
Nothing warns about this one.
|
|
1131
|
+
- **Mutants credited to a different test.** Where a file's module-level code depends on a file that
|
|
1132
|
+
no test loads, its mutants can be credited to a different test than when every file was imported
|
|
1133
|
+
first. Listing the file that the code depends on in `bun.alwaysImport` restores the earlier
|
|
1134
|
+
result.
|
|
1135
|
+
- **Some mutant runs cannot check for missed files.** When one of your preloads has already run a
|
|
1136
|
+
mutant's code before the tests start, that mutant's run does not check for files that the dry run
|
|
1137
|
+
missed, because it cannot tell a load that the mutant caused from one that the tests made.
|
|
652
1138
|
- **Cross-file order dependence.** Mutant runs order files by cost, not as in the dry run, so a
|
|
653
1139
|
global change one test file leaves behind (an unrestored `mock.module()`) can change results.
|
|
654
1140
|
- **No randomized order in mutant runs**, and `retry`/`rerunEach` are not supported.
|
|
@@ -665,8 +1151,9 @@ also fails; see [Inspector diagnostics](docs/internals.md#inspector-diagnostics)
|
|
|
665
1151
|
- [Mutant runs](docs/internals.md#mutant-runs): test selection, test-file ordering, fallbacks
|
|
666
1152
|
- [How results are scored](docs/internals.md#how-results-are-scored) and
|
|
667
1153
|
[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):
|
|
669
|
-
the completeness gate, coverage checks
|
|
1154
|
+
- [The dry run in detail](docs/internals.md#the-dry-run-in-detail): which mutated files are imported
|
|
1155
|
+
first, the start and drain handshakes, the completeness gate, coverage checks; and
|
|
1156
|
+
[how mutant runs check for files that the dry run missed](docs/internals.md#the-witness-in-mutant-runs)
|
|
670
1157
|
- [Log output](docs/internals.md#log-output): start and end summaries, repeated warnings
|
|
671
1158
|
- [Temporary files](docs/internals.md#temporary-files): the private per-run directory, removed when
|
|
672
1159
|
the run ends
|