check-test-evidence는 skip·fixme를 정규식
\b(?:test|it|describe)(?:\.describe)?\.(?:skip|fixme)\s*\( 로 찾았다.
testInfo.skip(), test.info().skip(), import { test as strictTest } 뒤의
strictTest.skip()은 못 봤다. 별칭은 tests/e2e/preload-use.spec.ts가 이미
쓴다. Playwright e2e에서 skip을 막는 곳은 이 검사뿐이라, 이런 꼴은
quarantine 없이 시험을 빼도 FE-GATE-008이 초록이었다. 파일도 ts·tsx만
읽어 Playwright testMatch 기본값이 도는 .mts·.cts·.js·.mjs·.cjs·.jsx
spec은 보지 않았다.
skip·fixme를 Babel 구문 트리로 찾는다(check-architecture.ts와 같은
@babel/core parseAsync). 시험 객체는 test·it·describe와 그 import 별칭,
namespace·default import의 .test·.it·.describe(@playwright/test의 default는
test 자체),
X.extend(...)를 받은 변수, 시험 callback의 두 번째 인자와 TestInfo 타입
인자(그리고 testInfo라는 이름, it.each(rows)(…)의 표 인자는 빼고), X.info(), 이것들의 describe·serial·
parallel·step 멤버다. 이런 객체의 skip·fixme 호출이 있고 파일에
quarantine(owner=…, defect=…, expires=…)이 없으면 전처럼 실패한다.
메시지 끝에 호출과 줄을 붙인다(예: testInfo.skip at line 7). 파일 고르기는
Playwright testMatch 기본값의 확장자로 넓힌다. skip·fixme라는 낱말이 없는
파일과 .txt 스냅숏·.d.ts는 파싱하지 않고, 파싱이 안 되는 파일은 실패로 적는다.
버린 안: 정규식에 testInfo만 더하기는 별칭과 줄바꿈 꼴을 또 놓친다.
test.fail()까지 막기는 규칙(.claude/rules/tests.md) 밖이고 repo가
preload-use.spec.ts에서 쓴다. 그래서 test.fail()은 거절하지 않는다.
한계: 이름과 구문으로 판정한다. skip을 변수에 담아 부르거나 이름을
계산해 부르는 꼴은 보지 않는다. Vitest의 skipIf·runIf도 이 항목 밖이다
(Vitest는 no-skipped-tests reporter가 실행에서 막는다).
시험: fixture 다섯(testinfo-skip·test-info-skip·aliased-skip·namespace-skip·
more-skip-forms)이 각각 따로 거절되고, 실행 중에 쓴 .spec.mts의 test.fixme가 거절되며 test.fail()
파일과 it.each 표 인자는 통과하며, 파싱이 안 되는 파일은 실패한다. timeout은 desktop에서 잰 가장 긴 값(test:coverage 955 ms,
1,287 ms)이다. RED·GREEN은 PR 본문에 적는다.
Refs: REV-FE-0003
183 lines
8.0 KiB
TypeScript
183 lines
8.0 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 { 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 a fixture run reads no config, so its result depends
|
|
// only on the files it names. A removal drill's copy keeps the registry
|
|
// but deletes playwright.capabilities.config.ts; when this run read the
|
|
// registry's configs, every fixture run there failed on ENOENT (main run
|
|
// 376, FE-GATE-030). The full check still reads every one.
|
|
const fixtureOnly = checkSource(root);
|
|
expect(fixtureOnly.status, fixtureOnly.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([]);
|
|
}, 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));
|
|
|
|
// REV-FE-0003. A regular expression saw only `test.skip(`, so these three
|
|
// skipped a Playwright test with no quarantine and FE-GATE-008 stayed green.
|
|
it.each([
|
|
["testinfo-skip.fixture", "info.skip at line 2, testInfo.skip at line 7"],
|
|
["test-info-skip.fixture", "test.info().skip at line 2"],
|
|
["aliased-skip.fixture", "strictTest.skip at line 4"],
|
|
["namespace-skip.fixture", "strict.test.skip at line 5, pw.skip at line 6"],
|
|
[
|
|
"more-skip-forms.fixture",
|
|
[
|
|
"info.skip at line 7",
|
|
"strictTest.skip at line 10",
|
|
"base.describe.serial.skip at line 11",
|
|
"base.describe.parallel.fixme at line 12",
|
|
"base.step.skip at line 13",
|
|
].join(", "),
|
|
],
|
|
])("rejects an unquarantined skip in %s", (fixture, call) => {
|
|
const result = checkSource(`${FORBIDDEN}/${fixture}`);
|
|
expect(result.status).toBe(1);
|
|
expect(result.stderr).toContain(`skip/fixme lacks owned expiring quarantine (${call})`);
|
|
}, childProcessTimeout(955));
|
|
|
|
// REV-FE-0003. Playwright's default testMatch also runs `.mts`, `.cts`,
|
|
// `.js` and `.mjs` specs, and the checker read only `ts|tsx`. Written at
|
|
// run time so no runner or typecheck picks the probe up.
|
|
it("reads a .spec.mts file and accepts test.fail()", async () => {
|
|
const root = await mkdtemp(path.join(tmpdir(), "test-evidence-extensions-"));
|
|
roots.push(root);
|
|
const fixme = ["test", "fixme"].join(".");
|
|
await writeFile(path.join(root, "probe.spec.mts"), `${fixme}("probe", async () => {});\n`);
|
|
const rejected = checkSource(path.join(root, "probe.spec.mts"));
|
|
expect(rejected.status).toBe(1);
|
|
expect(rejected.stderr).toContain("probe.spec.mts: skip/fixme lacks owned expiring quarantine");
|
|
|
|
// test.fail() runs the test and expects it to fail; the rule names only
|
|
// skip and fixme, and tests/e2e/preload-use.spec.ts uses it.
|
|
await writeFile(
|
|
path.join(root, "expected-failure.spec.ts"),
|
|
'test("fails on purpose", async () => {\n // Not a skip: the words make the checker parse this file.\n test.fail();\n});\n',
|
|
);
|
|
const accepted = checkSource(path.join(root, "expected-failure.spec.ts"));
|
|
expect(accepted.stderr).toBe("");
|
|
expect(accepted.status).toBe(0);
|
|
|
|
// A file the parser cannot read fails instead of passing unchecked;
|
|
// `it.each` table data named like a TestInfo is not a skip.
|
|
const skipCall = ["it", "skip"].join(".");
|
|
await writeFile(path.join(root, "broken.spec.ts"), `${skipCall}("unclosed", () => {\n`);
|
|
const broken = checkSource(path.join(root, "broken.spec.ts"));
|
|
expect(broken.status).toBe(1);
|
|
expect(broken.stderr).toContain("broken.spec.ts: cannot parse to look for skip/fixme");
|
|
await writeFile(
|
|
path.join(root, "table.test.ts"),
|
|
'it.each([[1, 2]])("skips %i rows", (input, cursor) => {\n cursor.skip(input);\n});\n',
|
|
);
|
|
const table = checkSource(path.join(root, "table.test.ts"));
|
|
expect(table.stderr).toBe("");
|
|
expect(table.status).toBe(0);
|
|
// Nor the callback of any other namespace import.
|
|
await writeFile(
|
|
path.join(root, "cursor.test.ts"),
|
|
'import * as db from "./db.ts";\n\ndb.withCursor("q", (error, cursor) => cursor.skip(10));\n',
|
|
);
|
|
const cursor = checkSource(path.join(root, "cursor.test.ts"));
|
|
expect(cursor.stderr).toBe("");
|
|
expect(cursor.status).toBe(0);
|
|
}, childProcessTimeout(1_287));
|
|
|
|
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));
|
|
});
|