문제: `test:a11y`(FE-GATE-009)가 `playwright.config.ts`를 그대로 써서 e2e의 결과 폴더·HTML report·`results.xml`에 쓴다. merge browser job은 한 checkout에서 FE-GATE-008 다음 FE-GATE-009를 돌고 `artifacts/`를 올리므로, 올린 e2e 증거는 a11y 실행의 것이다. FE-GATE-009에는 자기 JUnit·report 증거가 없다. 게이트 밖 `test:e2e:dev`도 e2e 설정을 펼쳐 같은 경로에 쓰므로, 로컬 실행이 FE-GATE-008 결과를 지운다 (Playwright는 시작할 때 결과 폴더를 비운다). 고른 방법: - `playwright.a11y.config.ts`가 e2e 설정을 펼치고 결과 경로만 `artifacts/tests/a11y/`로 바꾼다. `forbidOnly: true`는 글자로 둔다 (`check-test-evidence.ts`가 등록 설정마다 그 글자를 찾는다). `test:a11y`는 `--config playwright.a11y.config.ts --grep @a11y`. - `playwright.dev.config.ts`도 결과 경로를 `artifacts/tests/e2e-dev/`로 둔다. - `config/ci/gates.json`: a11y `results.xml`·`report/index.html` 증거(producer `test-a11y`)를 더하고 FE-GATE-009 증거에 넣는다. - 새 시험 `tests/unit/playwright-result-paths.test.ts`: package script가 부르는 Playwright 설정을 run ID 없이 불러 결과 경로를 모은다. (1) 서로 다른 설정 둘이 같은 경로(또는 한쪽 안의 경로)에 쓰면 실패, (2) 게이트 명령 둘이 같은 경로에 쓰면 실패, (3) 게이트 명령이 쓰는 JUnit·report가 그 게이트의 증거이고 producer가 그 명령이 아니면 실패. - FE-6 시험의 Playwright 쪽(`test:e2e`·`test:a11y`의 `playwright test` 두 줄과 「같은 설정이라 project가 같다」)을 `ci-workflow-generation.test.ts`에서 새 시험으로 옮긴다. 글자로 보던 것을, 같은 포트로 두 설정을 불러 결과 경로 밖 설정 전체가 같은지 보는 단언으로 바꾼다. gate 계약 쪽(008·009의 commandIds, merge browser job)은 그 자리에 둔다. - 제거 fixture 사본(FE-GATE-013·020)은 `artifacts/`에서 재생성 트리만 빼고 복사한다. 결과 경로를 옮기면 a11y·dev 결과와 report(실패하면 trace까지)가 사본에 들어가므로, `scripts/lib/removal-fixture.ts`의 목록에 `artifacts/tests/a11y`·`artifacts/tests/e2e-dev`를 더한다. 새 시험 (4): 각 Playwright 설정의 results·report 폴더가 그 목록 안에 있다. `a11y.json`·`a11y-data-state/`는 계속 복사되는지 fixture 시험이 본다. - `playwright.a11y.config.ts`가 `testDir: "./tests/e2e"`를 글자로 둔다. FE-GATE-029는 게이트 명령이 부르는 설정 파일 본문에서 `testDir:`를 찾으므로, 펼치기만 하면 `test:a11y`가 게이트하는 폴더가 0개다. 새 시험(`ungated-tests.test.ts`): 게이트 명령이 닿는 `playwright test`마다 testDir을 찾는다. - decisions.md FE-6 행은 옮긴 단언의 자리 `tests/unit/playwright-result-paths.test.ts`를 백틱으로 적는다. 샘플 제거 드릴(FE-GATE-020)은 사본에서 `ci-workflow-generation.test.ts`를 지우고, 사본의 `verify:documentation`은 살아 있는 문서의 백틱 경로를 대조한다. 그 시험 경로를 백틱으로 적은 첫 판은 020에서 실패했다. 버린 안: 경로를 백틱 없이 적기. `.claude/rules/docs.md`가 「검사를 피하려고 백틱을 빼지 않는다」고 정한다(1105/14-03). 드릴 쪽(문서 검사에 예외 경로 넘기기, 그 시험을 지우지 않기)은 b6bfc9b7에서 버린 안이라 손대지 않는다. 다른 살아 있는 문서에는 드릴이 지우는 네 파일을 백틱으로 적은 곳이 없다(`git grep`). - 시험 helper(설정 찾기·경로 겹침)에 거절 입력 시험을 둔다. - 버린 안: `test:a11y`에 `--output`·`--reporter` 인자를 붙이기. 결과 경로가 설정과 script 두 곳에 나뉘고, run ID 격리(`testRunPath`)를 다시 만들어야 한다. - 막지 않은 것: `test:visual:update`는 `test:visual`과 같은 설정이라 같은 경로에 쓴다. 같은 시험을 골든 갱신으로 도는 것이라 그 결과가 visual 결과다. 시험 (1)은 설정 단위라 이것을 막지 않는다. 위험·한계: FE-GATE-009의 증거가 둘 늘어 그 게이트가 JUnit·report 없이 끝나면 실패한다. 하류 프로젝트가 `test:a11y`를 고쳐 `--config` 없이 쓰면 새 시험이 실패한다(CHANGELOG 「먼저 할 일」). 결과 경로를 script 인자로 바꾸는 설정(`--output` 등)은 새 시험이 읽지 않는다. FE-GATE-029 파서는 `--grep-invert @a11y`를 읽지 않아 `@a11y` 시험을 008이 도는 것으로 센다(FE-6부터 있던 것, 이 커밋 밖). 검증(desktop `scripts/verify.sh exec`): - RED(트리 1e2c4a8f, 고치기 전): 새 시험 3개 모두 실패. dev 설정이 e2e 경로 셋, test-e2e·test-a11y가 같은 경로 셋, test-a11y의 JUnit·report가 FE-GATE-009 증거가 아니고 producer가 test-e2e. - GREEN: 새 시험, playwright-run-isolation, ci-workflow-generation, repository-layout, test-evidence-repository-configs 503개 통과. - 변이: a11y 결과 경로를 e2e로 → 새 시험 3개와 a11y 결과 폴더 시험 실패. dev 설정의 결과 경로 빼기 → 새 시험 (1)과 dev 결과 폴더 시험 실패. a11y 설정에 `workers: 1` → FE-6 시험 실패. - `check:types`·바꾼 파일 eslint·`check:ci` rc=0. - 리뷰 반영 RED(트리 a36e8676, 시험만 더함): 새 시험 (4)가 a11y·dev의 results·report 4개로, testDir 시험이 `test:a11y` 한 줄로 실패. 거절 입력 시험 둘과 fixture 형제 경로 단언은 통과. - 리뷰 반영 GREEN(트리 155a93de): 위 시험과 removal-fixture, ungated-tests, documentation-readiness 7파일 549개 통과, `check:types`·바꾼 파일 eslint rc=0. - FE-GATE-020: 첫 판(트리 ac0ea6d7)의 desktop merge에서 rc=1 (「decisions.md names paths that do not exist」). - FE-6 단언 옮김 RED(트리 eed3c87f): a11y 설정에 `retries: 7` 변이 → 옮긴 단언이 새 시험에서 실패(1 failed, 6 passed). 옛 자리에 그 단언이 없다(`ci-workflow-generation.test.ts`에서 `loadConfigFile`· `withoutResultPaths`·`playwrightRuns` grep 0건). - GREEN(트리 d2d941c3): 새 시험, ci-workflow-generation, ungated-tests, removal-fixture 4파일 485개 통과, `check:types`·바꾼 파일 eslint rc=0. Refs: 1106 리뷰 11 영역 3.2 (3) 증거 읽기 주의
237 lines
9.0 KiB
TypeScript
237 lines
9.0 KiB
TypeScript
import { createServer, type Server } from "node:net";
|
|
import path from "node:path";
|
|
import { pathToFileURL } from "node:url";
|
|
|
|
import type { PlaywrightTestConfig } from "@playwright/test";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
|
|
/**
|
|
* 1105/12-04. The run-isolation checks every Playwright config shares, for
|
|
* tests/unit/playwright-run-isolation.test.ts (the five configs every project
|
|
* has) and tests/unit/playwright-capabilities-run-isolation.test.ts (the
|
|
* capabilities config, which goes with the browser file/storage runtime).
|
|
*
|
|
* 1106/10-01. Each file imports its configs by name and passes them here, so
|
|
* no check depends on which config files a checkout happens to have.
|
|
*/
|
|
export type ConfigName = "e2e" | "a11y" | "visual" | "capabilities" | "storybook" | "dev";
|
|
export type ConfigLoaders = Readonly<
|
|
Partial<Record<ConfigName, () => Promise<{ default: PlaywrightTestConfig }>>>
|
|
>;
|
|
|
|
const PORT_VARIABLES: Readonly<Record<ConfigName, string>> = {
|
|
e2e: "TEST_E2E_PORT",
|
|
// The a11y config spreads the e2e one, server included.
|
|
a11y: "TEST_E2E_PORT",
|
|
visual: "TEST_VISUAL_PORT",
|
|
capabilities: "TEST_CAPABILITIES_PORT",
|
|
storybook: "TEST_STORYBOOK_PORT",
|
|
dev: "TEST_DEV_PORT",
|
|
};
|
|
/** The port variables of the configs' second servers. */
|
|
const SECOND_SERVER_PORT_VARIABLES = ["TEST_VISUAL_WORKSHOP_PORT"];
|
|
const RUN_VARIABLES = [
|
|
"TEST_RUN_ID",
|
|
"RUN_OUTPUT_ROOT",
|
|
...Object.values(PORT_VARIABLES),
|
|
...SECOND_SERVER_PORT_VARIABLES,
|
|
];
|
|
const held: Server[] = [];
|
|
|
|
/** For afterEach: forgets the loaded configs and frees the ports `hold` took. */
|
|
export async function releaseRuns(): Promise<void> {
|
|
vi.resetModules();
|
|
await Promise.all(
|
|
held.splice(0).map((server) => new Promise<void>((resolve) => server.close(() => resolve()))),
|
|
);
|
|
}
|
|
|
|
type ConfigProcess = Readonly<{
|
|
config: PlaywrightTestConfig;
|
|
after: Readonly<Record<string, string | undefined>>;
|
|
}>;
|
|
|
|
export type ConfigRuns = Readonly<{
|
|
/** The config as one process sees it, and what it left in that environment. */
|
|
loadProcess(
|
|
name: ConfigName,
|
|
environment?: Readonly<Record<string, string>>,
|
|
): Promise<ConfigProcess>;
|
|
load(name: ConfigName, environment?: Readonly<Record<string, string>>): Promise<PlaywrightTestConfig>;
|
|
}>;
|
|
|
|
async function loadInProcess(
|
|
loader: () => Promise<{ default: PlaywrightTestConfig }>,
|
|
environment: Readonly<Record<string, string>>,
|
|
): Promise<ConfigProcess> {
|
|
const saved = RUN_VARIABLES.map((variable) => [variable, process.env[variable]] as const);
|
|
for (const variable of RUN_VARIABLES) delete process.env[variable];
|
|
Object.assign(process.env, environment);
|
|
vi.resetModules();
|
|
try {
|
|
const config = (await loader()).default;
|
|
return {
|
|
config,
|
|
after: Object.fromEntries(RUN_VARIABLES.map((variable) => [variable, process.env[variable]])),
|
|
};
|
|
} finally {
|
|
for (const [variable, value] of saved) {
|
|
if (value === undefined) delete process.env[variable];
|
|
else process.env[variable] = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
/** Each load evaluates the config again with the environment of one process. */
|
|
export function configRuns(loaders: ConfigLoaders): ConfigRuns {
|
|
async function loadProcess(
|
|
name: ConfigName,
|
|
environment: Readonly<Record<string, string>> = {},
|
|
): Promise<ConfigProcess> {
|
|
const loader = loaders[name];
|
|
if (loader === undefined) throw new TypeError(`no loader for the ${name} config`);
|
|
return loadInProcess(loader, environment);
|
|
}
|
|
return {
|
|
loadProcess,
|
|
load: async (name, environment = {}) => (await loadProcess(name, environment)).config,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* The config a package script names (a path from the checkout root), as a
|
|
* process with `environment` and no other run variable sees it. Without a run
|
|
* ID its results are where the gates read them.
|
|
*/
|
|
export async function loadConfigFile(
|
|
file: string,
|
|
environment: Readonly<Record<string, string>> = {},
|
|
): Promise<PlaywrightTestConfig> {
|
|
const url = pathToFileURL(path.resolve(file)).href;
|
|
return (
|
|
await loadInProcess(() => import(url) as Promise<{ default: PlaywrightTestConfig }>, environment)
|
|
).config;
|
|
}
|
|
|
|
export function portOf(config: PlaywrightTestConfig): number {
|
|
return Number(new URL(String(config.use?.baseURL)).port);
|
|
}
|
|
|
|
/** Listens on `port` the way the first run's server does. */
|
|
export async function hold(port: number): Promise<void> {
|
|
const server = createServer();
|
|
held.push(server);
|
|
await new Promise<void>((resolve, reject) => {
|
|
server.once("error", reject);
|
|
server.listen(port, "127.0.0.1", () => resolve());
|
|
});
|
|
}
|
|
|
|
function reporterOption(config: PlaywrightTestConfig, reporter: string, option: string): string {
|
|
const reporters: readonly unknown[] = Array.isArray(config.reporter) ? config.reporter : [];
|
|
const entry = reporters.find(
|
|
(candidate) => Array.isArray(candidate) && candidate[0] === reporter,
|
|
) as readonly [string, Record<string, unknown>] | undefined;
|
|
return String(entry?.[1][option]);
|
|
}
|
|
|
|
/** Absolute paths of the config's results folder, HTML report folder and JUnit file. */
|
|
export function outputs(config: PlaywrightTestConfig) {
|
|
return {
|
|
results: path.resolve(String(config.outputDir)),
|
|
report: path.resolve(reporterOption(config, "html", "outputFolder")),
|
|
junit: path.resolve(reporterOption(config, "junit", "outputFile")),
|
|
};
|
|
}
|
|
|
|
/** The config's own server: the first one when it starts more than one. */
|
|
export function webServer(config: PlaywrightTestConfig) {
|
|
const [server] = webServers(config);
|
|
if (!server) throw new TypeError("expected a web server");
|
|
return server;
|
|
}
|
|
|
|
export function webServers(config: PlaywrightTestConfig) {
|
|
const servers = config.webServer;
|
|
return servers === undefined ? [] : Array.isArray(servers) ? servers : [servers];
|
|
}
|
|
|
|
/** Each config's results, report and JUnit file, by its folder under artifacts/tests. */
|
|
export function describeResultFolders(
|
|
runs: ConfigRuns,
|
|
folders: readonly (readonly [ConfigName, string])[],
|
|
): void {
|
|
describe.each(folders)("the %s config", (name, folder) => {
|
|
const expected = (root: string) => ({
|
|
results: path.resolve(root, `artifacts/tests/${folder}/results`),
|
|
report: path.resolve(root, `artifacts/tests/${folder}/report`),
|
|
junit: path.resolve(root, `artifacts/tests/${folder}/results.xml`),
|
|
});
|
|
|
|
it("writes where the gates read without a run ID", async () => {
|
|
expect(outputs(await runs.load(name as ConfigName))).toEqual(expected("."));
|
|
});
|
|
|
|
it("gives each run ID its own results, report and JUnit file", async () => {
|
|
const a = outputs(await runs.load(name as ConfigName, { TEST_RUN_ID: "a" }));
|
|
const b = outputs(await runs.load(name as ConfigName, { TEST_RUN_ID: "b" }));
|
|
|
|
expect(a).toEqual(expected(".tmp/runs/a"));
|
|
expect(b).toEqual(expected(".tmp/runs/b"));
|
|
});
|
|
});
|
|
}
|
|
|
|
/** Inside "the build a run serves": the dev servers' Vite cache. */
|
|
export function itKeepsTheViteCacheInTheRun(runs: ConfigRuns, names: readonly ConfigName[]): void {
|
|
it.each(names)("keeps the dev server's Vite cache in the run's folder (%s)", async (name) => {
|
|
expect(webServer(await runs.load(name)).env?.["RUN_OUTPUT_ROOT"]).toBe(".");
|
|
expect(webServer(await runs.load(name, { TEST_RUN_ID: "a" })).env?.["RUN_OUTPUT_ROOT"]).toBe(
|
|
".tmp/runs/a",
|
|
);
|
|
});
|
|
}
|
|
|
|
export function describeServerPorts(runs: ConfigRuns, names: readonly ConfigName[]): void {
|
|
describe.each(names)("the %s server port", (name) => {
|
|
it("is a free port the runner hands to its workers", async () => {
|
|
const runner = await runs.loadProcess(name);
|
|
const port = portOf(runner.config);
|
|
const server = webServer(runner.config);
|
|
|
|
// Playwright evaluates the config again in each worker, which inherits
|
|
// the runner's environment: the port is there, so baseURL agrees.
|
|
expect(runner.after[PORT_VARIABLES[name]]).toBe(String(port));
|
|
expect(portOf(await runs.load(name, { [PORT_VARIABLES[name]]: String(port) }))).toBe(port);
|
|
expect(server.url).toBe(`http://127.0.0.1:${port}`);
|
|
expect(server.command).toMatch(new RegExp(` (?:--port )?${port}(?: |$)`, "u"));
|
|
expect(server.reuseExistingServer).toBe(false);
|
|
});
|
|
|
|
it("moves for a second run while the first run's server holds its port", async () => {
|
|
const first = portOf(await runs.load(name));
|
|
await hold(first);
|
|
|
|
expect(portOf(await runs.load(name))).not.toBe(first);
|
|
});
|
|
|
|
it("is the one its variable pins", async () => {
|
|
const pinned = await runs.load(name, { [PORT_VARIABLES[name]]: "40123" });
|
|
expect(portOf(pinned)).toBe(40123);
|
|
expect(webServer(pinned).url).toBe("http://127.0.0.1:40123");
|
|
});
|
|
});
|
|
}
|
|
|
|
/** Inside "vite servers": the configs whose server is vite. */
|
|
export function itExitsWhenItsPortIsTaken(runs: ConfigRuns, names: readonly ConfigName[]): void {
|
|
it.each(names)(
|
|
"exit instead of moving to the next port when theirs is taken (%s)",
|
|
async (name) => {
|
|
// Without --strictPort vite moved on, and Playwright, waiting on the
|
|
// configured URL, tested whatever already listened there.
|
|
expect(webServer(await runs.load(name)).command).toMatch(/ --port \d+ --strictPort(?: |$)/u);
|
|
},
|
|
);
|
|
}
|