Curated, product-agnostic snapshot of the post-story-04 tree: demo content deleted, auth-only reference feature, web-next shell, all gates green. Product-specific docs, ADRs 027-029, PRDs/epics/archive, editor library traces, and product naming are curated out; generic template repairs (coverage provider devDeps, root test:coverage script, live lint fixes, root-only release-please) are kept. See TEMPLATE.md for provenance, curation list, and usage. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016j8z4VHjedXDTjEDNg7qHK
75 lines
2.2 KiB
JavaScript
75 lines
2.2 KiB
JavaScript
import { describe, it } from "vitest";
|
|
import { RuleTester } from "eslint";
|
|
import path from "node:path";
|
|
import os from "node:os";
|
|
import fs from "node:fs";
|
|
import rule from "./entity-must-have-test.js";
|
|
|
|
function makeModelsDir() {
|
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "emht-"));
|
|
const modelsDir = path.join(dir, "src", "entities", "models");
|
|
fs.mkdirSync(modelsDir, { recursive: true });
|
|
return modelsDir;
|
|
}
|
|
|
|
function makeEntityFixture({ withTest }) {
|
|
const modelsDir = makeModelsDir();
|
|
const entity = path.join(modelsDir, "cookie.ts");
|
|
fs.writeFileSync(entity, `export const cookie = {};`);
|
|
if (withTest) {
|
|
fs.writeFileSync(
|
|
path.join(modelsDir, "cookie.test.ts"),
|
|
`import { it } from "vitest"; it("works", () => {});`,
|
|
);
|
|
}
|
|
return { entity };
|
|
}
|
|
|
|
const tester = new RuleTester({
|
|
languageOptions: { ecmaVersion: "latest", sourceType: "module" },
|
|
});
|
|
|
|
describe("entity-must-have-test", () => {
|
|
it("passes when a sibling .test.ts exists", () => {
|
|
const { entity } = makeEntityFixture({ withTest: true });
|
|
tester.run("entity-must-have-test", rule, {
|
|
valid: [{ filename: entity, code: fs.readFileSync(entity, "utf8") }],
|
|
invalid: [],
|
|
});
|
|
});
|
|
|
|
it("fires when no sibling test file exists", () => {
|
|
const { entity } = makeEntityFixture({ withTest: false });
|
|
tester.run("entity-must-have-test", rule, {
|
|
valid: [],
|
|
invalid: [
|
|
{
|
|
filename: entity,
|
|
code: fs.readFileSync(entity, "utf8"),
|
|
errors: [{ messageId: "missingTest" }],
|
|
},
|
|
],
|
|
});
|
|
});
|
|
|
|
it("ignores files outside entities/models", () => {
|
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "emht-"));
|
|
const other = path.join(dir, "helper.ts");
|
|
fs.writeFileSync(other, `export const x = 1;`);
|
|
tester.run("entity-must-have-test", rule, {
|
|
valid: [{ filename: other, code: "export const x = 1;" }],
|
|
invalid: [],
|
|
});
|
|
});
|
|
|
|
it("ignores the index.ts barrel inside entities/models", () => {
|
|
const modelsDir = makeModelsDir();
|
|
const index = path.join(modelsDir, "index.ts");
|
|
fs.writeFileSync(index, `export {};`);
|
|
tester.run("entity-must-have-test", rule, {
|
|
valid: [{ filename: index, code: "export {};" }],
|
|
invalid: [],
|
|
});
|
|
});
|
|
});
|