chore(test): separate development feedback from full verification (#599)
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import { mkdir, symlink, writeFile } from "node:fs/promises";
|
||||
import { join, resolve } from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
const execute = promisify(execFile);
|
||||
const runner = resolve("scripts/run-development-tests.mjs");
|
||||
|
||||
describe("development test runner", () => {
|
||||
it("rejects nonexistent explicit paths instead of returning a zero-test success", async () => {
|
||||
await expect(
|
||||
execute(process.execPath, [
|
||||
runner,
|
||||
"focused",
|
||||
"src/missing.test.ts",
|
||||
"--dry-run",
|
||||
]),
|
||||
).rejects.toMatchObject({ code: 1 });
|
||||
});
|
||||
|
||||
it("reports actionable remediation when the comparison base is unavailable", async () => {
|
||||
await expect(
|
||||
execute(process.execPath, [
|
||||
runner,
|
||||
"changed",
|
||||
"--base",
|
||||
"missing-test-base",
|
||||
"--dry-run",
|
||||
]),
|
||||
).rejects.toMatchObject({
|
||||
code: 1,
|
||||
stderr: expect.stringContaining(
|
||||
"Fetch origin/main or pass --base REVISION",
|
||||
),
|
||||
});
|
||||
});
|
||||
|
||||
it("runs a committed branch regression through real Git and Vitest without dist", async () => {
|
||||
const root = await createTestTempDirectory("rea-development-tests-");
|
||||
await mkdir(join(root, "src"));
|
||||
await symlink(
|
||||
resolve("node_modules"),
|
||||
join(root, "node_modules"),
|
||||
"junction",
|
||||
);
|
||||
await writeFile(
|
||||
join(root, "package.json"),
|
||||
JSON.stringify({ type: "module" }),
|
||||
);
|
||||
await writeFile(join(root, ".gitignore"), "node_modules\n");
|
||||
await writeFile(
|
||||
join(root, "vitest.config.ts"),
|
||||
`export default { test: { projects: [{ test: { name: "domain", include: ["src/**/*.test.ts"] } }] } };`,
|
||||
);
|
||||
await writeFile(join(root, "src/value.ts"), "export const value = 1;\n");
|
||||
await writeFile(
|
||||
join(root, "src/value.test.ts"),
|
||||
`import { it, expect } from "vitest"; import { value } from "./value"; it("checks current source", () => expect(value).toBe(1));\n`,
|
||||
);
|
||||
const git = (arguments_: string[]) =>
|
||||
execute("git", arguments_, { cwd: root });
|
||||
await git(["init", "-b", "main"]);
|
||||
await git(["add", ".gitignore", "package.json", "vitest.config.ts", "src"]);
|
||||
const commit = [
|
||||
"-c",
|
||||
"user.name=REA fixture",
|
||||
"-c",
|
||||
"user.email=fixture@example.test",
|
||||
"commit",
|
||||
"-m",
|
||||
"fixture",
|
||||
];
|
||||
await git(commit);
|
||||
const { stdout: baseline } = await git(["rev-parse", "HEAD"]);
|
||||
await git(["update-ref", "refs/remotes/origin/main", baseline.trim()]);
|
||||
await git(["switch", "-c", "regression"]);
|
||||
await writeFile(join(root, "src/value.ts"), "export const value = 2;\n");
|
||||
await writeFile(
|
||||
join(root, "src/value.test.ts"),
|
||||
`import { it, expect } from "vitest"; import { value } from "./value"; it("checks current source", () => expect(value).toBe(2));\n`,
|
||||
);
|
||||
await git(["add", "src"]);
|
||||
await git(commit);
|
||||
expect((await git(["status", "--porcelain"])).stdout).toBe("");
|
||||
const { stdout } = await execute(process.execPath, [runner, "changed"], {
|
||||
cwd: root,
|
||||
});
|
||||
expect(stdout).toContain("1 passed");
|
||||
const explicit = await execute(
|
||||
process.execPath,
|
||||
[runner, "focused", "src/value.test.ts"],
|
||||
{ cwd: root },
|
||||
);
|
||||
expect(explicit.stdout).toContain("1 passed");
|
||||
}, 30_000);
|
||||
});
|
||||
@@ -0,0 +1,69 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
developmentTestPlan,
|
||||
parseDevelopmentTestRequest,
|
||||
} from "../../scripts/lib/development-tests.mjs";
|
||||
|
||||
describe("development test selection", () => {
|
||||
it("keeps dirty source feedback independent of compiled artifacts", () => {
|
||||
const plan = developmentTestPlan(parseDevelopmentTestRequest("local", []));
|
||||
expect(plan.needsBuild).toBe(false);
|
||||
expect(plan.vitestArguments).toContain("--changed");
|
||||
expect(plan.vitestArguments).not.toContain("acceptance");
|
||||
expect(plan.vitestArguments).not.toContain("process-global");
|
||||
});
|
||||
|
||||
it("always runs explicitly selected source tests, including on a clean tree", () => {
|
||||
const path = "src/config.test.ts";
|
||||
const plan = developmentTestPlan(
|
||||
parseDevelopmentTestRequest("local", [path, path]),
|
||||
);
|
||||
expect(plan.needsBuild).toBe(false);
|
||||
expect(
|
||||
plan.vitestArguments.filter((argument) => argument === path),
|
||||
).toHaveLength(1);
|
||||
expect(
|
||||
plan.vitestArguments.some((argument) => argument.startsWith("--changed")),
|
||||
).toBe(false);
|
||||
expect(plan.vitestArguments).not.toContain("--passWithNoTests");
|
||||
});
|
||||
|
||||
it("builds before explicitly selected compiled boundaries", () => {
|
||||
const plan = developmentTestPlan(
|
||||
parseDevelopmentTestRequest("focused", [
|
||||
"src/config.test.ts",
|
||||
"tests/acceptance/applications/runtime.test.ts",
|
||||
]),
|
||||
);
|
||||
expect(plan.needsBuild).toBe(true);
|
||||
expect(plan.vitestArguments).not.toContain("--passWithNoTests");
|
||||
expect(plan.vitestArguments).not.toContain("--changed");
|
||||
});
|
||||
|
||||
it("uses the resolved branch merge base for committed source changes", () => {
|
||||
const request = parseDevelopmentTestRequest("changed", ["--base", "main"]);
|
||||
const plan = developmentTestPlan(request, "a".repeat(40));
|
||||
expect(request.base).toBe("main");
|
||||
expect(plan.vitestArguments).toContain(`--changed=${"a".repeat(40)}`);
|
||||
expect(() => developmentTestPlan(request)).toThrow(
|
||||
"resolved Git merge base",
|
||||
);
|
||||
});
|
||||
|
||||
it.each([
|
||||
["focused", []],
|
||||
["focused", ["../src/config.test.ts"]],
|
||||
["focused", ["src/../config.test.ts"]],
|
||||
["focused", ["--passWithNoTests"]],
|
||||
["focused", ["--changed"]],
|
||||
["local", ["tests/acceptance/applications/runtime.test.ts"]],
|
||||
["changed", ["--base"]],
|
||||
["changed", ["--base=--help"]],
|
||||
["changed", ["src/config.test.ts"]],
|
||||
["local", ["--base", "main"]],
|
||||
["unknown", []],
|
||||
])("rejects invalid %s selections: %j", (mode, paths) => {
|
||||
expect(() => parseDevelopmentTestRequest(mode, paths)).toThrow();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user