test: trim test startup overhead

This commit is contained in:
Peter Steinberger
2026-03-21 23:30:51 +00:00
parent cf4d301a69
commit 37d5cbe43a
17 changed files with 1206 additions and 1047 deletions

View File

@@ -1,10 +1,26 @@
import { execFileSync } from "node:child_process";
import path from "node:path";
import { describe, expect, it } from "vitest";
import { collectArchitectureSmells } from "../scripts/check-architecture-smells.mjs";
import { collectArchitectureSmells, main } from "../scripts/check-architecture-smells.mjs";
const repoRoot = process.cwd();
const scriptPath = path.join(repoRoot, "scripts", "check-architecture-smells.mjs");
function createCapturedIo() {
let stdout = "";
let stderr = "";
return {
io: {
stdout: {
write(chunk) {
stdout += String(chunk);
},
},
stderr: {
write(chunk) {
stderr += String(chunk);
},
},
},
readStdout: () => stdout,
readStderr: () => stderr,
};
}
describe("architecture smell inventory", () => {
it("produces stable sorted output", async () => {
@@ -26,11 +42,11 @@ describe("architecture smell inventory", () => {
});
it("script json output matches the collector", async () => {
const stdout = execFileSync(process.execPath, [scriptPath, "--json"], {
cwd: repoRoot,
encoding: "utf8",
});
const captured = createCapturedIo();
const exitCode = await main(["--json"], captured.io);
expect(JSON.parse(stdout)).toEqual(await collectArchitectureSmells());
expect(exitCode).toBe(0);
expect(captured.readStderr()).toBe("");
expect(JSON.parse(captured.readStdout())).toEqual(await collectArchitectureSmells());
});
});