supercov 4.29.19 → 4.30.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.
@@ -12,7 +12,7 @@
12
12
  import { appendFileSync, existsSync, readFileSync, realpathSync, statSync } from "node:fs";
13
13
  import { dirname, join } from "node:path";
14
14
  import { pathToFileURL } from "node:url";
15
- import { attemptPath, baselineOf, entries, invocation, EVERYWHERE, firstWords, giveVerdict, key, loadPass, outcomeOf, placeOf, queuedWork, ranByRequests, readJson, reasonOf, serialFile, settleAttempt, strongPass, unreached, verdictOf, withoutCopy, writeJson } from "./playwrightStrong.mjs";
15
+ import { attemptPath, baselineOf, entries, invocation, EVERYWHERE, firstWords, stripAnsi, giveVerdict, key, loadPass, outcomeOf, placeOf, queuedWork, ranByRequests, readJson, reasonOf, serialFile, settleAttempt, strongPass, unreached, verdictOf, withoutCopy, writeJson } from "./playwrightStrong.mjs";
16
16
 
17
17
  // How often, at most, the status file is written.
18
18
  const STATUS_MS = 1_000;
@@ -114,16 +114,42 @@ export default class SupercovPlaywrightStrongReporter {
114
114
  this.timer = setInterval(() => this.writeStatus(true), 5_000);
115
115
  this.timer.unref?.();
116
116
  }
117
+ // What a web server or a global setup prints, outside any test, goes to
118
+ // the reporters: this one stands in for the project's, which would
119
+ // have printed it (Playwright's own prefix it, `[WebServer] `), so it
120
+ // passes it on. A build the server's command runs says why it failed
121
+ // there and nowhere else. What a test prints stays its own.
122
+ onStdOut(chunk, test) {
123
+ if (!test)
124
+ process.stdout.write(chunk);
125
+ }
126
+ onStdErr(chunk, test) {
127
+ if (!test)
128
+ process.stderr.write(chunk);
129
+ }
117
130
  onTestBegin(test) {
118
131
  if (!this.pass)
119
132
  return;
133
+ // A test began, so the command started: where no process of it has
134
+ // a mutant on everywhere (any round but one alone), it starts
135
+ // without one, which an alone round's failure is judged against.
136
+ if (!this.begun && this.work?.kind !== "alone")
137
+ markStartedWithoutMutant(this.pass);
138
+ this.begun = true;
120
139
  this.running.set(test.id, { title: test.title, begunAt: Date.now() });
121
140
  this.writeStatus(false);
122
141
  }
123
142
  onError(error) {
124
143
  // Outside any test: a web server that exited, a global setup that
125
- // threw. Each invocation's first one's time and words.
126
- if (!this.pass || this.erred)
144
+ // threw. Said on the command's output, every one, whole: this
145
+ // reporter stands in for the project's, which would have printed
146
+ // it, and the judge's record below keeps only the first one's words.
147
+ if (!this.pass)
148
+ return;
149
+ const text = stripAnsi(String(error?.stack ?? error?.message ?? error));
150
+ console.error(`[supercov] the command reported an error outside any test: ${text}`);
151
+ // Each invocation's first one's time and words, for the judge.
152
+ if (this.erred)
127
153
  return;
128
154
  this.erred = true;
129
155
  writeJson(`${this.pass.round}/errors/${process.pid}.json`, { pid: process.pid, at: Date.now(), message: firstWords(error?.message ?? error) });
@@ -266,6 +292,11 @@ export default class SupercovPlaywrightStrongReporter {
266
292
  clearInterval(this.timer);
267
293
  this.running.clear();
268
294
  this.writeStatus(true);
295
+ // A command that failed before any test began (a web server that
296
+ // would not start, a global setup that threw) failed: it says so by
297
+ // its exit code, and Supercov shows and keeps its output.
298
+ if (this.erred && !this.begun)
299
+ return undefined;
269
300
  // A killed mutant fails a test, and that is the point: the command's
270
301
  // outcome is the pass's, not the tests'. The verdicts are the
271
302
  // judge's, once every invocation has ended.
@@ -425,8 +456,16 @@ export default class SupercovPlaywrightStrongReporter {
425
456
  // the whole command started with it, which says whether it was the
426
457
  // mutant's doing.) An error after the round began to stop is the
427
458
  // stop's: its servers went down under it.
459
+ // That is the mutant's doing only where the command starts without
460
+ // it: some round of this pass began a test with no mutant on
461
+ // everywhere. Where none did, the command fails without any
462
+ // mutant too (a build of the pass's copy that fails), and the
463
+ // failure says nothing of this one: no verdict.
428
464
  if (kind === "alone" && !work.batch && globalError && globalError.at < stoppedAt && !ended.length) {
429
- verdict({ status: "killed", reason: `the command failed with it switched on (${globalError.message})${suffix}` });
465
+ if (startedWithoutMutant(pass))
466
+ verdict({ status: "killed", reason: `the command failed with it switched on (${globalError.message})${suffix}` });
467
+ else
468
+ verdict({ status: "error", reason: `the command failed with it switched on (${globalError.message}), and no run of it in this pass got as far as a test without a mutant${suffix}` });
430
469
  continue;
431
470
  }
432
471
  // Its invocation's server never ran it: alone, the whole command
@@ -572,6 +611,21 @@ export default class SupercovPlaywrightStrongReporter {
572
611
  }
573
612
  }
574
613
 
614
+ // Whether some round of the pass began a test in a command with no mutant
615
+ // on everywhere: the command starts without one.
616
+ function markStartedWithoutMutant(pass) {
617
+ try {
618
+ writeJson(`${pass.shared}/started-without-mutant`, Date.now());
619
+ }
620
+ catch {
621
+ // Unmarked, an alone round's failure decides nothing.
622
+ }
623
+ }
624
+
625
+ function startedWithoutMutant(pass) {
626
+ return existsSync(`${pass.shared}/started-without-mutant`);
627
+ }
628
+
575
629
  /** A round as its first line says it. */
576
630
  function describeRound(work) {
577
631
  if (work.kind === "main")
@@ -10,6 +10,7 @@ import Module, { register, syncBuiltinESMExports } from "node:module";
10
10
  import fs, { closeSync, openSync, readFileSync, realpathSync, unlinkSync } from "node:fs";
11
11
  import path, { basename, dirname, isAbsolute, relative, resolve, sep } from "node:path";
12
12
  import { fileURLToPath } from "node:url";
13
+ import { isMainThread } from "node:worker_threads";
13
14
  import { installLaunchSupervisor, wrapImportedCapability } from "./launchSupervisor.mjs";
14
15
  import { __supercovBindCapabilityWrapper } from "./capability.mjs";
15
16
  import { adaptRunnerEntry, noteSkippedCoverageThresholds } from "./runnerEntry.mjs";
@@ -41,7 +42,15 @@ const isNpmItself = (() => {
41
42
  return false;
42
43
  }
43
44
  })();
44
- if (!isNpmItself)
45
+ // Nor in a worker thread. Node writes a thread's compiled code as the
46
+ // thread ends, a temporary file and a rename for each module it compiled, and
47
+ // a runner waits for its worker to end: AVA stops a file whose worker sends
48
+ // nothing for 10 s ("Timed out while running tests", "Failed to exit"). On a
49
+ // disk busy with other writes, each rename took 0.2 s, and the two workers
50
+ // of a two-file suite spent most of a minute ending: 20 of 24 runs failed
51
+ // where AVA alone passed. A worker thread compiles as it would without
52
+ // Supercov; a process keeps the cache.
53
+ if (!isNpmItself && isMainThread)
45
54
  enableNodeCompileCache(process.env.SUPERCOV_COMPILE_CACHE);
46
55
  installLaunchSupervisor();
47
56
  // Playwright's compile cache, written whole (atomic.mjs says why).
@@ -0,0 +1,103 @@
1
+ // A resident AVA for a strong pass's jobs (strongJobs.mjs): one process that
2
+ // keeps AVA's command loaded, its configuration read and its options worked
3
+ // out, and runs one job after another, where each job started the command.
4
+ //
5
+ // AVA runs every test file in a worker of its own (a worker thread, or a
6
+ // child process under --no-worker-threads), made for the file as the run
7
+ // starts and given the main process's environment as it is then, so each
8
+ // job's file and the code it tests load afresh, with the job's mutant on
9
+ // from the worker's start, as in a command of its own. This process loads
10
+ // none of the project's code: the command's main process does not either. Between runs the main
11
+ // process keeps only what AVA's own watch mode keeps between its reruns:
12
+ // its options and its cache directory.
13
+ //
14
+ // The options are AVA's command's own: the host runs AVA's command
15
+ // (`lib/cli.js`) with the command's arguments and takes the Api it makes as
16
+ // it would start its first run. It refuses (the driver starts the command
17
+ // for each job, as before) where the command watches or debugs, or where
18
+ // AVA's command ends instead (a configuration it rejects).
19
+ //
20
+ // The driver forks it in the project's copy and sends
21
+ // { type: "init", args: [<the command's arguments to ava>] }
22
+ // { type: "job", id, file: <absolute test file>, mutant: { file, index } | null, environment: {...} }
23
+ // and it answers { type: "ready", error? } and { type: "done", id, error?, tainted? }:
24
+ // `tainted` that this process runs no further job.
25
+ import { realpathSync } from "node:fs";
26
+ import { createRequire, syncBuiltinESMExports } from "node:module";
27
+ import { join } from "node:path";
28
+ import { pathToFileURL } from "node:url";
29
+ import threads from "node:worker_threads";
30
+
31
+ const root = process.cwd();
32
+ // A shared worker (AVA's plugin API) lives as long as the main process: in a
33
+ // command, one job's; here, every later job's too. A job that starts one
34
+ // is the host's last.
35
+ let sharedWorker = false;
36
+ {
37
+ const { Worker } = threads;
38
+ threads.Worker = class extends Worker {
39
+ constructor(file, ...rest) {
40
+ if (/shared-worker-loader/.test(String(file)))
41
+ sharedWorker = true;
42
+ super(file, ...rest);
43
+ }
44
+ };
45
+ syncBuiltinESMExports();
46
+ }
47
+ let api;
48
+ let run;
49
+ let runOptions;
50
+
51
+ async function init(args) {
52
+ if (args.some((argument) => /^(?:-w|--watch|debug|reset-cache)$/.test(argument)))
53
+ throw new Error("the command watches, debugs or resets AVA's cache");
54
+ process.env.SUPERCOV_STRONG_PLAN = "";
55
+ process.env.SUPERCOV_ACTIVE_MUTANT = "-";
56
+ // The installed package, by its real path: AVA's command loads its Api
57
+ // from there, and only that module's Api is the one it makes.
58
+ const main = realpathSync(createRequire(join(root, "package.json")).resolve("ava"));
59
+ const at = main.replaceAll("\\", "/").lastIndexOf("/node_modules/ava/");
60
+ if (at < 0)
61
+ throw new Error(`AVA is not where a package is: ${main}`);
62
+ const avaRoot = main.slice(0, at + "/node_modules/ava".length);
63
+ const load = async (name) => import(pathToFileURL(join(avaRoot, "lib", name)).href);
64
+ const { default: Api } = await load("api.js");
65
+ run = Api.prototype.run;
66
+ // AVA's command makes its Api from the command line and the project's
67
+ // configuration, and starts its run: the run is taken here instead, with
68
+ // what the command asked of it (its files, its line numbers).
69
+ const made = new Promise((resolveMade) => {
70
+ Api.prototype.run = function capture(options) {
71
+ resolveMade({ api: this, options });
72
+ return new Promise(() => { });
73
+ };
74
+ });
75
+ process.argv = [process.execPath, join(avaRoot, "entrypoints", "cli.mjs"), ...args];
76
+ const { default: loadCli } = await load("cli.js");
77
+ const exited = loadCli().then(() => {
78
+ throw new Error("AVA's command ended without starting a run");
79
+ });
80
+ ({ api, options: runOptions } = await Promise.race([made, exited]));
81
+ Api.prototype.run = run;
82
+ }
83
+
84
+ // A job runs what the command runs, as the command's own run would: every
85
+ // test file in a worker of its own, where the adapter runs only the job's
86
+ // tests (strongJob.mjs). The workers take the environment as it is when the
87
+ // run makes them.
88
+ async function runJob({ environment, mutant }) {
89
+ Object.assign(process.env, environment, { SUPERCOV_ACTIVE_MUTANT: mutant ? `${mutant.file}#${mutant.index}` : "-" });
90
+ await run.call(api, runOptions);
91
+ return sharedWorker ? { tainted: true } : {};
92
+ }
93
+
94
+ process.on("message", (message) => {
95
+ const reply = (answer) => process.send?.(answer);
96
+ if (message?.type === "init") {
97
+ init(message.args ?? []).then(() => reply({ type: "ready" }), (error) => reply({ type: "ready", error: String(error?.stack ?? error) }));
98
+ return;
99
+ }
100
+ if (message?.type === "job")
101
+ runJob(message).then((outcome) => reply({ type: "done", id: message.id, ...outcome }), (error) => reply({ type: "done", id: message.id, error: String(error?.stack ?? error), tainted: true }));
102
+ });
103
+ process.send?.({ type: "started" });