Files
agentic-dev/scripts/coverage/mutate.test.mjs
Danijel Martinek 1883883911 test(scripts): wire scripts/**/*.test.mjs under a vitest runner
241 tests across 16 script test files were wired to NO runner (the
generators vitest config never included them and several used node:test
imports that vitest silently skips). New root vitest.scripts.config.mjs
+ pnpm test:scripts + a CI validate step run them all; node:test imports
converted to vitest keeping node:assert. Split out of 8c88a9a where a
concurrent agent's staged files were swept into the marketing-pages
commit.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-10 18:25:43 +02:00

74 lines
2.5 KiB
JavaScript

// Runs under vitest (pnpm test:scripts picks up scripts/**/*.test.mjs);
// node:assert keeps the original assertion style.
import { test, describe } from "vitest";
import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";
import os from "node:os";
import { discoverStrykerConfigs } from "./mutate.mjs";
describe("discoverStrykerConfigs", () => {
test("finds stryker.config.json under packages/* and apps/*", () => {
const tmpRoot = fs.mkdtempSync(path.join(os.tmpdir(), "mutate-disc-"));
try {
fs.mkdirSync(path.join(tmpRoot, "packages", "p1"), { recursive: true });
fs.mkdirSync(path.join(tmpRoot, "apps", "a1"), { recursive: true });
fs.mkdirSync(path.join(tmpRoot, "packages", "no-stryker"), {
recursive: true,
});
fs.writeFileSync(
path.join(tmpRoot, "packages", "p1", "stryker.config.json"),
"{}",
);
fs.writeFileSync(
path.join(tmpRoot, "packages", "p1", "package.json"),
JSON.stringify({ name: "@repo/p1" }),
);
fs.writeFileSync(
path.join(tmpRoot, "apps", "a1", "stryker.config.json"),
"{}",
);
fs.writeFileSync(
path.join(tmpRoot, "apps", "a1", "package.json"),
JSON.stringify({ name: "@repo/a1" }),
);
const found = discoverStrykerConfigs(tmpRoot);
assert.equal(found.length, 2);
const names = found.map((f) => f.packageName).sort();
assert.deepEqual(names, ["@repo/a1", "@repo/p1"]);
} finally {
fs.rmSync(tmpRoot, { recursive: true, force: true });
}
});
test("falls back to packageDir when no package.json", () => {
const tmpRoot = fs.mkdtempSync(path.join(os.tmpdir(), "mutate-disc2-"));
try {
fs.mkdirSync(path.join(tmpRoot, "packages", "no-pkg-json"), {
recursive: true,
});
fs.writeFileSync(
path.join(tmpRoot, "packages", "no-pkg-json", "stryker.config.json"),
"{}",
);
const found = discoverStrykerConfigs(tmpRoot);
assert.equal(found.length, 1);
assert.equal(found[0].packageName, "packages/no-pkg-json");
} finally {
fs.rmSync(tmpRoot, { recursive: true, force: true });
}
});
test("returns empty when nothing matches", () => {
const tmpRoot = fs.mkdtempSync(path.join(os.tmpdir(), "mutate-disc3-"));
try {
const found = discoverStrykerConfigs(tmpRoot);
assert.deepEqual(found, []);
} finally {
fs.rmSync(tmpRoot, { recursive: true, force: true });
}
});
});