test(architecture): consolidate import boundary verification
This commit is contained in:
@@ -161,21 +161,17 @@ describe("incremental module import boundaries", () => {
|
|||||||
["src/application/probe.ts", "../browser/CdpCaptureValues.js", true],
|
["src/application/probe.ts", "../browser/CdpCaptureValues.js", true],
|
||||||
["src/ghidra/probe.ts", "../generatedPackageMetadata.js", true],
|
["src/ghidra/probe.ts", "../generatedPackageMetadata.js", true],
|
||||||
["src/hopper/probe.ts", "../contracts/officialToolContracts.js", true],
|
["src/hopper/probe.ts", "../contracts/officialToolContracts.js", true],
|
||||||
])("checks %s importing %s", async (file, dependency, allowed) => {
|
])("checks %s importing %s", (file, dependency, allowed) => {
|
||||||
const temporary = await createTestTempDirectory("rea-module-boundary-");
|
const violations = inspectModuleBoundaries(
|
||||||
const fixture = join(temporary, file);
|
file,
|
||||||
await mkdir(dirname(fixture), { recursive: true });
|
|
||||||
await writeFile(
|
|
||||||
fixture,
|
|
||||||
`import { value } from ${JSON.stringify(dependency)}; export { value };\n`,
|
`import { value } from ${JSON.stringify(dependency)}; export { value };\n`,
|
||||||
|
process.cwd(),
|
||||||
);
|
);
|
||||||
const result = spawnSync(process.execPath, [verifier, file], {
|
if (allowed) expect(violations).toEqual([]);
|
||||||
cwd: temporary,
|
else
|
||||||
encoding: "utf8",
|
expect(violations).toMatchObject([
|
||||||
});
|
{ file, boundary: expect.any(String) },
|
||||||
if (result.error !== undefined) throw result.error;
|
]);
|
||||||
expect(result.status).toBe(allowed ? 0 : 1);
|
|
||||||
if (!allowed) expect(result.stderr).toContain("resolves to src/");
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -282,21 +278,25 @@ describe("module import syntax and source discovery", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("test lane import boundaries", () => {
|
describe("test lane import boundaries", () => {
|
||||||
it.each([
|
const cases: Array<[string, string, boolean]> = [
|
||||||
["src/application/probe.test.ts", "../server/createServer.js", false],
|
["src/application/probe.test.ts", "../server/createServer.js", false],
|
||||||
["tests/composition/probe.test.ts", "node:child_process", false],
|
["tests/composition/process.test.ts", "node:child_process", false],
|
||||||
["tests/composition/probe.test.ts", "node:net", false],
|
["tests/composition/net.test.ts", "node:net", false],
|
||||||
["tests/composition/probe.test.ts", "playwright", false],
|
["tests/composition/browser.test.ts", "playwright", false],
|
||||||
["tests/composition/probe.test.ts", "../../src/domain/result.js", true],
|
["tests/composition/domain.test.ts", "../../src/domain/result.js", true],
|
||||||
])("checks %s importing %s", async (file, dependency, allowed) => {
|
];
|
||||||
|
|
||||||
|
it("checks the test-lane import matrix in one lint invocation", async () => {
|
||||||
const temporary = await createTestTempDirectory("rea-test-lane-");
|
const temporary = await createTestTempDirectory("rea-test-lane-");
|
||||||
const config = join(temporary, ".oxlintrc.json");
|
const config = join(temporary, ".oxlintrc.json");
|
||||||
await copyFile(resolve(".oxlintrc.json"), config);
|
await copyFile(resolve(".oxlintrc.json"), config);
|
||||||
await mkdir(dirname(join(temporary, file)), { recursive: true });
|
for (const [file, dependency] of cases) {
|
||||||
await writeFile(
|
await mkdir(dirname(join(temporary, file)), { recursive: true });
|
||||||
join(temporary, file),
|
await writeFile(
|
||||||
`import { value } from ${JSON.stringify(dependency)}; export { value };\n`,
|
join(temporary, file),
|
||||||
);
|
`import { value } from ${JSON.stringify(dependency)}; export { value };\n`,
|
||||||
|
);
|
||||||
|
}
|
||||||
const result = spawnSync(
|
const result = spawnSync(
|
||||||
process.execPath,
|
process.execPath,
|
||||||
[
|
[
|
||||||
@@ -305,13 +305,22 @@ describe("test lane import boundaries", () => {
|
|||||||
config,
|
config,
|
||||||
"--format",
|
"--format",
|
||||||
"json",
|
"json",
|
||||||
file,
|
...cases.map(([file]) => file),
|
||||||
],
|
],
|
||||||
{ cwd: temporary, encoding: "utf8" },
|
{ cwd: temporary, encoding: "utf8" },
|
||||||
);
|
);
|
||||||
if (result.error !== undefined) throw result.error;
|
if (result.error !== undefined) throw result.error;
|
||||||
expect(result.status).toBe(allowed ? 0 : 1);
|
const report = JSON.parse(result.stdout) as {
|
||||||
if (!allowed) expect(result.stdout).toContain("no-restricted-imports");
|
diagnostics: Array<{ filename: string; code: string }>;
|
||||||
|
};
|
||||||
|
const violations = new Set(
|
||||||
|
report.diagnostics
|
||||||
|
.filter(({ code }) => code === "eslint(no-restricted-imports)")
|
||||||
|
.map(({ filename }) => filename.replaceAll("\\", "/")),
|
||||||
|
);
|
||||||
|
for (const [file, , allowed] of cases)
|
||||||
|
expect(violations.has(file)).toBe(!allowed);
|
||||||
|
expect(result.status).toBe(cases.some(([, , allowed]) => !allowed) ? 1 : 0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user