@ingenioz-it/caits 0.5.0 → 0.5.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/bin/caits.js CHANGED
@@ -23,6 +23,8 @@ const USAGE = `Usage: caits <command>
23
23
  check <script>… Runs the npm scripts of the checks at once. Shows the output of the checks that fail, and only theirs.
24
24
  architecture Checks the rules of quality/architecture.mjs.
25
25
  e2e Runs the end-to-end tests on the production build.
26
+ mutation Runs the mutation tests (Stryker), then gives the score of each file and the mutants that survived. Its exit
27
+ code is that of Stryker.
26
28
  mutation-summary Gives the mutation score of each file (--survivors: the mutants that survived).
27
29
  mutation-suite The unit tests, as Stryker runs them for each mutant.
28
30
 
@@ -30,7 +32,7 @@ const USAGE = `Usage: caits <command>
30
32
  --version Shows the version of CAITS.`;
31
33
 
32
34
  /** The commands that run a tool of quality/: their code is in the folder quality/ of CAITS. */
33
- const TOOLS = new Set(["dev", "check", "architecture", "e2e", "mutation-summary", "mutation-suite"]);
35
+ const TOOLS = new Set(["dev", "check", "architecture", "e2e", "mutation", "mutation-summary", "mutation-suite"]);
34
36
 
35
37
  /** The options of `caits init`. */
36
38
  const INIT_OPTIONS = /** @type {const} */ ({ caits: { type: "string" }, example: { type: "boolean" }, "example-source": { type: "string" }, "no-install": { type: "boolean" } });
package/bin/init.js CHANGED
@@ -99,7 +99,7 @@ const PACKAGE = {
99
99
  "test:integration": "vitest run --config quality/vite.config.ts .integration.test.ts",
100
100
  "test:e2e": "caits e2e",
101
101
  "test:coverage": "vitest run --config quality/vite.config.ts --coverage --reporter=default --reporter=@ingenioz-it/caits/quality/test-docs/vitest-reporter",
102
- "test:mutation": "stryker run quality/stryker.config.mjs && caits mutation-summary",
102
+ "test:mutation": "caits mutation",
103
103
  tdd: "vitest --config quality/vite.config.ts",
104
104
  check: "caits check typecheck lint:code lint:architecture test:coverage test:mutation test:e2e"
105
105
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ingenioz-it/caits",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "CAITS (Clean Architecture In TypeScript): the technical base of a Marko project with a backend and a frontend.",
5
5
  "keywords": [
6
6
  "clean-architecture",
@@ -2,7 +2,7 @@
2
2
  import { existsSync, readFileSync } from "node:fs";
3
3
 
4
4
  /** The report that Stryker writes in JSON (quality/caits/stryker.mjs). */
5
- const REPORT = "reports/mutation/mutation.json";
5
+ export const REPORT = "reports/mutation/mutation.json";
6
6
 
7
7
  /** @typedef {{ status: string; mutatorName: string; replacement?: string; location: { start: { line: number } } }} Mutant */
8
8
 
@@ -0,0 +1,30 @@
1
+ // `caits mutation`: the mutation tests (Stryker, with quality/stryker.config.mjs), then the score of each file and the mutants that
2
+ // survived, whether Stryker passed or not. Stryker alone ends with its threshold when the score is too low: the survivors say what to fix.
3
+ import { spawn } from "node:child_process";
4
+ import { existsSync, rmSync } from "node:fs";
5
+ import { REPORT, run as summary } from "./mutation-summary.mjs";
6
+
7
+ /** The configuration of Stryker in a project: it imports the defaults of CAITS (quality/caits/stryker.mjs). */
8
+ export const STRYKER_CONFIG = "quality/stryker.config.mjs";
9
+
10
+ /**
11
+ * @param {string[]} args the options of Stryker
12
+ * @returns {Promise<number>} the exit code of Stryker
13
+ */
14
+ export async function run(args) {
15
+ if (!existsSync(STRYKER_CONFIG)) throw new Error(`${STRYKER_CONFIG} is missing: it gives the configuration of the mutation tests. Run \`npx caits init .\` to write it.`);
16
+ // A run that stops before its report must not show the summary of the run before.
17
+ rmSync(REPORT, { force: true });
18
+ // Ctrl+C and `caits check` stop the whole group of processes: Stryker and its test runners stop with this command.
19
+ const stryker = spawn("npx", ["stryker", "run", STRYKER_CONFIG, ...args], { stdio: "inherit" });
20
+ /** @type {number} */
21
+ const status = await new Promise(resolve => {
22
+ stryker.on("error", () => resolve(1));
23
+ stryker.on("close", code => resolve(code ?? 1));
24
+ });
25
+ if (existsSync(REPORT)) {
26
+ console.log("");
27
+ summary(["--survivors"]);
28
+ }
29
+ return status;
30
+ }