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,14 +1,13 @@
import { execFileSync } from "node:child_process";
import { readFileSync } from "node:fs";
import path from "node:path";
import { describe, expect, it } from "vitest";
import {
collectPluginExtensionImportBoundaryInventory,
diffInventory,
main,
} from "../scripts/check-plugin-extension-import-boundary.mjs";
const repoRoot = process.cwd();
const scriptPath = path.join(repoRoot, "scripts", "check-plugin-extension-import-boundary.mjs");
const baselinePath = path.join(
repoRoot,
"test",
@@ -20,6 +19,27 @@ function readBaseline() {
return JSON.parse(readFileSync(baselinePath, "utf8"));
}
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("plugin extension import boundary inventory", () => {
it("keeps dedicated web-search registry shims out of the remaining inventory", async () => {
const inventory = await collectPluginExtensionImportBoundaryInventory();
@@ -65,12 +85,12 @@ describe("plugin extension import boundary inventory", () => {
expect(diffInventory(expected, actual)).toEqual({ missing: [], unexpected: [] });
});
it("script json output matches the baseline exactly", () => {
const stdout = execFileSync(process.execPath, [scriptPath, "--json"], {
cwd: repoRoot,
encoding: "utf8",
});
it("script json output matches the baseline exactly", async () => {
const captured = createCapturedIo();
const exitCode = await main(["--json"], captured.io);
expect(JSON.parse(stdout)).toEqual(readBaseline());
expect(exitCode).toBe(0);
expect(captured.readStderr()).toBe("");
expect(JSON.parse(captured.readStdout())).toEqual(readBaseline());
});
});