supercov 4.24.8 → 4.26.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/bin/arguments.js +26 -0
- package/bin/supercov.js +2 -1
- package/docs/cli.md +16 -0
- package/docs/workspace-isolation.md +3 -0
- package/package.json +10 -9
- package/runtime/javascript/atomic.mjs +20 -3
- package/runtime/javascript/launchSupervisor.mjs +10 -0
- package/runtime/javascript/playwright.mjs +441 -181
- package/runtime/javascript/playwrightCacheThread.mjs +6 -0
- package/runtime/javascript/register.mjs +84 -10
- package/runtime/javascript/resolve-loader.mjs +45 -3
- package/runtime/javascript/runnerEvidence.mjs +16 -1
- package/runtime/javascript/runtime.mjs +313 -92
- package/runtime/javascript/snapshots.mjs +149 -0
- package/runtime/javascript/transport.mjs +36 -0
- package/runtime/javascript/vitest.mjs +6 -2
|
@@ -37,7 +37,8 @@ var COVERAGE_CARRIER_ENV = "SUPERCOV_CONTEXT";
|
|
|
37
37
|
var DEFAULT_SERVER_EVIDENCE_ROOT = "/tmp/supercov-server-evidence";
|
|
38
38
|
function configuredServerEvidenceRoot() {
|
|
39
39
|
var _a8;
|
|
40
|
-
|
|
40
|
+
const configured = typeof process !== "undefined" ? (_a8 = process.env) == null ? void 0 : _a8["SUPERCOV_SERVER_EVIDENCE_ROOT"] : void 0;
|
|
41
|
+
return configured ? configured : DEFAULT_SERVER_EVIDENCE_ROOT;
|
|
41
42
|
}
|
|
42
43
|
function nonEmpty(value) {
|
|
43
44
|
return typeof value === "string" && value.length > 0;
|
|
@@ -117,6 +118,18 @@ function serverEvidenceDirectory(scope, root = configuredServerEvidenceRoot()) {
|
|
|
117
118
|
function serverEvidencePath(scope, root = configuredServerEvidenceRoot()) {
|
|
118
119
|
return `${serverEvidenceDirectory(scope, root)}/${pathComponent(scope.attemptId)}.jsonl`;
|
|
119
120
|
}
|
|
121
|
+
// A scope's evidence directory and file, made once per scope and root: a
|
|
122
|
+
// server works them out for every record it writes, thousands per test.
|
|
123
|
+
var scopedEvidenceLocations = /* @__PURE__ */ new WeakMap();
|
|
124
|
+
function scopedEvidenceLocation(scope) {
|
|
125
|
+
const root = configuredServerEvidenceRoot();
|
|
126
|
+
const known = scopedEvidenceLocations.get(scope);
|
|
127
|
+
if (known !== void 0 && known.root === root)
|
|
128
|
+
return known;
|
|
129
|
+
const location = { root, directory: serverEvidenceDirectory(scope, root), path: serverEvidencePath(scope, root) };
|
|
130
|
+
scopedEvidenceLocations.set(scope, location);
|
|
131
|
+
return location;
|
|
132
|
+
}
|
|
120
133
|
function backgroundEvidenceDirectory(runId, root = configuredServerEvidenceRoot()) {
|
|
121
134
|
return `${serverRunEvidenceDirectory(runId, root)}/background`;
|
|
122
135
|
}
|
|
@@ -157,7 +170,9 @@ function createState() {
|
|
|
157
170
|
// Per value-position logical expression (`a && b`, `a || b`, `a ?? b`): the distinct
|
|
158
171
|
// (right operand evaluated?, result truthy?) pairs seen, keyed by branch id.
|
|
159
172
|
logicals: /* @__PURE__ */ new Map(),
|
|
160
|
-
|
|
173
|
+
// The events already recorded, by phase: a hit by its id, anything else
|
|
174
|
+
// by its type and what tells it apart (eventSeen).
|
|
175
|
+
eventKeys: /* @__PURE__ */ new Map(),
|
|
161
176
|
bufferedAttempts: /* @__PURE__ */ new Set(),
|
|
162
177
|
serverBuffers: /* @__PURE__ */ new Map(),
|
|
163
178
|
persistedServerRecords: /* @__PURE__ */ new Set(),
|
|
@@ -194,7 +209,7 @@ function createState() {
|
|
|
194
209
|
state2.hits.add(id);
|
|
195
210
|
for (const event of (_d = stored.events) != null ? _d : []) {
|
|
196
211
|
state2.events.push(event);
|
|
197
|
-
state2.eventKeys
|
|
212
|
+
eventSeen(state2.eventKeys, event);
|
|
198
213
|
}
|
|
199
214
|
} catch (e) {
|
|
200
215
|
}
|
|
@@ -241,13 +256,14 @@ function activateProbeV2Key(key, force = false) {
|
|
|
241
256
|
if (state.probeV2NextEpoch >= 4294967295) {
|
|
242
257
|
state.probeV2NextEpoch = 1;
|
|
243
258
|
state.probeV2ContextEpochs.clear();
|
|
259
|
+
state.probeV2EpochGeneration = (state.probeV2EpochGeneration || 0) + 1;
|
|
244
260
|
for (const file of state.probeV2Files) {
|
|
245
261
|
file.hitEpochs.fill(0);
|
|
246
262
|
file.decisionObservationEpochs.fill(0);
|
|
247
263
|
file.decisionObservationCounts.fill(0);
|
|
248
264
|
file.decisionCompleteEpochs.fill(0);
|
|
249
265
|
for (const vectors of file.decisionEpochs) {
|
|
250
|
-
if (vectors
|
|
266
|
+
if (vectors.size === void 0)
|
|
251
267
|
vectors.fill(0);
|
|
252
268
|
else
|
|
253
269
|
vectors.clear();
|
|
@@ -260,8 +276,38 @@ function activateProbeV2Key(key, force = false) {
|
|
|
260
276
|
state.probeV2Clock.epoch = epoch;
|
|
261
277
|
return epoch;
|
|
262
278
|
}
|
|
279
|
+
// The async hook activates the current request's context before every
|
|
280
|
+
// callback the server runs, and building its key and looking it up was most of
|
|
281
|
+
// a Next server's time in the hook. A request's context object is never
|
|
282
|
+
// changed once made, and its key is made of it alone, so each keeps the epoch
|
|
283
|
+
// it was given until the epochs are cleared.
|
|
284
|
+
// Every copy of the runtime in a process shares one state, and the hook is the
|
|
285
|
+
// first copy's, so the cache and its generation live on that state too: a
|
|
286
|
+
// reset from another copy has to reach them.
|
|
287
|
+
var emptyProbeV2Context = Object.freeze({});
|
|
263
288
|
function activateProbeV2Context(context) {
|
|
264
|
-
|
|
289
|
+
// Work no request owns is keyed by the test running when it runs, which
|
|
290
|
+
// changes under the same context: only a request's context keeps its epoch.
|
|
291
|
+
if (!context.scope)
|
|
292
|
+
return activateProbeV2Key(probeV2ContextKey(context));
|
|
293
|
+
if (state.probeV2ContextEpochCache === void 0) {
|
|
294
|
+
state.probeV2ContextEpochCache = /* @__PURE__ */ new WeakMap();
|
|
295
|
+
state.probeV2EpochGeneration = 0;
|
|
296
|
+
}
|
|
297
|
+
const cached = state.probeV2ContextEpochCache.get(context);
|
|
298
|
+
if (cached !== void 0 && cached.generation === state.probeV2EpochGeneration) {
|
|
299
|
+
state.probeV2Clock.epoch = cached.epoch;
|
|
300
|
+
return cached.epoch;
|
|
301
|
+
}
|
|
302
|
+
const epoch = activateProbeV2Key(probeV2ContextKey(context));
|
|
303
|
+
state.probeV2ContextEpochCache.set(context, { generation: state.probeV2EpochGeneration, epoch });
|
|
304
|
+
return epoch;
|
|
305
|
+
}
|
|
306
|
+
// The context the async hook leaves to a callback's first probe: the
|
|
307
|
+
// request's store, or else the one the environment carries.
|
|
308
|
+
function resolveProbeV2Epoch() {
|
|
309
|
+
var _a8, _b;
|
|
310
|
+
return activateProbeV2Context((_b = (_a8 = serverPhaseStorage == null ? void 0 : serverPhaseStorage.getStore()) != null ? _a8 : environmentRequestContext()) != null ? _b : emptyProbeV2Context);
|
|
265
311
|
}
|
|
266
312
|
function withProbeV2Context(context, callback) {
|
|
267
313
|
const previous = state.probeV2Clock.epoch;
|
|
@@ -283,10 +329,14 @@ function installProbeV2AsyncHook() {
|
|
|
283
329
|
return;
|
|
284
330
|
const epochs = [];
|
|
285
331
|
createHook({
|
|
332
|
+
// NaN, which no epoch equals: the callback's first probe works out
|
|
333
|
+
// its context. Most callbacks a server or a test runner runs reach no
|
|
334
|
+
// instrumented code, and working it out here, for every one, read the
|
|
335
|
+
// environment twice and built a key each time: on a Next app's suite,
|
|
336
|
+
// more of the server's time than any of Supercov's other work.
|
|
286
337
|
before() {
|
|
287
|
-
var _a9, _b;
|
|
288
338
|
epochs.push(state.probeV2Clock.epoch);
|
|
289
|
-
|
|
339
|
+
state.probeV2Clock.epoch = NaN;
|
|
290
340
|
},
|
|
291
341
|
after() {
|
|
292
342
|
var _a9;
|
|
@@ -329,6 +379,7 @@ function resetCoverage(testId2) {
|
|
|
329
379
|
state.logicals.clear();
|
|
330
380
|
state.eventKeys.clear();
|
|
331
381
|
state.probeV2ContextEpochs.clear();
|
|
382
|
+
state.probeV2EpochGeneration = (state.probeV2EpochGeneration || 0) + 1;
|
|
332
383
|
activateProbeV2Key(`reset\0${state.probeV2NextEpoch}`, true);
|
|
333
384
|
if (testId2)
|
|
334
385
|
runtimeGlobal.__SUPERCOV_MCDC_TEST_ID__ = testId2;
|
|
@@ -341,6 +392,78 @@ function resetCoverage(testId2) {
|
|
|
341
392
|
}
|
|
342
393
|
runtimeGlobal.__SUPERCOV_MCDC_SNAPSHOT__ = decisionSnapshot;
|
|
343
394
|
runtimeGlobal.__SUPERCOV_COVERAGE_SNAPSHOT__ = coverageSnapshot;
|
|
395
|
+
// A snapshot as the text the Playwright collector reads back. Its events
|
|
396
|
+
// become rows over one table of the strings they repeat -- point ids, phase
|
|
397
|
+
// ids, kinds -- each row in the key order of its event (`shapes`), and its
|
|
398
|
+
// hits indexes into the same table; snapshots.mjs's expandSnapshot gives
|
|
399
|
+
// back what JSON.parse of the whole would have. A large frontend's page
|
|
400
|
+
// holds tens of thousands of events, each naming its point, phase and
|
|
401
|
+
// environment in full, read back at the end of every test and from every
|
|
402
|
+
// page that leaves: relaying them cost the browser's own process more than
|
|
403
|
+
// its renderers spent running the app.
|
|
404
|
+
function compactSnapshotText(snapshot) {
|
|
405
|
+
if (!snapshot || typeof snapshot !== "object" || !Array.isArray(snapshot.events) || !Array.isArray(snapshot.hits))
|
|
406
|
+
return JSON.stringify(snapshot);
|
|
407
|
+
const strings = [];
|
|
408
|
+
const stringIndexes = /* @__PURE__ */ new Map();
|
|
409
|
+
const intern = (value) => {
|
|
410
|
+
let index = stringIndexes.get(value);
|
|
411
|
+
if (index === void 0) {
|
|
412
|
+
index = strings.length;
|
|
413
|
+
strings.push(value);
|
|
414
|
+
stringIndexes.set(value, index);
|
|
415
|
+
}
|
|
416
|
+
return index;
|
|
417
|
+
};
|
|
418
|
+
const shapes = [];
|
|
419
|
+
const shapeIndexes = /* @__PURE__ */ new Map();
|
|
420
|
+
const rows = [];
|
|
421
|
+
for (let position = 0; position < snapshot.events.length; position += 1) {
|
|
422
|
+
const event = snapshot.events[position];
|
|
423
|
+
if (!event || typeof event !== "object" || Array.isArray(event))
|
|
424
|
+
return JSON.stringify(snapshot);
|
|
425
|
+
const fields = [];
|
|
426
|
+
const values = [];
|
|
427
|
+
const keys = Object.keys(event);
|
|
428
|
+
for (let index = 0; index < keys.length; index += 1) {
|
|
429
|
+
const value = event[keys[index]];
|
|
430
|
+
// What JSON.stringify leaves out of an object.
|
|
431
|
+
if (value === void 0 || typeof value === "function" || typeof value === "symbol")
|
|
432
|
+
continue;
|
|
433
|
+
if (typeof value === "string") {
|
|
434
|
+
fields.push(`s${keys[index]}`);
|
|
435
|
+
values.push(intern(value));
|
|
436
|
+
} else {
|
|
437
|
+
fields.push(`v${keys[index]}`);
|
|
438
|
+
values.push(value);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
const name = fields.join("\0");
|
|
442
|
+
let shape = shapeIndexes.get(name);
|
|
443
|
+
if (shape === void 0) {
|
|
444
|
+
shape = shapes.length;
|
|
445
|
+
shapes.push(fields);
|
|
446
|
+
shapeIndexes.set(name, shape);
|
|
447
|
+
}
|
|
448
|
+
rows.push(shape);
|
|
449
|
+
for (let index = 0; index < values.length; index += 1)
|
|
450
|
+
rows.push(values[index]);
|
|
451
|
+
}
|
|
452
|
+
const hits = [];
|
|
453
|
+
for (let index = 0; index < snapshot.hits.length; index += 1) {
|
|
454
|
+
if (typeof snapshot.hits[index] !== "string")
|
|
455
|
+
return JSON.stringify(snapshot);
|
|
456
|
+
hits.push(intern(snapshot.hits[index]));
|
|
457
|
+
}
|
|
458
|
+
const rest = {};
|
|
459
|
+
const keys = Object.keys(snapshot);
|
|
460
|
+
for (let index = 0; index < keys.length; index += 1) {
|
|
461
|
+
if (keys[index] !== "events" && keys[index] !== "hits")
|
|
462
|
+
rest[keys[index]] = snapshot[keys[index]];
|
|
463
|
+
}
|
|
464
|
+
return JSON.stringify({ supercovCompactSnapshot: 1, order: keys, rest, strings, shapes, rows, hits });
|
|
465
|
+
}
|
|
466
|
+
runtimeGlobal.__SUPERCOV_COMPACT_SNAPSHOT__ = compactSnapshotText;
|
|
344
467
|
runtimeGlobal.__SUPERCOV_RESET__ = resetCoverage;
|
|
345
468
|
// A dedicated worker blocked in `Atomics.wait` runs no evaluation, so the
|
|
346
469
|
// test runner could not read its evidence and reported the test as a lower
|
|
@@ -417,11 +540,32 @@ function pushWorkerEvidence() {
|
|
|
417
540
|
runtimeGlobal.__SUPERCOV_WORKER_EVIDENCE__ = () => Array.from(received, ([token, pushed]) => ({ token, url: pushed.url, current: pushed.current, snapshot: pushed.snapshot }));
|
|
418
541
|
})();
|
|
419
542
|
var persistBrowserListenersInstalled = false;
|
|
543
|
+
// How much evidence the document holds. Every part of it only grows until a
|
|
544
|
+
// reset, so the same size twice is the same evidence.
|
|
545
|
+
function evidenceSize() {
|
|
546
|
+
let size = state.hits.size + state.events.length;
|
|
547
|
+
for (const decision of state.decisions.values())
|
|
548
|
+
size += decision.vectors.size;
|
|
549
|
+
for (const vectors of state.logicals.values())
|
|
550
|
+
size += vectors.size;
|
|
551
|
+
return size;
|
|
552
|
+
}
|
|
553
|
+
// The evidence's size when this document gave it to the Playwright collector
|
|
554
|
+
// on the way out. Its next document need not inherit it then: carried through
|
|
555
|
+
// localStorage as well, every page of a test parsed all the evidence of the
|
|
556
|
+
// pages before it on load and wrote it all again on leaving, a test of thirty
|
|
557
|
+
// pages paying for the first one thirty times, and the collector merged the
|
|
558
|
+
// same evidence once per page. What runs after the hand-over -- the rest of a
|
|
559
|
+
// handler that set `location.href`, a render it started -- is still carried.
|
|
560
|
+
var handedOverSize = -1;
|
|
420
561
|
function persistBrowserNow() {
|
|
421
562
|
if (!isBrowser)
|
|
422
563
|
return;
|
|
423
564
|
try {
|
|
424
|
-
|
|
565
|
+
if (handedOverSize === evidenceSize())
|
|
566
|
+
localStorage.removeItem(storageKey);
|
|
567
|
+
else
|
|
568
|
+
localStorage.setItem(storageKey, JSON.stringify(coverageSnapshot()));
|
|
425
569
|
} catch (e) {
|
|
426
570
|
}
|
|
427
571
|
}
|
|
@@ -433,8 +577,10 @@ function persistBrowserNow() {
|
|
|
433
577
|
// it does.
|
|
434
578
|
function handOverBrowser() {
|
|
435
579
|
try {
|
|
436
|
-
if (typeof runtimeGlobal.__supercovLeaving === "function")
|
|
437
|
-
runtimeGlobal.__supercovLeaving(
|
|
580
|
+
if (typeof runtimeGlobal.__supercovLeaving === "function") {
|
|
581
|
+
runtimeGlobal.__supercovLeaving(compactSnapshotText(coverageSnapshot()));
|
|
582
|
+
handedOverSize = evidenceSize();
|
|
583
|
+
}
|
|
438
584
|
} catch (e) {
|
|
439
585
|
}
|
|
440
586
|
}
|
|
@@ -468,6 +614,19 @@ function persistBrowser() {
|
|
|
468
614
|
function attemptKey(scope) {
|
|
469
615
|
return `${scope.runId}\0${scope.workerId}\0${scope.attemptId}`;
|
|
470
616
|
}
|
|
617
|
+
// An attempt's file says its scope once per writing process: each line
|
|
618
|
+
// without one is of the scope of the line before it in the same file.
|
|
619
|
+
var scopedPathsWritten = /* @__PURE__ */ new Set();
|
|
620
|
+
function serverLine(record, path) {
|
|
621
|
+
if (!path)
|
|
622
|
+
return JSON.stringify(record);
|
|
623
|
+
const { scope, ...line } = record;
|
|
624
|
+
if (scope && !scopedPathsWritten.has(path)) {
|
|
625
|
+
scopedPathsWritten.add(path);
|
|
626
|
+
line.scope = scope;
|
|
627
|
+
}
|
|
628
|
+
return JSON.stringify(line);
|
|
629
|
+
}
|
|
471
630
|
function serverRecordKey(record) {
|
|
472
631
|
var _a8;
|
|
473
632
|
const suffix = record.type === "decision" ? `${record.id}:${vectorKey(record.vector)}` : record.id;
|
|
@@ -530,7 +689,7 @@ function flushBufferedServerEvidence(scope) {
|
|
|
530
689
|
return void 0;
|
|
531
690
|
try {
|
|
532
691
|
makeEvidenceDirectory(fs, buffered.directory);
|
|
533
|
-
fs.appendFileSync(buffered.path, [...buffered.records.values()].map((record) =>
|
|
692
|
+
fs.appendFileSync(buffered.path, [...buffered.records.values()].map((record) => serverLine(record, buffered.path)).join("\n") + "\n");
|
|
534
693
|
return buffered.path;
|
|
535
694
|
} catch (e) {
|
|
536
695
|
return void 0;
|
|
@@ -758,7 +917,8 @@ function flushOnTermination(flush) {
|
|
|
758
917
|
}
|
|
759
918
|
} catch (e) {
|
|
760
919
|
}
|
|
761
|
-
|
|
920
|
+
const signals = ["SIGTERM", "SIGINT", "SIGHUP", "SIGBREAK"];
|
|
921
|
+
for (const signal of signals) {
|
|
762
922
|
try {
|
|
763
923
|
process.on(signal, () => {
|
|
764
924
|
drain();
|
|
@@ -770,6 +930,24 @@ function flushOnTermination(flush) {
|
|
|
770
930
|
} catch (e) {
|
|
771
931
|
}
|
|
772
932
|
}
|
|
933
|
+
// A listener keeps nothing alive, and a signal a process sends itself is
|
|
934
|
+
// handled on a later turn of its event loop: `process.kill(process.pid,
|
|
935
|
+
// "SIGTERM")` as a script's last line exited 0, once nothing else held the
|
|
936
|
+
// loop open, where alone it ended by the signal. A signal to itself that
|
|
937
|
+
// only this listener would take is drained and left to act at once.
|
|
938
|
+
try {
|
|
939
|
+
const kill = process.kill;
|
|
940
|
+
const numbered = { 1: "SIGHUP", 2: "SIGINT", 15: "SIGTERM", 21: "SIGBREAK" };
|
|
941
|
+
process.kill = function supercovKill(pid, signal) {
|
|
942
|
+
const name = signal === void 0 ? "SIGTERM" : typeof signal === "number" ? numbered[signal] : signal;
|
|
943
|
+
if (Number(pid) === process.pid && signals.indexOf(name) >= 0 && process.listenerCount(name) <= 1) {
|
|
944
|
+
drain();
|
|
945
|
+
process.removeAllListeners(name);
|
|
946
|
+
}
|
|
947
|
+
return kill.apply(this, arguments);
|
|
948
|
+
};
|
|
949
|
+
} catch (e) {
|
|
950
|
+
}
|
|
773
951
|
}
|
|
774
952
|
// Rust compiled to wasm and measured by the Rust frontend keeps what it ran
|
|
775
953
|
// in the module's memory, behind `__supercov_region_<crate>`. When the run
|
|
@@ -995,24 +1173,10 @@ function appendServer(record) {
|
|
|
995
1173
|
var _a8, _b, _c, _d;
|
|
996
1174
|
if (state.runtimeSnapshots) {
|
|
997
1175
|
const timestampMs = (_a8 = record.timestampMs) != null ? _a8 : Date.now();
|
|
998
|
-
if (record.type === "decision")
|
|
999
|
-
recordBrowserEvent(
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
vector: record.vector,
|
|
1003
|
-
timestampMs
|
|
1004
|
-
}, record.phaseId ? { phaseId: record.phaseId } : {}), {
|
|
1005
|
-
environment: "server"
|
|
1006
|
-
}));
|
|
1007
|
-
} else {
|
|
1008
|
-
recordBrowserEvent(__spreadProps(__spreadValues({
|
|
1009
|
-
type: "hit",
|
|
1010
|
-
id: record.id,
|
|
1011
|
-
timestampMs
|
|
1012
|
-
}, record.phaseId ? { phaseId: record.phaseId } : {}), {
|
|
1013
|
-
environment: "server"
|
|
1014
|
-
}));
|
|
1015
|
-
}
|
|
1176
|
+
if (record.type === "decision")
|
|
1177
|
+
recordBrowserEvent(decisionEvent(record.id, record.vector, timestampMs, record.phaseId, "server"));
|
|
1178
|
+
else
|
|
1179
|
+
recordBrowserEvent(hitEvent(record.id, timestampMs, record.phaseId, "server"));
|
|
1016
1180
|
return;
|
|
1017
1181
|
}
|
|
1018
1182
|
const fs = getFs();
|
|
@@ -1024,8 +1188,9 @@ function appendServer(record) {
|
|
|
1024
1188
|
if (!runId)
|
|
1025
1189
|
return;
|
|
1026
1190
|
try {
|
|
1027
|
-
const
|
|
1028
|
-
const
|
|
1191
|
+
const location = scope ? scopedEvidenceLocation(scope) : void 0;
|
|
1192
|
+
const directory = location == null ? void 0 : location.directory;
|
|
1193
|
+
const path = location == null ? void 0 : location.path;
|
|
1029
1194
|
// Work done while handling a request that named no test -- a webhook a
|
|
1030
1195
|
// mock server sends -- says so, with the request's number.
|
|
1031
1196
|
const stored = serverPhaseStorage == null ? void 0 : serverPhaseStorage.getStore();
|
|
@@ -1050,7 +1215,7 @@ function appendServer(record) {
|
|
|
1050
1215
|
appendDurableBackgroundRecord(fs, runId, serialized);
|
|
1051
1216
|
return;
|
|
1052
1217
|
}
|
|
1053
|
-
enqueueServerAppend(directory, path,
|
|
1218
|
+
enqueueServerAppend(directory, path, serverLine(serialized, path) + "\n", runId);
|
|
1054
1219
|
if (deduplicationKey)
|
|
1055
1220
|
state.persistedServerRecords.add(deduplicationKey);
|
|
1056
1221
|
} catch (cause) {
|
|
@@ -1059,18 +1224,22 @@ function appendServer(record) {
|
|
|
1059
1224
|
throw serverTransportError(runId, cause);
|
|
1060
1225
|
}
|
|
1061
1226
|
}
|
|
1062
|
-
//
|
|
1063
|
-
//
|
|
1064
|
-
|
|
1227
|
+
// The context a parent process gave this one, in SUPERCOV_CONTEXT: read on
|
|
1228
|
+
// every first hit, and fixed for the process's life. Supercov only ever gives
|
|
1229
|
+
// it to a child, at spawn, so it is read once per environment object: a
|
|
1230
|
+
// read of process.env, an interceptor, on every first hit of a large suite's
|
|
1231
|
+
// tests was the runtime's largest cost. A suite that swaps process.env for
|
|
1232
|
+
// another object is read again.
|
|
1233
|
+
var decodedEnvironmentCarrier = { env: void 0, context: void 0 };
|
|
1065
1234
|
function environmentRequestContext() {
|
|
1066
1235
|
if (isBrowser || typeof process === "undefined")
|
|
1067
1236
|
return void 0;
|
|
1068
|
-
const
|
|
1069
|
-
if (
|
|
1237
|
+
const env = process.env;
|
|
1238
|
+
if (env === decodedEnvironmentCarrier.env)
|
|
1070
1239
|
return decodedEnvironmentCarrier.context;
|
|
1071
|
-
const carrier = decodeCoverageCarrier(
|
|
1240
|
+
const carrier = decodeCoverageCarrier(env[COVERAGE_CARRIER_ENV]);
|
|
1072
1241
|
const context = carrier ? __spreadValues(__spreadValues({}, carrier.scope ? { scope: carrier.scope } : {}), carrier.phaseId ? { phaseId: carrier.phaseId } : {}) : void 0;
|
|
1073
|
-
decodedEnvironmentCarrier = {
|
|
1242
|
+
decodedEnvironmentCarrier = { env, context };
|
|
1074
1243
|
return context;
|
|
1075
1244
|
}
|
|
1076
1245
|
function currentRequestContext() {
|
|
@@ -1639,13 +1808,24 @@ function noteSupport(scope) {
|
|
|
1639
1808
|
const moduleBuiltin = typeof process.getBuiltinModule === "function" ? process.getBuiltinModule("node:module") : void 0;
|
|
1640
1809
|
const cache = moduleBuiltin && moduleBuiltin._cache;
|
|
1641
1810
|
const root = process.env.SUPERCOV_PROJECT_ROOT;
|
|
1642
|
-
|
|
1811
|
+
// The in-thread module hooks count every load (resolve-loader.mjs): a
|
|
1812
|
+
// cache nothing was loaded into since the last request holds nothing
|
|
1813
|
+
// new. Listing a Next server's thousands of keys on every request was
|
|
1814
|
+
// the most of its time any of Supercov's code took. Without the count
|
|
1815
|
+
// (off-thread hooks), every request looks.
|
|
1816
|
+
const loads = runtimeGlobal.__SUPERCOV_MODULE_LOADS__;
|
|
1817
|
+
const unchanged = typeof loads === "number" && loads === supportNoted.loads;
|
|
1818
|
+
supportNoted.loads = loads;
|
|
1819
|
+
if (cache && root && !unchanged) {
|
|
1643
1820
|
for (const name of Object.keys(cache)) {
|
|
1821
|
+
// Each is looked at once, whether it is noted or not.
|
|
1822
|
+
if (supportNoted.modules.has(name))
|
|
1823
|
+
continue;
|
|
1824
|
+
supportNoted.modules.add(name);
|
|
1644
1825
|
// The copy lives under `.supercov/`: the project root decides.
|
|
1645
1826
|
const inside = name.indexOf(root) === 0 ? name.slice(root.length).replace(/^[\\/]/, "") : "";
|
|
1646
|
-
if (
|
|
1827
|
+
if (inside === "" || /^\.supercov[\\/]/.test(inside) || /(?:^|[\\/])node_modules[\\/]/.test(inside))
|
|
1647
1828
|
continue;
|
|
1648
|
-
supportNoted.modules.add(name);
|
|
1649
1829
|
lines.push({ loaded: name });
|
|
1650
1830
|
}
|
|
1651
1831
|
}
|
|
@@ -1754,16 +1934,25 @@ function withRequestPhase(handler, event) {
|
|
|
1754
1934
|
return requestContext !== void 0 || context.scope || context.phaseId ? serverPhaseStorage.run(context, () => withProbeV2Context(context, invoke)) : invoke();
|
|
1755
1935
|
};
|
|
1756
1936
|
}
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1937
|
+
// Whether `event` was already recorded, recording it if not. Kept per phase,
|
|
1938
|
+
// so a first hit looks up its id alone: one key joining the phase, the type
|
|
1939
|
+
// and the id was built and hashed for every first hit of every test.
|
|
1940
|
+
function eventSeen(seen, event) {
|
|
1941
|
+
const phase = event.phaseId != null ? event.phaseId : "unscoped";
|
|
1942
|
+
let keys = seen.get(phase);
|
|
1943
|
+
if (keys === void 0) {
|
|
1944
|
+
keys = /* @__PURE__ */ new Set();
|
|
1945
|
+
seen.set(phase, keys);
|
|
1946
|
+
}
|
|
1947
|
+
const key = event.type === "hit" ? event.id : `${event.type}\0${event.type === "decision" ? `${event.id}:${vectorKey(event.vector)}` : event.id}`;
|
|
1948
|
+
if (keys.has(key))
|
|
1949
|
+
return true;
|
|
1950
|
+
keys.add(key);
|
|
1951
|
+
return false;
|
|
1761
1952
|
}
|
|
1762
1953
|
function recordBrowserEvent(event) {
|
|
1763
|
-
|
|
1764
|
-
if (state.eventKeys.has(key))
|
|
1954
|
+
if (eventSeen(state.eventKeys, event))
|
|
1765
1955
|
return false;
|
|
1766
|
-
state.eventKeys.add(key);
|
|
1767
1956
|
state.events.push(event);
|
|
1768
1957
|
workerEvidenceChanged();
|
|
1769
1958
|
return true;
|
|
@@ -1789,6 +1978,8 @@ function recordCoverageHit(id) {
|
|
|
1789
1978
|
activateProbeV2Context(currentRequestContext());
|
|
1790
1979
|
epoch = clock.epoch;
|
|
1791
1980
|
clock.epoch = previousEpoch;
|
|
1981
|
+
} else if (epoch !== epoch) {
|
|
1982
|
+
epoch = resolveProbeV2Epoch();
|
|
1792
1983
|
}
|
|
1793
1984
|
if (!state.hitEpochs)
|
|
1794
1985
|
state.hitEpochs = /* @__PURE__ */ new Map();
|
|
@@ -1798,40 +1989,74 @@ function recordCoverageHit(id) {
|
|
|
1798
1989
|
const timestampMs = Date.now();
|
|
1799
1990
|
const phaseId = currentPhaseId();
|
|
1800
1991
|
if (isBrowser) {
|
|
1801
|
-
if (recordBrowserEvent(
|
|
1802
|
-
type: "hit",
|
|
1803
|
-
id,
|
|
1804
|
-
timestampMs
|
|
1805
|
-
}, phaseId ? { phaseId } : {}), {
|
|
1806
|
-
environment: "browser"
|
|
1807
|
-
})))
|
|
1992
|
+
if (recordBrowserEvent(hitEvent(id, timestampMs, phaseId, "browser")))
|
|
1808
1993
|
persistBrowser();
|
|
1809
1994
|
} else {
|
|
1810
|
-
appendServer(
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1995
|
+
appendServer(phaseId ? { type: "hit", id, timestampMs, phaseId } : { type: "hit", id, timestampMs });
|
|
1996
|
+
}
|
|
1997
|
+
}
|
|
1998
|
+
// A first hit's event, built as one literal in the order the spread helpers
|
|
1999
|
+
// gave its keys: they walked every key of three objects for each first hit
|
|
2000
|
+
// of every statement in every test.
|
|
2001
|
+
function hitEvent(id, timestampMs, phaseId, environment) {
|
|
2002
|
+
return phaseId ? { type: "hit", id, timestampMs, phaseId, environment } : { type: "hit", id, timestampMs, environment };
|
|
2003
|
+
}
|
|
2004
|
+
function decisionEvent(id, vector, timestampMs, phaseId, environment) {
|
|
2005
|
+
return phaseId ? { type: "decision", id, vector, timestampMs, phaseId, environment } : { type: "decision", id, vector, timestampMs, environment };
|
|
2006
|
+
}
|
|
2007
|
+
// A module carries the key of its table of ids, which the manifest holds, and
|
|
2008
|
+
// how many points and decisions it numbers: evidence names a probe by the key
|
|
2009
|
+
// and its place, `~p<key>.<place>` or `~d<key>.<place>`, and the report reads
|
|
2010
|
+
// the id there. A place whose id an earlier place has is named as that one,
|
|
2011
|
+
// as it was one id: a selection's two short outcomes are one point.
|
|
2012
|
+
function probeAliases(flat) {
|
|
2013
|
+
const aliases = /* @__PURE__ */ new Map();
|
|
2014
|
+
for (let index = 0; flat && index + 1 < flat.length; index += 2)
|
|
2015
|
+
aliases.set(flat[index], flat[index + 1]);
|
|
2016
|
+
return aliases;
|
|
2017
|
+
}
|
|
2018
|
+
function probePlaceName(names, aliases, count, kind, key, place) {
|
|
2019
|
+
if (!(place >= 0 && place < count))
|
|
2020
|
+
return void 0;
|
|
2021
|
+
let name = names[place];
|
|
2022
|
+
if (name === void 0) {
|
|
2023
|
+
const first = aliases.get(place);
|
|
2024
|
+
name = names[place] = first === void 0 ? `~${kind}${key}.${place}` : probePlaceName(names, aliases, count, kind, key, first);
|
|
1815
2025
|
}
|
|
2026
|
+
return name;
|
|
2027
|
+
}
|
|
2028
|
+
function probePointName(file, place) {
|
|
2029
|
+
return probePlaceName(file.pointNames, file.pointAliases, file.pointCount, "p", file.key, place);
|
|
2030
|
+
}
|
|
2031
|
+
function probeDecisionName(file, place) {
|
|
2032
|
+
return probePlaceName(file.decisionNames, file.decisionAliases, file.decisionWidths.length, "d", file.key, place);
|
|
1816
2033
|
}
|
|
1817
2034
|
function registerProbeV2(definition) {
|
|
1818
2035
|
var _a8, _b;
|
|
2036
|
+
const pointCount = definition.points;
|
|
2037
|
+
const decisionCount = definition.decisionWidths.length;
|
|
1819
2038
|
const file = {
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
2039
|
+
key: definition.key,
|
|
2040
|
+
pointCount,
|
|
2041
|
+
pointNames: [],
|
|
2042
|
+
pointAliases: probeAliases(definition.pointAliases),
|
|
2043
|
+
decisionNames: [],
|
|
2044
|
+
decisionAliases: probeAliases(definition.decisionAliases),
|
|
1823
2045
|
decisionWidths: definition.decisionWidths,
|
|
1824
|
-
pointIds: definition.pointIds,
|
|
1825
2046
|
clock: state.probeV2Clock,
|
|
1826
|
-
hitEpochs: new Uint32Array(
|
|
2047
|
+
hitEpochs: new Uint32Array(pointCount),
|
|
2048
|
+
// A narrow decision's vectors in an array, a wide one's in a Map, told
|
|
2049
|
+
// apart by `size`, which only the Map has: `instanceof Uint32Array` read
|
|
2050
|
+
// the global on every evaluation, and under Vitest's jsdom environment
|
|
2051
|
+
// each read is a getter call, most of a canvas app's measured unit time.
|
|
1827
2052
|
decisionEpochs: definition.decisionWidths.map((width) => width <= 6 ? new Uint32Array(2 * 3 ** width) : /* @__PURE__ */ new Map()),
|
|
1828
|
-
decisionVectorCounts: definition.
|
|
2053
|
+
decisionVectorCounts: definition.decisionWidths.map((_, index) => {
|
|
1829
2054
|
var _a9, _b2;
|
|
1830
2055
|
return (_b2 = (_a9 = definition.decisionVectorCounts) == null ? void 0 : _a9[index]) != null ? _b2 : 0;
|
|
1831
2056
|
}),
|
|
1832
|
-
decisionObservationEpochs: new Uint32Array(
|
|
1833
|
-
decisionObservationCounts: new Uint16Array(
|
|
1834
|
-
decisionCompleteEpochs: new Uint32Array(
|
|
2057
|
+
decisionObservationEpochs: new Uint32Array(decisionCount),
|
|
2058
|
+
decisionObservationCounts: new Uint16Array(decisionCount),
|
|
2059
|
+
decisionCompleteEpochs: new Uint32Array(decisionCount),
|
|
1835
2060
|
pendingDefaults: new Uint32Array(definition.defaultCount || 0),
|
|
1836
2061
|
// A selection's outcomes -- short falsy, short truthy, right falsy, right
|
|
1837
2062
|
// truthy -- are four consecutive points per site from the first index.
|
|
@@ -1869,13 +2094,15 @@ function coverageHitV2(file, index) {
|
|
|
1869
2094
|
recordCoverageHitV2(file, index);
|
|
1870
2095
|
}
|
|
1871
2096
|
function recordCoverageHitV2(file, index) {
|
|
1872
|
-
const id = file
|
|
2097
|
+
const id = probePointName(file, index);
|
|
1873
2098
|
if (!id)
|
|
1874
2099
|
return;
|
|
1875
2100
|
const fallbackEpoch = !file.clock.fast;
|
|
1876
2101
|
const previousEpoch = file.clock.epoch;
|
|
1877
2102
|
if (fallbackEpoch)
|
|
1878
2103
|
activateProbeV2Context(currentRequestContext());
|
|
2104
|
+
else if (previousEpoch !== previousEpoch)
|
|
2105
|
+
resolveProbeV2Epoch();
|
|
1879
2106
|
try {
|
|
1880
2107
|
const epoch = file.clock.epoch;
|
|
1881
2108
|
if (file.hitEpochs[index] === epoch)
|
|
@@ -1884,7 +2111,7 @@ function recordCoverageHitV2(file, index) {
|
|
|
1884
2111
|
coverageHit(id);
|
|
1885
2112
|
const selections = file.selectionPoints;
|
|
1886
2113
|
if (selections !== void 0 && index >= selections[0] && index < selections[0] + 4 * selections[1])
|
|
1887
|
-
|
|
2114
|
+
recordLogicalOutcome(id, index - selections[0] & 3);
|
|
1888
2115
|
} finally {
|
|
1889
2116
|
if (fallbackEpoch)
|
|
1890
2117
|
file.clock.epoch = previousEpoch;
|
|
@@ -1910,14 +2137,14 @@ function mcdcEndV2(file, decisionIndex, encoded, value) {
|
|
|
1910
2137
|
const clock = file.clock;
|
|
1911
2138
|
if (clock.fast) {
|
|
1912
2139
|
const seen = file.decisionEpochs[decisionIndex];
|
|
1913
|
-
if (seen
|
|
2140
|
+
if (seen !== void 0 && seen.size === void 0 && seen[encoded * 2 + (value ? 1 : 0)] === clock.epoch)
|
|
1914
2141
|
return value;
|
|
1915
2142
|
}
|
|
1916
2143
|
return recordMcdcEndV2(file, decisionIndex, encoded, value);
|
|
1917
2144
|
}
|
|
1918
2145
|
function recordMcdcEndV2(file, decisionIndex, encoded, value) {
|
|
1919
2146
|
var _a8, _b;
|
|
1920
|
-
const id = file
|
|
2147
|
+
const id = probeDecisionName(file, decisionIndex);
|
|
1921
2148
|
if (!id || !Number.isSafeInteger(encoded) || encoded < 0)
|
|
1922
2149
|
return value;
|
|
1923
2150
|
const outcome = Boolean(value);
|
|
@@ -1928,12 +2155,14 @@ function recordMcdcEndV2(file, decisionIndex, encoded, value) {
|
|
|
1928
2155
|
const previousEpoch = file.clock.epoch;
|
|
1929
2156
|
if (fallbackEpoch)
|
|
1930
2157
|
activateProbeV2Context(currentRequestContext());
|
|
2158
|
+
else if (previousEpoch !== previousEpoch)
|
|
2159
|
+
resolveProbeV2Epoch();
|
|
1931
2160
|
try {
|
|
1932
2161
|
const epoch = file.clock.epoch;
|
|
1933
2162
|
const seen = file.decisionEpochs[decisionIndex];
|
|
1934
2163
|
if (!seen)
|
|
1935
2164
|
return value;
|
|
1936
|
-
if (seen
|
|
2165
|
+
if (seen.size === void 0) {
|
|
1937
2166
|
if (seen[vectorIndex] === epoch)
|
|
1938
2167
|
return value;
|
|
1939
2168
|
seen[vectorIndex] = epoch;
|
|
@@ -2007,8 +2236,12 @@ function recordSelectionOutcome(id, outcome) {
|
|
|
2007
2236
|
branchId = separator > 0 ? id.slice(0, separator) : null;
|
|
2008
2237
|
selectionBranchIds.set(id, branchId);
|
|
2009
2238
|
}
|
|
2010
|
-
if (branchId
|
|
2011
|
-
|
|
2239
|
+
if (branchId !== null)
|
|
2240
|
+
recordLogicalOutcome(branchId, outcome);
|
|
2241
|
+
}
|
|
2242
|
+
// The outcomes of a selection by its branch id, or by the name of its point
|
|
2243
|
+
// that was hit, whose branch the report reads from the point's id.
|
|
2244
|
+
function recordLogicalOutcome(branchId, outcome) {
|
|
2012
2245
|
let vectors = state.logicals.get(branchId);
|
|
2013
2246
|
if (!vectors) {
|
|
2014
2247
|
vectors = /* @__PURE__ */ new Map();
|
|
@@ -2266,22 +2499,10 @@ function mcdcEnd(frame, value) {
|
|
|
2266
2499
|
const timestampMs = Date.now();
|
|
2267
2500
|
const phaseId = currentPhaseId();
|
|
2268
2501
|
if (isBrowser) {
|
|
2269
|
-
if (recordBrowserEvent(
|
|
2270
|
-
type: "decision",
|
|
2271
|
-
id: decision.id,
|
|
2272
|
-
vector,
|
|
2273
|
-
timestampMs
|
|
2274
|
-
}, phaseId ? { phaseId } : {}), {
|
|
2275
|
-
environment: "browser"
|
|
2276
|
-
})))
|
|
2502
|
+
if (recordBrowserEvent(decisionEvent(decision.id, vector, timestampMs, phaseId, "browser")))
|
|
2277
2503
|
persistBrowser();
|
|
2278
2504
|
} else {
|
|
2279
|
-
appendServer(
|
|
2280
|
-
type: "decision",
|
|
2281
|
-
id: decision.id,
|
|
2282
|
-
vector,
|
|
2283
|
-
timestampMs
|
|
2284
|
-
}, phaseId ? { phaseId } : {}));
|
|
2505
|
+
appendServer(phaseId ? { type: "decision", id: decision.id, vector, timestampMs, phaseId } : { type: "decision", id: decision.id, vector, timestampMs });
|
|
2285
2506
|
}
|
|
2286
2507
|
return value;
|
|
2287
2508
|
}
|