@hughescr/stryker-bun-runner 1.5.2 → 1.6.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 +50 -13
- package/dist/index.d.ts +137 -20
- package/dist/index.js +1051 -142
- package/dist/templates/coverage-preload.js +483 -0
- package/package.json +4 -2
- package/dist/coverage/preload-logic.js +0 -255
- package/dist/templates/coverage-preload.ts +0 -440
|
@@ -0,0 +1,483 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/templates/coverage-preload.ts
|
|
3
|
+
import { beforeEach, afterEach, afterAll, describe, test, it } from "bun:test";
|
|
4
|
+
|
|
5
|
+
// src/coverage/preload-logic.ts
|
|
6
|
+
import { appendFileSync, closeSync, constants, openSync, writeSync } from "fs";
|
|
7
|
+
var preloadFs = { appendFileSync, closeSync, openSync, writeSync };
|
|
8
|
+
var HIT_LIMIT_TOKEN_ENV = "__STRYKER_HIT_LIMIT_TOKEN__";
|
|
9
|
+
var SYNC_TOKEN_ENV = "__STRYKER_SYNC_TOKEN__";
|
|
10
|
+
function getPreloadConfig() {
|
|
11
|
+
return {
|
|
12
|
+
syncPort: process.env.__STRYKER_SYNC_PORT__,
|
|
13
|
+
syncToken: process.env[SYNC_TOKEN_ENV],
|
|
14
|
+
coverageFile: process.env.__STRYKER_COVERAGE_FILE__,
|
|
15
|
+
activeMutant: process.env.__STRYKER_ACTIVE_MUTANT__,
|
|
16
|
+
hitLimit: parseHitLimit(process.env.__STRYKER_HIT_LIMIT__),
|
|
17
|
+
hitLimitToken: process.env[HIT_LIMIT_TOKEN_ENV]
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function parseHitLimit(raw) {
|
|
21
|
+
const limit = Number(raw);
|
|
22
|
+
return Number.isInteger(limit) && limit > 0 ? limit : undefined;
|
|
23
|
+
}
|
|
24
|
+
function shouldCollectCoverage(config) {
|
|
25
|
+
return !config.activeMutant && !!config.coverageFile;
|
|
26
|
+
}
|
|
27
|
+
function waitForSyncReady(socket) {
|
|
28
|
+
return new Promise((resolve) => {
|
|
29
|
+
socket.addEventListener("message", (event) => {
|
|
30
|
+
if (event.data === "ready") {
|
|
31
|
+
resolve({ ready: true });
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
socket.addEventListener("error", () => {
|
|
35
|
+
resolve({ ready: false, problem: "failed with a connection error" });
|
|
36
|
+
});
|
|
37
|
+
socket.addEventListener("close", (event) => {
|
|
38
|
+
const reason = event.reason ? `, reason "${event.reason}"` : "";
|
|
39
|
+
resolve({ ready: false, problem: `closed (code ${event.code ?? "unknown"}${reason})` });
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function syncAddress(syncPort) {
|
|
44
|
+
return `ws://127.0.0.1:${syncPort}/sync`;
|
|
45
|
+
}
|
|
46
|
+
async function awaitRunnerReady(deps) {
|
|
47
|
+
const openSocket = deps.openSocket ?? ((url) => new WebSocket(url));
|
|
48
|
+
const fail = deps.fail ?? ((message) => {
|
|
49
|
+
console.error(message);
|
|
50
|
+
process.exit(1);
|
|
51
|
+
});
|
|
52
|
+
let socket;
|
|
53
|
+
let outcome;
|
|
54
|
+
try {
|
|
55
|
+
socket = openSocket(`${syncAddress(deps.syncPort)}/${deps.syncToken}`);
|
|
56
|
+
outcome = await waitForSyncReady(socket);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
const reason = redactToken(error instanceof Error ? error.message : String(error), deps.syncToken);
|
|
59
|
+
return fail(formatSyncNotReadyMessage(deps.syncPort, `could not be opened (${reason})`));
|
|
60
|
+
}
|
|
61
|
+
if (!outcome.ready) {
|
|
62
|
+
return fail(formatSyncNotReadyMessage(deps.syncPort, outcome.problem));
|
|
63
|
+
}
|
|
64
|
+
if (deps.keepOpen) {
|
|
65
|
+
return socket;
|
|
66
|
+
}
|
|
67
|
+
socket.close();
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
function redactToken(text, token) {
|
|
71
|
+
return token === "" ? text : text.replaceAll(token, "[redacted]");
|
|
72
|
+
}
|
|
73
|
+
function formatSyncNotReadyMessage(syncPort, problem) {
|
|
74
|
+
return [
|
|
75
|
+
`[Stryker] stryker-bun-runner: the dry run's sync connection to the runner (${syncAddress(syncPort)}) ${problem}`,
|
|
76
|
+
"before the runner signalled that it is ready to observe the tests. Exiting without running any test: tests run now",
|
|
77
|
+
"would not be seen by the runner's inspector, so their results and per-test coverage would be lost."
|
|
78
|
+
].join(" ");
|
|
79
|
+
}
|
|
80
|
+
var PRELOAD_TIMINGS_ENV = "__STRYKER_PRELOAD_TIMINGS__";
|
|
81
|
+
function preloadEpochNow() {
|
|
82
|
+
return performance.timeOrigin + performance.now();
|
|
83
|
+
}
|
|
84
|
+
var PRELOAD_TIMINGS_PREFIX = "[Stryker Timings] ";
|
|
85
|
+
function formatPreloadTimings(timings) {
|
|
86
|
+
return `
|
|
87
|
+
${PRELOAD_TIMINGS_PREFIX}${JSON.stringify(timings)}
|
|
88
|
+
`;
|
|
89
|
+
}
|
|
90
|
+
function initializeStrykerNamespace(globalObj) {
|
|
91
|
+
const g = globalObj;
|
|
92
|
+
g.__stryker__ ??= { mutantCoverage: { static: {}, perTest: {} } };
|
|
93
|
+
const strykerGlobal = g.__stryker__;
|
|
94
|
+
strykerGlobal.mutantCoverage ??= { static: {}, perTest: {} };
|
|
95
|
+
g.__mutantCoverage__ = strykerGlobal.mutantCoverage;
|
|
96
|
+
return strykerGlobal;
|
|
97
|
+
}
|
|
98
|
+
function setActiveMutant(strykerNamespace, activeMutant) {
|
|
99
|
+
strykerNamespace.activeMutant = activeMutant;
|
|
100
|
+
}
|
|
101
|
+
var HIT_LIMIT_SENTINEL = "__STRYKER_HIT_LIMIT_REACHED__";
|
|
102
|
+
function formatHitLimitSentinel(token, hitCount) {
|
|
103
|
+
return `
|
|
104
|
+
${HIT_LIMIT_SENTINEL} ${token} ${hitCount}
|
|
105
|
+
`;
|
|
106
|
+
}
|
|
107
|
+
function installHitLimit(strykerNamespace, hitLimit, token, report = (line) => {
|
|
108
|
+
preloadFs.writeSync(2, line);
|
|
109
|
+
}) {
|
|
110
|
+
let hitCount = 0;
|
|
111
|
+
let reported = false;
|
|
112
|
+
strykerNamespace.hitLimit = hitLimit;
|
|
113
|
+
Object.defineProperty(strykerNamespace, "hitCount", {
|
|
114
|
+
configurable: true,
|
|
115
|
+
enumerable: true,
|
|
116
|
+
get: () => hitCount,
|
|
117
|
+
set: (value) => {
|
|
118
|
+
hitCount = value;
|
|
119
|
+
if (!reported && hitCount > hitLimit) {
|
|
120
|
+
reported = true;
|
|
121
|
+
report(formatHitLimitSentinel(token, hitCount));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
class StaticGapTracker {
|
|
128
|
+
coverage;
|
|
129
|
+
held;
|
|
130
|
+
constructor(coverage) {
|
|
131
|
+
this.coverage = coverage;
|
|
132
|
+
}
|
|
133
|
+
open() {
|
|
134
|
+
this.close();
|
|
135
|
+
this.held = this.coverage.static;
|
|
136
|
+
this.coverage.static = {};
|
|
137
|
+
}
|
|
138
|
+
close() {
|
|
139
|
+
const held = this.held;
|
|
140
|
+
if (held === undefined) {
|
|
141
|
+
return [];
|
|
142
|
+
}
|
|
143
|
+
const gap = this.coverage.static;
|
|
144
|
+
this.coverage.static = held;
|
|
145
|
+
this.held = undefined;
|
|
146
|
+
const ids = Object.keys(gap);
|
|
147
|
+
for (const id of ids) {
|
|
148
|
+
held[id] = (held[id] ?? 0) + gap[id];
|
|
149
|
+
}
|
|
150
|
+
return ids;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function serializeCoverageData(mutantCoverage, lateHits = [], gapTracker) {
|
|
154
|
+
gapTracker?.close();
|
|
155
|
+
const data = {
|
|
156
|
+
perTest: mutantCoverage?.perTest ?? {},
|
|
157
|
+
static: mutantCoverage?.static ?? {},
|
|
158
|
+
...lateHits.length > 0 ? { lateHits } : {}
|
|
159
|
+
};
|
|
160
|
+
return JSON.stringify(data);
|
|
161
|
+
}
|
|
162
|
+
var COVERAGE_APPEND_FLAGS = constants.O_WRONLY | constants.O_APPEND | constants.O_CREAT | constants.O_NOFOLLOW;
|
|
163
|
+
function writeCoverageToFile(coverageFile, data) {
|
|
164
|
+
const line = typeof data === "string" ? data : JSON.stringify(data);
|
|
165
|
+
const fd = preloadFs.openSync(coverageFile, COVERAGE_APPEND_FLAGS, 384);
|
|
166
|
+
try {
|
|
167
|
+
preloadFs.appendFileSync(fd, `${line}
|
|
168
|
+
`, "utf8");
|
|
169
|
+
} finally {
|
|
170
|
+
preloadFs.closeSync(fd);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
async function readEagerModules(file, deps = {}) {
|
|
174
|
+
if (file === null) {
|
|
175
|
+
return [];
|
|
176
|
+
}
|
|
177
|
+
const readJson = deps.readJson ?? ((listFile) => globalThis.Bun.file(listFile).json());
|
|
178
|
+
let problem;
|
|
179
|
+
try {
|
|
180
|
+
const list = await readJson(file);
|
|
181
|
+
if (Array.isArray(list) && list.every((entry) => typeof entry === "string")) {
|
|
182
|
+
return list;
|
|
183
|
+
}
|
|
184
|
+
problem = "not a JSON array of module paths";
|
|
185
|
+
} catch (error) {
|
|
186
|
+
problem = describeError(error);
|
|
187
|
+
}
|
|
188
|
+
(deps.warn ?? console.warn)(`[Stryker] Could not read the eager module list ${file} (${problem}); importing no modules ahead of the tests, so module-level mutants may be attributed to a test instead of to static coverage`);
|
|
189
|
+
return [];
|
|
190
|
+
}
|
|
191
|
+
var LIFELINE_FD_ENV = "__STRYKER_LIFELINE_FD__";
|
|
192
|
+
function describeError(error) {
|
|
193
|
+
const { code, message } = error;
|
|
194
|
+
return String(code ?? message);
|
|
195
|
+
}
|
|
196
|
+
function parseLifelineFd(value) {
|
|
197
|
+
if (value === undefined || !/^\d+$/.test(value)) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
const fd = Number(value);
|
|
201
|
+
return Number.isSafeInteger(fd) && fd > 2 ? fd : undefined;
|
|
202
|
+
}
|
|
203
|
+
function openLifelineReader(fd, file) {
|
|
204
|
+
const openFile = file ?? ((lifelineFd) => globalThis.Bun.file(lifelineFd));
|
|
205
|
+
const reader = openFile(fd).stream().getReader();
|
|
206
|
+
let onEnd;
|
|
207
|
+
let onError;
|
|
208
|
+
const drain = async () => {
|
|
209
|
+
for (;; ) {
|
|
210
|
+
const { done } = await reader.read();
|
|
211
|
+
if (done) {
|
|
212
|
+
onEnd?.();
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
return {
|
|
218
|
+
once(_event, listener) {
|
|
219
|
+
onEnd = listener;
|
|
220
|
+
},
|
|
221
|
+
on(_event, listener) {
|
|
222
|
+
onError = listener;
|
|
223
|
+
},
|
|
224
|
+
resume() {
|
|
225
|
+
drain().catch((error) => {
|
|
226
|
+
onError?.(error);
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
function watchParentLifeline(deps) {
|
|
232
|
+
let settled = false;
|
|
233
|
+
const unavailable = (reason) => {
|
|
234
|
+
if (!settled) {
|
|
235
|
+
settled = true;
|
|
236
|
+
deps.onUnavailable(reason);
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
const fd = parseLifelineFd(deps.fdValue);
|
|
240
|
+
if (fd === undefined) {
|
|
241
|
+
unavailable(`${LIFELINE_FD_ENV}=${deps.fdValue ?? "(unset)"} names no lifeline descriptor`);
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
const open = deps.open ?? ((lifelineFd) => openLifelineReader(lifelineFd));
|
|
245
|
+
let lifeline;
|
|
246
|
+
try {
|
|
247
|
+
lifeline = open(fd);
|
|
248
|
+
} catch (error) {
|
|
249
|
+
unavailable(`opening fd ${fd} failed: ${describeError(error)}`);
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
lifeline.once("end", () => {
|
|
253
|
+
settled = true;
|
|
254
|
+
deps.onOrphaned();
|
|
255
|
+
});
|
|
256
|
+
lifeline.on("error", (error) => {
|
|
257
|
+
unavailable(`reading fd ${fd} failed: ${describeError(error)}`);
|
|
258
|
+
});
|
|
259
|
+
lifeline.resume();
|
|
260
|
+
}
|
|
261
|
+
function startOrphanWatchdog(deps) {
|
|
262
|
+
const originalPpid = deps.originalPpid ?? deps.getPpid();
|
|
263
|
+
let fired = false;
|
|
264
|
+
const intervalId = setInterval(() => {
|
|
265
|
+
if (fired || deps.getPpid() === originalPpid) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
fired = true;
|
|
269
|
+
deps.onOrphaned();
|
|
270
|
+
}, deps.intervalMs ?? 1000);
|
|
271
|
+
intervalId.unref();
|
|
272
|
+
return () => {
|
|
273
|
+
clearInterval(intervalId);
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
function guardAgainstOrphaning(deps) {
|
|
277
|
+
const originalPpid = deps.getPpid();
|
|
278
|
+
watchParentLifeline({
|
|
279
|
+
fdValue: deps.fdValue,
|
|
280
|
+
onOrphaned: deps.onOrphaned,
|
|
281
|
+
open: deps.open,
|
|
282
|
+
onUnavailable: (reason) => {
|
|
283
|
+
deps.log?.(`[Stryker] parent lifeline unavailable (${reason}); polling the parent PID on a timer instead`);
|
|
284
|
+
startOrphanWatchdog({ getPpid: deps.getPpid, onOrphaned: deps.onOrphaned, intervalMs: deps.intervalMs, originalPpid });
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
var ORPHAN_DEBUG_ENV = "STRYKER_BUN_RUNNER_DEBUG";
|
|
289
|
+
function orphanDebugLog(value, write) {
|
|
290
|
+
if (value === undefined || value === "" || value === "0" || value === "false") {
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
return (message) => {
|
|
294
|
+
write(`${message}
|
|
295
|
+
`);
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// src/templates/coverage-preload.ts
|
|
300
|
+
var timings = process.env[PRELOAD_TIMINGS_ENV] ? {} : undefined;
|
|
301
|
+
var nowEpoch = preloadEpochNow;
|
|
302
|
+
if (timings) {
|
|
303
|
+
timings["at.preloadStart"] = nowEpoch();
|
|
304
|
+
}
|
|
305
|
+
guardAgainstOrphaning({
|
|
306
|
+
fdValue: process.env[LIFELINE_FD_ENV],
|
|
307
|
+
getPpid: () => process.ppid,
|
|
308
|
+
log: orphanDebugLog(process.env[ORPHAN_DEBUG_ENV], (text) => process.stderr.write(text)),
|
|
309
|
+
onOrphaned: () => {
|
|
310
|
+
console.warn("[Stryker] Parent process is no longer running \u2014 terminating to avoid an orphaned bun test process");
|
|
311
|
+
process.exit(1);
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
Object.defineProperty(describe, "concurrent", { value: describe, writable: true, configurable: true });
|
|
315
|
+
Object.defineProperty(test, "concurrent", { value: test, writable: true, configurable: true });
|
|
316
|
+
Object.defineProperty(it, "concurrent", { value: it, writable: true, configurable: true });
|
|
317
|
+
var EAGER_MODULES_FILE = __EAGER_MODULES_FILE__;
|
|
318
|
+
var config = getPreloadConfig();
|
|
319
|
+
var { syncPort, syncToken, coverageFile, activeMutant, hitLimit, hitLimitToken } = config;
|
|
320
|
+
delete process.env[HIT_LIMIT_TOKEN_ENV];
|
|
321
|
+
delete process.env[SYNC_TOKEN_ENV];
|
|
322
|
+
var shouldCollectCoverage2 = shouldCollectCoverage(config);
|
|
323
|
+
var ws = null;
|
|
324
|
+
var DRAIN_ACK_TIMEOUT_MS = 40000;
|
|
325
|
+
var perFileCounters = new Map;
|
|
326
|
+
function extractFilePrefix(bunMain) {
|
|
327
|
+
if (!bunMain) {
|
|
328
|
+
return "unknown";
|
|
329
|
+
}
|
|
330
|
+
const sandboxMatch = /\.stryker-tmp\/sandbox-[^/]+\/(.+)$/.exec(bunMain);
|
|
331
|
+
if (sandboxMatch) {
|
|
332
|
+
return sandboxMatch[1];
|
|
333
|
+
}
|
|
334
|
+
const cwd = process.cwd();
|
|
335
|
+
if (bunMain.startsWith(`${cwd}/`)) {
|
|
336
|
+
return bunMain.slice(cwd.length + 1);
|
|
337
|
+
}
|
|
338
|
+
return bunMain.replace(/^.*\//, "");
|
|
339
|
+
}
|
|
340
|
+
var lastEndedTestId;
|
|
341
|
+
var lastFilePrefix;
|
|
342
|
+
var lateHits = [];
|
|
343
|
+
var lastBunMain;
|
|
344
|
+
var currentFilePrefix = "";
|
|
345
|
+
if (syncPort) {
|
|
346
|
+
ws = await awaitRunnerReady({ syncPort, syncToken: syncToken ?? "", keepOpen: shouldCollectCoverage2 });
|
|
347
|
+
if (timings) {
|
|
348
|
+
timings["at.preloadReady"] = nowEpoch();
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
var g = globalThis;
|
|
352
|
+
var strykerGlobal = initializeStrykerNamespace(g);
|
|
353
|
+
var mutantCoverage = strykerGlobal.mutantCoverage;
|
|
354
|
+
var gapTracker = new StaticGapTracker(mutantCoverage);
|
|
355
|
+
if (activeMutant) {
|
|
356
|
+
setActiveMutant(strykerGlobal, activeMutant);
|
|
357
|
+
if (hitLimit !== undefined && hitLimitToken) {
|
|
358
|
+
installHitLimit(strykerGlobal, hitLimit, hitLimitToken);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
if (shouldCollectCoverage2) {
|
|
362
|
+
const EAGER_MODULES = await readEagerModules(EAGER_MODULES_FILE);
|
|
363
|
+
for (const modPath of EAGER_MODULES) {
|
|
364
|
+
try {
|
|
365
|
+
await import(modPath);
|
|
366
|
+
} catch (err) {
|
|
367
|
+
console.warn(`[Stryker] Eager import failed for ${modPath}:`, err);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
if (timings) {
|
|
371
|
+
timings["at.eagerImported"] = nowEpoch();
|
|
372
|
+
timings.eagerModules = EAGER_MODULES.length;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
var writeCoverageData = () => {
|
|
376
|
+
if (!shouldCollectCoverage2 || !coverageFile) {
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
const data = serializeCoverageData(strykerGlobal.mutantCoverage, lateHits, gapTracker);
|
|
380
|
+
if (timings) {
|
|
381
|
+
timings["at.coverageFormatted"] = nowEpoch();
|
|
382
|
+
timings["bytes.coverage"] = data.length;
|
|
383
|
+
}
|
|
384
|
+
try {
|
|
385
|
+
writeCoverageToFile(coverageFile, data);
|
|
386
|
+
if (timings) {
|
|
387
|
+
timings["at.coverageWritten"] = nowEpoch();
|
|
388
|
+
}
|
|
389
|
+
} catch (error) {
|
|
390
|
+
console.error(`[Stryker Coverage] Failed to write coverage to ${coverageFile}: ${error instanceof Error ? error.message : String(error)}`);
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
if (shouldCollectCoverage2) {
|
|
394
|
+
beforeEach(() => {
|
|
395
|
+
const hookStart = timings ? performance.now() : 0;
|
|
396
|
+
const bunMain = String(globalThis.Bun?.main ?? "");
|
|
397
|
+
if (bunMain !== lastBunMain) {
|
|
398
|
+
lastBunMain = bunMain;
|
|
399
|
+
currentFilePrefix = extractFilePrefix(bunMain);
|
|
400
|
+
}
|
|
401
|
+
const filePrefix = currentFilePrefix;
|
|
402
|
+
const bledMutantIds = gapTracker.close();
|
|
403
|
+
if (filePrefix !== lastFilePrefix) {
|
|
404
|
+
lastEndedTestId = undefined;
|
|
405
|
+
} else if (lastEndedTestId !== undefined && bledMutantIds.length > 0) {
|
|
406
|
+
lateHits.push({ testId: lastEndedTestId, mutantIds: bledMutantIds });
|
|
407
|
+
}
|
|
408
|
+
const prevCount = perFileCounters.get(filePrefix) ?? 0;
|
|
409
|
+
const nextCount = prevCount + 1;
|
|
410
|
+
perFileCounters.set(filePrefix, nextCount);
|
|
411
|
+
const testId = `${filePrefix}@@test-${nextCount}`;
|
|
412
|
+
strykerGlobal.currentTestId = testId;
|
|
413
|
+
mutantCoverage.perTest[testId] ??= {};
|
|
414
|
+
if (timings) {
|
|
415
|
+
timings["at.firstTest"] ??= nowEpoch();
|
|
416
|
+
timings["ms.beforeEach"] = (timings["ms.beforeEach"] ?? 0) + (performance.now() - hookStart);
|
|
417
|
+
timings.tests = (timings.tests ?? 0) + 1;
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
afterEach(() => {
|
|
421
|
+
const hookStart = timings ? performance.now() : 0;
|
|
422
|
+
const endedTestId = strykerGlobal.currentTestId;
|
|
423
|
+
lastEndedTestId = endedTestId;
|
|
424
|
+
if (endedTestId) {
|
|
425
|
+
const sepIdx = endedTestId.lastIndexOf("@@");
|
|
426
|
+
lastFilePrefix = sepIdx === -1 ? endedTestId : endedTestId.slice(0, sepIdx);
|
|
427
|
+
}
|
|
428
|
+
gapTracker.open();
|
|
429
|
+
strykerGlobal.currentTestId = undefined;
|
|
430
|
+
if (timings) {
|
|
431
|
+
timings["ms.afterEach"] = (timings["ms.afterEach"] ?? 0) + (performance.now() - hookStart);
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
afterAll(async () => {
|
|
435
|
+
if (timings) {
|
|
436
|
+
timings["at.afterAll"] = nowEpoch();
|
|
437
|
+
timings.afterAlls = (timings.afterAlls ?? 0) + 1;
|
|
438
|
+
}
|
|
439
|
+
const trailingBleed = gapTracker.close();
|
|
440
|
+
if (lastEndedTestId !== undefined && trailingBleed.length > 0) {
|
|
441
|
+
lateHits.push({ testId: lastEndedTestId, mutantIds: trailingBleed });
|
|
442
|
+
}
|
|
443
|
+
writeCoverageData();
|
|
444
|
+
lateHits.length = 0;
|
|
445
|
+
if (ws && ws.readyState === WebSocket.OPEN) {
|
|
446
|
+
try {
|
|
447
|
+
await new Promise((resolve) => {
|
|
448
|
+
const wsForDrain = ws;
|
|
449
|
+
const timeout = setTimeout(() => {
|
|
450
|
+
console.warn("[Stryker] Timeout waiting for drain acknowledgment");
|
|
451
|
+
resolve();
|
|
452
|
+
}, DRAIN_ACK_TIMEOUT_MS);
|
|
453
|
+
wsForDrain.onmessage = (event) => {
|
|
454
|
+
if (event.data === "drained") {
|
|
455
|
+
clearTimeout(timeout);
|
|
456
|
+
resolve();
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
wsForDrain.onerror = () => {
|
|
460
|
+
clearTimeout(timeout);
|
|
461
|
+
resolve();
|
|
462
|
+
};
|
|
463
|
+
try {
|
|
464
|
+
if (timings) {
|
|
465
|
+
timings["at.drainRequested"] = nowEpoch();
|
|
466
|
+
}
|
|
467
|
+
wsForDrain.send("drain-request");
|
|
468
|
+
} catch {
|
|
469
|
+
clearTimeout(timeout);
|
|
470
|
+
resolve();
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
} catch (error) {
|
|
474
|
+
console.warn("[Stryker] Error during drain handshake:", error);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
if (timings) {
|
|
478
|
+
timings["at.drained"] = nowEpoch();
|
|
479
|
+
preloadFs.writeSync(2, formatPreloadTimings(timings));
|
|
480
|
+
}
|
|
481
|
+
ws?.close();
|
|
482
|
+
});
|
|
483
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hughescr/stryker-bun-runner",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "Stryker mutation testing test runner plugin for Bun (bun test), with per-test coverage",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"stryker",
|
|
@@ -35,12 +35,14 @@
|
|
|
35
35
|
"dist"
|
|
36
36
|
],
|
|
37
37
|
"scripts": {
|
|
38
|
-
"build": "bun build src/index.ts --outdir dist --target node --format esm --packages external && bun build
|
|
38
|
+
"build": "rm -rf dist && bun build src/index.ts --outdir dist --target node --format esm --packages external && bun scripts/build-preload.ts dist/templates && dts-bundle-generator --config dts-bundle-generator.config.json",
|
|
39
39
|
"lint": "eslint --cache --format unix .",
|
|
40
40
|
"mutate": "stryker run",
|
|
41
41
|
"prepublishOnly": "bun run build",
|
|
42
42
|
"test": "bun test",
|
|
43
43
|
"typecheck": "node node_modules/typescript/bin/tsc --noEmit && node node_modules/typescript/bin/tsc --noEmit -p scripts",
|
|
44
|
+
"bench": "sh bench/lock.sh --exclusive -- bun bench/run.ts",
|
|
45
|
+
"checks": "sh bench/lock.sh --shared -- sh -c 'bun test && bun run lint && bun run typecheck'",
|
|
44
46
|
"postversion": "git commit -m \"Bump package version to $npm_package_version\" package.json; git flow release start $npm_package_version; git flow release finish -m $npm_package_version $npm_package_version; git checkout develop; git merge main"
|
|
45
47
|
},
|
|
46
48
|
"dependencies": {
|