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());
});
});

View File

@@ -1,11 +1,12 @@
import { execFileSync } from "node:child_process";
import fs from "node:fs";
import path from "node:path";
import { describe, expect, it } from "vitest";
import { collectExtensionPluginSdkBoundaryInventory } from "../scripts/check-extension-plugin-sdk-boundary.mjs";
import {
collectExtensionPluginSdkBoundaryInventory,
main,
} from "../scripts/check-extension-plugin-sdk-boundary.mjs";
const repoRoot = process.cwd();
const scriptPath = path.join(repoRoot, "scripts", "check-extension-plugin-sdk-boundary.mjs");
const relativeOutsidePackageBaselinePath = path.join(
repoRoot,
"test",
@@ -13,6 +14,27 @@ const relativeOutsidePackageBaselinePath = path.join(
"extension-relative-outside-package-inventory.json",
);
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("extension src outside plugin-sdk boundary inventory", () => {
it("is currently empty", async () => {
const inventory = await collectExtensionPluginSdkBoundaryInventory("src-outside-plugin-sdk");
@@ -38,17 +60,13 @@ describe("extension src outside plugin-sdk boundary inventory", () => {
).toEqual(first);
});
it("script json output is empty", () => {
const stdout = execFileSync(
process.execPath,
[scriptPath, "--mode=src-outside-plugin-sdk", "--json"],
{
cwd: repoRoot,
encoding: "utf8",
},
);
it("script json output is empty", async () => {
const captured = createCapturedIo();
const exitCode = await main(["--mode=src-outside-plugin-sdk", "--json"], captured.io);
expect(JSON.parse(stdout)).toEqual([]);
expect(exitCode).toBe(0);
expect(captured.readStderr()).toBe("");
expect(JSON.parse(captured.readStdout())).toEqual([]);
});
});
@@ -59,17 +77,13 @@ describe("extension plugin-sdk-internal boundary inventory", () => {
expect(inventory).toEqual([]);
});
it("script json output is empty", () => {
const stdout = execFileSync(
process.execPath,
[scriptPath, "--mode=plugin-sdk-internal", "--json"],
{
cwd: repoRoot,
encoding: "utf8",
},
);
it("script json output is empty", async () => {
const captured = createCapturedIo();
const exitCode = await main(["--mode=plugin-sdk-internal", "--json"], captured.io);
expect(JSON.parse(stdout)).toEqual([]);
expect(exitCode).toBe(0);
expect(captured.readStderr()).toBe("");
expect(JSON.parse(captured.readStdout())).toEqual([]);
});
});
@@ -81,17 +95,13 @@ describe("extension relative-outside-package boundary inventory", () => {
expect(inventory).toEqual(expected);
});
it("script json output matches the checked-in baseline", () => {
const stdout = execFileSync(
process.execPath,
[scriptPath, "--mode=relative-outside-package", "--json"],
{
cwd: repoRoot,
encoding: "utf8",
},
);
it("script json output matches the checked-in baseline", async () => {
const captured = createCapturedIo();
const exitCode = await main(["--mode=relative-outside-package", "--json"], captured.io);
const expected = JSON.parse(fs.readFileSync(relativeOutsidePackageBaselinePath, "utf8"));
expect(JSON.parse(stdout)).toEqual(expected);
expect(exitCode).toBe(0);
expect(captured.readStderr()).toBe("");
expect(JSON.parse(captured.readStdout())).toEqual(expected);
});
});

File diff suppressed because it is too large Load Diff

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());
});
});

View File

@@ -1,10 +1,29 @@
import { execFileSync } from "node:child_process";
import path from "node:path";
import { describe, expect, it } from "vitest";
import { collectWebSearchProviderBoundaryInventory } from "../scripts/check-web-search-provider-boundaries.mjs";
import {
collectWebSearchProviderBoundaryInventory,
main,
} from "../scripts/check-web-search-provider-boundaries.mjs";
const repoRoot = process.cwd();
const scriptPath = path.join(repoRoot, "scripts", "check-web-search-provider-boundaries.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("web search provider boundary inventory", () => {
it("has no remaining production inventory in core", async () => {
@@ -35,12 +54,12 @@ describe("web search provider boundary inventory", () => {
).toEqual(first);
});
it("script json output is empty", () => {
const stdout = execFileSync(process.execPath, [scriptPath, "--json"], {
cwd: repoRoot,
encoding: "utf8",
});
it("script json output is empty", async () => {
const captured = createCapturedIo();
const exitCode = await main(["--json"], captured.io);
expect(JSON.parse(stdout)).toEqual([]);
expect(exitCode).toBe(0);
expect(captured.readStderr()).toBe("");
expect(JSON.parse(captured.readStdout())).toEqual([]);
});
});