supercov 4.27.0 → 4.29.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.
Files changed (32) hide show
  1. package/README.md +43 -16
  2. package/docs/cli.md +358 -9
  3. package/docs/getting-started.md +18 -0
  4. package/docs/mutation.md +539 -0
  5. package/docs/supported-suites.md +109 -60
  6. package/package.json +11 -10
  7. package/runtime/javascript/atomic.mjs +6 -2
  8. package/runtime/javascript/ava.mjs +12 -0
  9. package/runtime/javascript/bunTest.mjs +17 -0
  10. package/runtime/javascript/jest.cjs +67 -0
  11. package/runtime/javascript/jest.config.mjs +46 -6
  12. package/runtime/javascript/jestReporter.mjs +5 -2
  13. package/runtime/javascript/mocha.mjs +79 -5
  14. package/runtime/javascript/nodeTest.mjs +28 -0
  15. package/runtime/javascript/playwright.mjs +33 -0
  16. package/runtime/javascript/playwrightStrong.mjs +477 -0
  17. package/runtime/javascript/playwrightStrongReporter.mjs +377 -0
  18. package/runtime/javascript/runnerEntry.mjs +62 -0
  19. package/runtime/javascript/runtime.mjs +752 -13
  20. package/runtime/javascript/snapshots.mjs +16 -1
  21. package/runtime/javascript/strongJestHost.mjs +103 -0
  22. package/runtime/javascript/strongJob.mjs +78 -0
  23. package/runtime/javascript/strongJobs.mjs +809 -0
  24. package/runtime/javascript/strongMochaHost.mjs +166 -0
  25. package/runtime/javascript/strongWasmOut.cjs +96 -0
  26. package/runtime/javascript/tap.mjs +43 -1
  27. package/runtime/javascript/transport.mjs +5 -0
  28. package/runtime/javascript/vitest.mjs +74 -2
  29. package/runtime/javascript/vitestBrowser.mjs +34 -2
  30. package/runtime/javascript/vitestStrong.mjs +234 -0
  31. package/runtime/javascript/vitestStrongReporter.mjs +2268 -0
  32. package/runtime/javascript/vitestStrongSpawner.mjs +248 -0
@@ -37,6 +37,9 @@ export function mergeSnapshots(snapshots) {
37
37
  const events = new Map();
38
38
  const decisions = new Map();
39
39
  const logicals = new Map();
40
+ // What each comparison and infection probe saw: a page's probes run in
41
+ // the browser, and a merge that left them out lost every outcome there.
42
+ const comparisons = new Map();
40
43
  const vectorsOf = (map, key, initial) => {
41
44
  let entry = map.get(key);
42
45
  if (!entry) {
@@ -73,13 +76,25 @@ export function mergeSnapshots(snapshots) {
73
76
  for (const vector of logical.vectors ?? [])
74
77
  entry.seen.set(JSON.stringify(vector), vector);
75
78
  }
79
+ for (const comparison of snapshot?.comparisons ?? []) {
80
+ let outcomes = comparisons.get(comparison.id);
81
+ if (!outcomes) {
82
+ outcomes = new Set();
83
+ comparisons.set(comparison.id, outcomes);
84
+ }
85
+ for (const outcome of comparison.outcomes ?? [])
86
+ outcomes.add(outcome);
87
+ }
76
88
  }
77
- return {
89
+ const merged = {
78
90
  decisions: [...decisions.values()].map(({ seen, id }) => ({ id, vectors: [...seen.values()] })),
79
91
  hits: [...hits],
80
92
  events: [...events.values()],
81
93
  logicals: [...logicals.values()].map(({ seen, id }) => ({ id, vectors: [...seen.values()] })),
82
94
  };
95
+ if (comparisons.size)
96
+ merged.comparisons = [...comparisons].map(([id, outcomes]) => ({ id, outcomes: [...outcomes] }));
97
+ return merged;
83
98
  }
84
99
  /**
85
100
  * A snapshot as JSON.parse would give it from the text a page's runtime
@@ -0,0 +1,103 @@
1
+ // A resident Jest for a strong pass's jobs (strongJobs.mjs): one process that
2
+ // keeps Jest loaded, as StrykerJS's Jest runner does, and runs one job after
3
+ // another in band, each test file in the fresh module registry and
4
+ // environment Jest gives every test file. The job's mutant is switched on
5
+ // here before Jest loads the file's modules; its tests and outcomes go
6
+ // through the Jest adapter as in a job started from the command.
7
+ //
8
+ // The driver forks it in the project's copy and sends
9
+ // { type: "init", args: [<the command's arguments to jest>] }
10
+ // { type: "job", id, file: <absolute test file>, mutant: { file, index } | null, environment: {...} }
11
+ // and it answers { type: "ready" } and { type: "done", id, error? }.
12
+ import { createRequire } from "node:module";
13
+ import { join, resolve } from "node:path";
14
+ import { fileURLToPath } from "node:url";
15
+
16
+ globalThis.__SUPERCOV_DIRECT_RUNTIME__ ??= await import("./runtime.mjs");
17
+ process.__SUPERCOV_DIRECT_RUNTIME__ ??= globalThis.__SUPERCOV_DIRECT_RUNTIME__;
18
+ const runtime = globalThis.__SUPERCOV_DIRECT_RUNTIME__;
19
+ const generatedConfig = fileURLToPath(new URL("./jest.config.mjs", import.meta.url));
20
+
21
+ // The project's Jest: its CLI's argument parser and its core.
22
+ function projectJest(root) {
23
+ const fromRoot = createRequire(join(root, "package.json"));
24
+ let cli;
25
+ try {
26
+ cli = fromRoot.resolve("jest-cli");
27
+ }
28
+ catch {
29
+ cli = createRequire(fromRoot.resolve("jest/package.json")).resolve("jest-cli");
30
+ }
31
+ const { buildArgv } = createRequire(cli)("jest-cli");
32
+ const { runCLI } = createRequire(cli)("@jest/core");
33
+ return { buildArgv, runCLI };
34
+ }
35
+
36
+ let jest;
37
+ let base;
38
+ let config;
39
+ const root = process.cwd();
40
+ const reporter = fileURLToPath(new URL("./jestReporter.mjs", import.meta.url));
41
+
42
+ // Whether a configuration survives being written as JSON: only then is it
43
+ // handed to Jest as JSON, as StrykerJS's runner hands it.
44
+ function plain(value) {
45
+ if (value === null || ["string", "number", "boolean"].includes(typeof value))
46
+ return true;
47
+ if (Array.isArray(value))
48
+ return value.every(plain);
49
+ if (typeof value === "object" && Object.getPrototypeOf(value) === Object.prototype)
50
+ return Object.values(value).every((item) => item === undefined || plain(item));
51
+ return false;
52
+ }
53
+
54
+ async function init(args) {
55
+ jest = projectJest(root);
56
+ base = await jest.buildArgv(args);
57
+ // The project's own configuration, read by Supercov's (jest.config.mjs).
58
+ if (base.config && resolve(String(base.config)) !== generatedConfig)
59
+ process.env.SUPERCOV_ORIGINAL_JEST_CONFIG = resolve(String(base.config));
60
+ // Read once, not for every job (no job is under way, so it leaves no
61
+ // test file out: a job names its one file by its path). A job's outcome
62
+ // is Supercov's reporter's alone: the project's reporters (a terminal's,
63
+ // a JUnit file's) and its console have no reader here.
64
+ const { default: read } = await import(generatedConfig);
65
+ const resolved = { ...(await read()), reporters: [reporter] };
66
+ config = plain(resolved) ? JSON.stringify(resolved) : generatedConfig;
67
+ }
68
+
69
+ async function runJob({ file, mutant, environment }) {
70
+ Object.assign(process.env, environment);
71
+ if (mutant)
72
+ runtime.setActiveMutant(mutant.file, mutant.index);
73
+ else
74
+ runtime.clearActiveMutant();
75
+ try {
76
+ const argv = {
77
+ ...base,
78
+ _: [file],
79
+ config,
80
+ runTestsByPath: true,
81
+ runInBand: true,
82
+ silent: true,
83
+ watch: false,
84
+ watchAll: false,
85
+ };
86
+ await jest.runCLI(argv, Array.isArray(base.projects) && base.projects.length ? base.projects : [root]);
87
+ }
88
+ finally {
89
+ runtime.clearActiveMutant();
90
+ }
91
+ }
92
+
93
+ process.on("message", (message) => {
94
+ const reply = (answer) => process.send?.(answer);
95
+ if (message?.type === "init") {
96
+ init(message.args).then(() => reply({ type: "ready" }), (error) => reply({ type: "ready", error: String(error?.stack ?? error) }));
97
+ return;
98
+ }
99
+ if (message?.type === "job") {
100
+ runJob(message).then(() => reply({ type: "done", id: message.id }), (error) => reply({ type: "done", id: message.id, error: String(error?.stack ?? error) }));
101
+ }
102
+ });
103
+ process.send?.({ type: "started" });
@@ -0,0 +1,78 @@
1
+ // One job of a strong pass run by the command itself (strongJobs.mjs): which
2
+ // test files and tests this process of the runner runs, and whether it stops
3
+ // at the first failure. The adapters ask it as a file loads and as each test
4
+ // is registered or starts; outside a strong pass there is no job and every
5
+ // test runs as written.
6
+ //
7
+ // SUPERCOV_STRONG_JOB names a JSON file:
8
+ // { "files": { "<test file>": ["<test id>", ...] | null }, "known": [...],
9
+ // "bail": true }
10
+ // A file in `files` runs its listed tests, or every test where the list is
11
+ // null. A file in `known` (every test file of the measured run) and not in
12
+ // `files` runs none. Any other file -- a helper the runner loads as a test
13
+ // file, a file the measured run did not have -- runs as written.
14
+ import { readFileSync } from "node:fs";
15
+ import { relative, sep } from "node:path";
16
+ import { fileURLToPath } from "node:url";
17
+
18
+ const jobKey = Symbol.for("supercov.strongJob");
19
+
20
+ function localFile(file) {
21
+ if (!file)
22
+ return undefined;
23
+ const absolute = String(file).startsWith("file:") ? fileURLToPath(file) : String(file);
24
+ return relative(process.cwd(), absolute).split(sep).join("/");
25
+ }
26
+
27
+ function read() {
28
+ const path = typeof process !== "undefined" ? process.env?.SUPERCOV_STRONG_JOB : undefined;
29
+ if (!path)
30
+ return null;
31
+ let spec;
32
+ try {
33
+ spec = JSON.parse(readFileSync(path, "utf8"));
34
+ }
35
+ catch {
36
+ return null;
37
+ }
38
+ const files = new Map(Object.entries(spec.files ?? {}).map(([file, tests]) => [file, tests === null ? null : new Set(tests)]));
39
+ const known = new Set(spec.known ?? []);
40
+ let failed = false;
41
+ return {
42
+ bail: spec.bail === true,
43
+ // Whether the runner should load this test file at all.
44
+ runsFile(file) {
45
+ const local = localFile(file);
46
+ return local === undefined || files.has(local) || !known.has(local);
47
+ },
48
+ // Whether this test of this file runs.
49
+ selects(file, testId) {
50
+ const local = localFile(file);
51
+ if (local === undefined)
52
+ return true;
53
+ if (!files.has(local))
54
+ return !known.has(local);
55
+ const tests = files.get(local);
56
+ return tests === null || tests.has(testId);
57
+ },
58
+ // A test failed: with `bail`, every later test is skipped.
59
+ fail() {
60
+ failed = true;
61
+ },
62
+ get stopped() {
63
+ return this.bail && failed;
64
+ },
65
+ };
66
+ }
67
+
68
+ /** The process's job, or null outside a strong pass's job. */
69
+ export function strongJob() {
70
+ // One job per process at a time, whichever copy of this module asks: a
71
+ // resident runner (strongMochaHost.mjs) names the next job's file in
72
+ // SUPERCOV_STRONG_JOB, and the job is read again.
73
+ const path = typeof process !== "undefined" ? process.env?.SUPERCOV_STRONG_JOB : undefined;
74
+ const cached = globalThis[jobKey];
75
+ if (cached === undefined || cached.path !== path)
76
+ Object.defineProperty(globalThis, jobKey, { value: { path, job: read() }, configurable: true, writable: true });
77
+ return globalThis[jobKey].job;
78
+ }