Files
clean-architecture-frontend…/tests/unit/test-evidence-source-rules.test.ts
T
DongHyeonka 34a7627d36 fix(test-evidence): 검사 규칙마다 혼자 도는 거절 시험을 두고 strict import를 lint로 본다
문제: `check-test-evidence.ts`의 세 규칙에 혼자 도는 거절 시험이 없었다.
화면 전체 mask 규칙은 fixture만 있고 시험이 없었고, FE-GATE-029의 디렉터리
실행은 공통 접두어만 기대해 다른 fixture가 실패하면 통과했다. Playwright
설정의 forbidOnly 확인과 strict fixture 우회 확인은 전체 실행에서만 돌아
fixture로 시험할 수 없었다. strict fixture 확인은 `tests/e2e/*.spec.ts`
본문에 경로 글자가 있는지만 보아, 주석에만 적어도 통과했고 다른 브라우저
폴더 셋은 보지 않았다(1112/03-04).

고친 것:
- mask fixture 하나만 돌리는 시험을 더한다.
- forbidOnly 규칙이 시나리오 검사 밖의 모든 실행에서 돌고, 읽은 설정 목록을
  보고의 `facts.playwrightConfigs`에 남긴다. `--playwright-config <파일>`로
  다른 설정을 줄 수 있다. 거절 fixture(forbidOnly 없는 설정)와, 플래그가
  없으면 저장소 설정 전부를 읽는지 보는 시험을 더한다.
- strict fixture 확인은 ESLint `no-restricted-imports`로 옮긴다.
  `tests/{e2e,browser-capabilities,visual,storybook}/**/*.spec.ts`가
  `@playwright/test`의 `test`(이름·기본 import)나 strict fixture가 넓히는
  base test를 import하면 오류다. 일부러 plain test를 쓰는 둘
  (`preload-use.spec.ts`, `chunk-load-error.spec.ts`)만 예외다. 문자열 검사는
  지운다. 네 폴더 각각의 lint fixture를 시험이 lint한다.

위험·한계: w2-fe-2 PR #47이 두 예외 spec의 import를
`tests/support/browser/browser-test.ts`로 바꾼다. 그 경로의 `test`도 이
규칙이 막으므로 예외 둘은 그대로 필요하다.

검증: desktop 변이 셋 — mask 블록 삭제, forbidOnly 호출 삭제, ESLint 규칙
삭제 — 에서 각각 해당 시험이 실패하고(1·1·5건), 고친 코드에서 51건 통과.
`corepack pnpm lint` rc=0.

Refs: 1112/03-03, 1112/03-04
2026-11-13 23:29:13 +09:00

112 lines
4.5 KiB
TypeScript

import { spawnSync } from "node:child_process";
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import path from "node:path";
import { afterAll, describe, expect, it } from "vitest";
import { selectRepositoryPaths } from "../../scripts/lib/repository-layout.ts";
import { childProcessTimeout } from "../helpers/child-process-timeout.ts";
const FORBIDDEN = "tests/fixtures/test-evidence/forbidden";
const roots: string[] = [];
afterAll(async () => {
await Promise.all(roots.map((root) => rm(root, { recursive: true, force: true })));
});
function checkSource(sourceRoot: string, extra: readonly string[] = []) {
const result = spawnSync(
process.execPath,
[
"scripts/check-test-evidence.ts",
"--source-only",
"--source-root",
sourceRoot,
"--artifact",
"artifacts/quality/test-evidence-source-rules.json",
...extra,
],
{ encoding: "utf8" },
);
return { status: result.status, stderr: result.stderr };
}
// 11-08. Each forbidden fixture is checked alone, so a rule that stops firing
// is not hidden by another fixture in the same directory still failing.
describe("test evidence source rules", () => {
it("rejects a focused test", () => {
const result = checkSource(`${FORBIDDEN}/focused-test.fixture`);
expect(result.status).toBe(1);
expect(result.stderr).toContain("focused test");
}, childProcessTimeout(1_333));
it("rejects a quarantine whose expiry date has passed", () => {
const result = checkSource(`${FORBIDDEN}/expired-quarantine.fixture`);
expect(result.status).toBe(1);
expect(result.stderr).toContain("quarantine expired on 2020-01-01");
}, childProcessTimeout(739));
// 1112/03-03. The mask fixture had no test of its own: the directory run
// expects only the common prefix, so this rule could stop firing unseen.
it("rejects a screenshot mask over the whole UI", () => {
const result = checkSource(`${FORBIDDEN}/full-screen-mask.fixture`);
expect(result.status).toBe(1);
expect(result.stderr).toContain("screenshot mask may not cover the whole UI");
}, childProcessTimeout(141));
// 1112/03-03. The forbidOnly rule ran only in the full check, on the
// repository's own configs, so nothing showed it still rejects a config.
it("rejects a Playwright config without forbidOnly and accepts the repository's", async () => {
const root = await mkdtemp(path.join(tmpdir(), "test-evidence-config-"));
roots.push(root);
await writeFile(path.join(root, "clean.fixture"), "export {};\n");
const missing = checkSource(root, [
"--playwright-config",
"tests/fixtures/test-evidence/playwright-config/missing-forbid-only.fixture",
]);
expect(missing.status).toBe(1);
expect(missing.stderr).toContain(
"tests/fixtures/test-evidence/playwright-config/missing-forbid-only.fixture: missing forbidOnly: true",
);
const present = checkSource(root, ["--playwright-config", "playwright.config.ts"]);
expect(present.stderr).toBe("");
expect(present.status).toBe(0);
// Without the flag the rule reads the repository's configs, every one.
const repository = checkSource(root);
expect(repository.status, repository.stderr).toBe(0);
const report = JSON.parse(await readFile("artifacts/quality/test-evidence-source-rules.json", "utf8")) as {
facts: { playwrightConfigs?: string[] };
};
expect(report.facts.playwrightConfigs).toEqual([...selectRepositoryPaths("playwright-configs")]);
expect(report.facts.playwrightConfigs?.length).toBeGreaterThan(0);
}, childProcessTimeout(296));
it("rejects a skip without a quarantine", () => {
const result = checkSource(`${FORBIDDEN}/unowned-skip.fixture`);
expect(result.status).toBe(1);
expect(result.stderr).toContain("lacks owned expiring quarantine");
}, childProcessTimeout(1_188));
it("accepts a skip under an unexpired quarantine", async () => {
const root = await mkdtemp(path.join(tmpdir(), "test-evidence-quarantine-"));
roots.push(root);
const file = path.join(root, "quarantined.fixture");
// Built from parts so this file is not itself a skip the checker scans.
const skip = ["test", "skip"].join(".");
await writeFile(
file,
[
`// ${"quarantine"}(owner=frontend-platform, defect=open-fixture, expires=2999-12-31)`,
`${skip}("quarantined", async () => {});`,
"",
].join("\n"),
);
const result = checkSource(file);
expect(result.stderr).toBe("");
expect(result.status).toBe(0);
}, childProcessTimeout(842));
});