@hughescr/stryker-bun-runner 1.3.0 → 1.3.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 +4 -3
- package/dist/index.d.ts +8 -2
- package/dist/index.js +29 -44
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -65,8 +65,9 @@ The plugin uses Bun's Inspector Protocol (WebSocket) to:
|
|
|
65
65
|
2. **Track execution** - Listens for TestReporter events to correlate test runs with coverage
|
|
66
66
|
3. **Sequential execution** - Uses `--concurrency=1` to ensure reliable coverage correlation
|
|
67
67
|
4. **Build hierarchy** - Reconstructs test names from describe blocks for accurate reporting
|
|
68
|
+
5. **Targeted mutant runs** - Runs only the tests that covered each mutant (via `--test-name-pattern`); bails after the first failure unless Stryker's `disableBail` option is set (dry runs never bail, since the full suite must run for coverage). Any bail flag in `bun.bunArgs` is ignored — bail is decided solely by the runner.
|
|
68
69
|
|
|
69
|
-
This approach provides reliable test-to-mutant correlation, even with multiple test files.
|
|
70
|
+
Oversized covering-test patterns (over 100,000 UTF-8 bytes) fall back to running the full suite, to stay within OS argument-length limits. This approach provides reliable test-to-mutant correlation, even with multiple test files.
|
|
70
71
|
|
|
71
72
|
## Options
|
|
72
73
|
|
|
@@ -76,7 +77,7 @@ This approach provides reliable test-to-mutant correlation, even with multiple t
|
|
|
76
77
|
| `bun.timeout` | `number` | `10000` | Timeout per test in milliseconds |
|
|
77
78
|
| `bun.inspectorTimeout` | `number` | `5000` | Timeout for Inspector WebSocket connection in milliseconds |
|
|
78
79
|
| `bun.env` | `object` | `undefined` | Additional environment variables to pass to bun test |
|
|
79
|
-
| `bun.bunArgs` | `string[]` | `undefined` | Additional bun test flags (e.g., `['--
|
|
80
|
+
| `bun.bunArgs` | `string[]` | `undefined` | Additional bun test flags (e.g., `['--only']`). Bail flags (`--bail`, `--bail=<N>`, or a space-separated `--bail <N>`) are ignored here — bail is fully managed by the runner via Stryker's `disableBail` option (see [How It Works](#how-it-works)). |
|
|
80
81
|
| `bun.testFiles` | `string[]` | `undefined` | Explicit list of test file paths (absolute or relative to cwd). When provided, skips auto-discovery and uses this list verbatim. Relative paths resolve against the bun subprocess's cwd. Useful for restricting mutation testing to a subset of test files. |
|
|
81
82
|
| `bun.smol` | `boolean` | `false` | Pass Bun's `--smol` flag to every child: a smaller JavaScriptCore heap at some cost to speed. Recommended on memory-constrained machines — see [Memory model](#memory-model). |
|
|
82
83
|
| `bun.maxChildRss` | `number` | `undefined` | Soft memory ceiling in bytes for each child's RSS. A child that exceeds it is killed and the run reported as a clean timeout for that mutant. See [Memory containment](#memory-containment). |
|
|
@@ -90,7 +91,7 @@ bun: {
|
|
|
90
91
|
timeout: 30000, // 30 second test timeout
|
|
91
92
|
inspectorTimeout: 10000, // 10 second connection timeout
|
|
92
93
|
env: { DEBUG: 'true' }, // Extra environment variables
|
|
93
|
-
bunArgs: ['--
|
|
94
|
+
bunArgs: ['--only'], // Extra bun test flags (bail flags here are ignored — see Options table)
|
|
94
95
|
smol: true, // Smaller JSC heap, some speed cost — see Memory model
|
|
95
96
|
maxChildRss: 1_500_000_000, // Kill+report-timeout a child using more than ~1.5GB RSS
|
|
96
97
|
rssCheckIntervalMs: 1000, // How often to poll RSS when maxChildRss is set
|
package/dist/index.d.ts
CHANGED
|
@@ -196,8 +196,14 @@ export interface BunTestRunnerOptions {
|
|
|
196
196
|
*/
|
|
197
197
|
env?: Record<string, string>;
|
|
198
198
|
/**
|
|
199
|
-
* Additional bun test flags to pass
|
|
200
|
-
*
|
|
199
|
+
* Additional bun test flags to pass.
|
|
200
|
+
*
|
|
201
|
+
* Bail flags (`--bail`, `--bail=<N>`, or a space-separated `--bail <N>`) are
|
|
202
|
+
* stripped if present — bail is fully managed by the runner based on
|
|
203
|
+
* Stryker's `disableBail` option, so a bail flag configured here would
|
|
204
|
+
* otherwise silently override that decision.
|
|
205
|
+
*
|
|
206
|
+
* @example ['--only', '--verbose']
|
|
201
207
|
*/
|
|
202
208
|
bunArgs?: string[];
|
|
203
209
|
/**
|
package/dist/index.js
CHANGED
|
@@ -5618,30 +5618,12 @@ function mapCoverageToInspectorIds(rawCoverage, executionOrder, testHierarchy, l
|
|
|
5618
5618
|
}
|
|
5619
5619
|
return { coverage: rawCoverage, inspectorIdToProjectFile: new Map };
|
|
5620
5620
|
}
|
|
5621
|
-
function
|
|
5622
|
-
const appearances = new Map;
|
|
5623
|
-
for (const [, counts] of perTestEntries) {
|
|
5624
|
-
for (const mutantId of Object.keys(counts)) {
|
|
5625
|
-
appearances.set(mutantId, (appearances.get(mutantId) ?? 0) + 1);
|
|
5626
|
-
}
|
|
5627
|
-
}
|
|
5628
|
-
return appearances;
|
|
5629
|
-
}
|
|
5630
|
-
function buildPromoteToStaticSet(existingStaticKeys, perTestAppearances) {
|
|
5631
|
-
const promoteToStatic = new Set(existingStaticKeys);
|
|
5632
|
-
for (const [mutantId, count] of perTestAppearances) {
|
|
5633
|
-
if (count > 1) {
|
|
5634
|
-
promoteToStatic.add(mutantId);
|
|
5635
|
-
}
|
|
5636
|
-
}
|
|
5637
|
-
return promoteToStatic;
|
|
5638
|
-
}
|
|
5639
|
-
function buildFilteredPerTest(perTestEntries, promoteToStatic) {
|
|
5621
|
+
function buildFilteredPerTest(perTestEntries, staticIds) {
|
|
5640
5622
|
const newPerTest = {};
|
|
5641
5623
|
for (const [testId, counts] of perTestEntries) {
|
|
5642
5624
|
const filteredCounts = {};
|
|
5643
5625
|
for (const [mutantId, hitCount] of Object.entries(counts)) {
|
|
5644
|
-
if (!
|
|
5626
|
+
if (!staticIds.has(mutantId)) {
|
|
5645
5627
|
filteredCounts[mutantId] = hitCount;
|
|
5646
5628
|
}
|
|
5647
5629
|
}
|
|
@@ -5652,27 +5634,11 @@ function buildFilteredPerTest(perTestEntries, promoteToStatic) {
|
|
|
5652
5634
|
return newPerTest;
|
|
5653
5635
|
}
|
|
5654
5636
|
function stabilizeCoverage(coverage) {
|
|
5655
|
-
const
|
|
5656
|
-
|
|
5657
|
-
|
|
5658
|
-
|
|
5659
|
-
|
|
5660
|
-
const perTestAppearances = countPerTestAppearances(perTestEntries);
|
|
5661
|
-
const promoteToStatic = buildPromoteToStaticSet(existingStaticKeys, perTestAppearances);
|
|
5662
|
-
const existingStatic = new Set(existingStaticKeys);
|
|
5663
|
-
const hasNewPromotions = [...promoteToStatic].some((id) => !existingStatic.has(id));
|
|
5664
|
-
const hasPerTestContamination = perTestEntries.some(([, counts]) => Object.keys(counts).some((id) => promoteToStatic.has(id)));
|
|
5665
|
-
if (!hasNewPromotions && !hasPerTestContamination) {
|
|
5666
|
-
return coverage;
|
|
5667
|
-
}
|
|
5668
|
-
const newStatic = { ...coverage.static };
|
|
5669
|
-
for (const mutantId of promoteToStatic) {
|
|
5670
|
-
if (!(mutantId in newStatic)) {
|
|
5671
|
-
newStatic[mutantId] = 1;
|
|
5672
|
-
}
|
|
5673
|
-
}
|
|
5674
|
-
const newPerTest = buildFilteredPerTest(perTestEntries, promoteToStatic);
|
|
5675
|
-
return { static: newStatic, perTest: newPerTest };
|
|
5637
|
+
const staticIds = new Set(Object.keys(coverage.static));
|
|
5638
|
+
return {
|
|
5639
|
+
static: coverage.static,
|
|
5640
|
+
perTest: buildFilteredPerTest(Object.entries(coverage.perTest), staticIds)
|
|
5641
|
+
};
|
|
5676
5642
|
}
|
|
5677
5643
|
function pairKeysWithInspectorIds(globallyOrderedPerTestKeys, executionOrder, testHierarchy, logger) {
|
|
5678
5644
|
const nonSkipped = executionOrder.filter((id) => {
|
|
@@ -6309,6 +6275,20 @@ async function getPsRss(pid) {
|
|
|
6309
6275
|
|
|
6310
6276
|
// src/process-runner.ts
|
|
6311
6277
|
var KILL_GRACE_PERIOD_MS = 500;
|
|
6278
|
+
function stripBailArgs(bunArgs) {
|
|
6279
|
+
const sanitized = [];
|
|
6280
|
+
for (let i = 0;i < bunArgs.length; i++) {
|
|
6281
|
+
const arg = bunArgs[i];
|
|
6282
|
+
if (arg === "--bail" || arg.startsWith("--bail=")) {
|
|
6283
|
+
if (arg === "--bail" && /^\d+$/.test(bunArgs[i + 1])) {
|
|
6284
|
+
i += 1;
|
|
6285
|
+
}
|
|
6286
|
+
continue;
|
|
6287
|
+
}
|
|
6288
|
+
sanitized.push(arg);
|
|
6289
|
+
}
|
|
6290
|
+
return sanitized;
|
|
6291
|
+
}
|
|
6312
6292
|
function killWithEscalation(childProcess, isClosed, gracePeriodMs) {
|
|
6313
6293
|
childProcess.kill("SIGTERM");
|
|
6314
6294
|
setTimeout(() => {
|
|
@@ -6341,7 +6321,7 @@ async function runBunTests(options) {
|
|
|
6341
6321
|
args.push("--smol");
|
|
6342
6322
|
}
|
|
6343
6323
|
if (options.bunArgs && options.bunArgs.length > 0) {
|
|
6344
|
-
args.push(...options.bunArgs);
|
|
6324
|
+
args.push(...stripBailArgs(options.bunArgs));
|
|
6345
6325
|
}
|
|
6346
6326
|
if (options.testFiles && options.testFiles.length > 0) {
|
|
6347
6327
|
args.push(...options.testFiles);
|
|
@@ -7751,6 +7731,7 @@ async function cleanupSanitizedBunfig(filePath) {
|
|
|
7751
7731
|
}
|
|
7752
7732
|
}
|
|
7753
7733
|
// src/utils/test-name-pattern.ts
|
|
7734
|
+
var MAX_TEST_NAME_PATTERN_LENGTH = 1e5;
|
|
7754
7735
|
function buildTestNamePattern(testFilter) {
|
|
7755
7736
|
if (testFilter.length === 0) {
|
|
7756
7737
|
return;
|
|
@@ -7772,7 +7753,11 @@ function buildTestNamePattern(testFilter) {
|
|
|
7772
7753
|
if (alternatives.size === 0) {
|
|
7773
7754
|
return;
|
|
7774
7755
|
}
|
|
7775
|
-
|
|
7756
|
+
const pattern = `^(?:${[...alternatives].join("|")})$`;
|
|
7757
|
+
if (Buffer.byteLength(pattern) > MAX_TEST_NAME_PATTERN_LENGTH) {
|
|
7758
|
+
return;
|
|
7759
|
+
}
|
|
7760
|
+
return pattern;
|
|
7776
7761
|
}
|
|
7777
7762
|
// src/utils/test-file-discovery.ts
|
|
7778
7763
|
import * as fsPromises from "node:fs/promises";
|
|
@@ -8344,7 +8329,7 @@ exit=%s timedOut=%s
|
|
|
8344
8329
|
bunArgs: this.bunArgs,
|
|
8345
8330
|
bunfigPath,
|
|
8346
8331
|
activeMutant: options.activeMutant.id,
|
|
8347
|
-
bail:
|
|
8332
|
+
bail: !options.disableBail,
|
|
8348
8333
|
sequentialMode: true,
|
|
8349
8334
|
preloadScript: this.preloadScriptPath,
|
|
8350
8335
|
testNamePattern,
|