문제: FE-GATE-029(check:ci:gating)는 게이트가 닿는 `playwright test` 실행마다 설정의 testDir을 gated로 셌고, `--grep`·`--grep-invert`·파일 필터를 읽지 않았다. FE-GATE-009의 test:a11y에서 Playwright 실행을 빼도 029는 통과했다. test:e2e(FE-GATE-008)가 tests/e2e를 `--grep-invert @a11y`로 돌기 때문에, 시험이 모두 @a11y인 tests/e2e/accessibility.spec.ts는 어느 게이트에서도 돌지 않는다. 설정도 `--config X`만 읽어서 `-c X`·`--config=X` 실행은 e2e 설정의 testDir로 셌다. result-paths 시험은 세 꼴을 따로 읽고 있었다. 고른 방법: 시험 본문이 아니라 게이트가 도는 인자만 본다. testDir 하나는 필터 없는 gated 실행이 있거나, `--grep-invert P` 실행마다 같은 testDir을 `--grep P`(같은 글자)로 도는 gated 실행이 있을 때만 gated다. 파일 필터가 있는 실행, `--grep`·`--grep-invert`를 합쳐 둘 이상 쓴 실행, 설정(또는 그 설정이 상대 경로로 import한 설정)의 글자에 `grep`·`grepInvert` 속성이 있는 실행은 나누지 않는 부분 실행으로 센다. 그런 testDir 아래 게이트 밖 파일은 testDir 한 줄로 알린다: testDir, 실행과 그 script, 빠진 짝. 인자 parser는 `scripts/lib/playwright-test-args.ts` 하나로 두고 029와 result-paths 시험이 같이 쓴다. `docs/operations/ci-quality-gates.md`의 029 설명에 이 규칙을 적는다. 버린 안: - `playwright test --list --reporter=json`으로 Playwright에 묻기: 시험 파일을 in-process로 불러 생성물(`src/features/*` 색인)에 기대고, 실행마다 수 초가 든다. - Babel로 시험 파일을 읽어 Playwright grep 판정을 흉내 내기: 제목 경로, 태그, forceRegExp 같은 Playwright 1.62 내부 규칙을 템플릿 안에 다시 만든다. 버전에 묶이고, 템플릿 리터럴 제목 때문에 파생 서비스에서 거짓 실패가 난다. 위험·한계: 짝은 글자로만 맞춘다. 정규식으로 같은 뜻이라도 글자가 다르면 실패한다(실패 쪽). 모르는 옵션 뒤 맨 토큰은 파일 필터로 센다(실패 쪽). `--project=X`·`--shard=X`처럼 `=`로 붙인 다른 옵션과 설정의 testMatch· testIgnore는 읽지 않는다. 필터는 package script 글자에서만 읽어, 게이트 계약의 `args`로 붙는 인자는 보지 않는다(전에도 읽지 않았다). Playwright 설정 파일의 주석에 `grep:` 꼴을 쓰면 부분 실행으로 센다. 검증: 고치기 전 desktop에서 009의 실행을 뺀 변이로 FE-GATE-029 rc=0, 새 단위 시험 17개 실패(변이 저장소에서 tests/e2e를 셈, -c·--config= 못 읽음, 짝 없는 실행을 셈). 고친 뒤 단위 시험 3파일 61개 통과, 같은 변이에서 FE-GATE-029 rc=1 (「Playwright testDir tests/e2e is only partly run … has no gated `--grep @a11y` run to pair with」). 리뷰에서 나온 `-cX`·`-gP`·`-GP` 꼴: parser만 고치기 전으로 되돌린 변이에서 새 시험 4개 실패, 되돌리면 61개 통과. 확인 리뷰에서 나온 `-xGP` 꼴(값 없는 `-x` 뒤에 붙인 옵션)과 `--grep-invert`를 두 번 쓴 실행: 두 고침을 되돌린 변이에서 새 시험 6개 실패, 되돌리면 67개 통과.
85 lines
3.1 KiB
TypeScript
85 lines
3.1 KiB
TypeScript
/**
|
|
* fe-ci-next-12. The `playwright test` runs of a package script command, as
|
|
* FE-GATE-029 (scripts/lib/ungated-tests.ts) and the result path test
|
|
* (tests/unit/playwright-result-paths.test.ts) read them. Each reads the
|
|
* options that pick the config and the tests: `-c`/`--config`, `-g`/`--grep`
|
|
* and `-G`/`--grep-invert`, written as `-c X`, `-cX`, `--config X` or
|
|
* `--config=X` (commander reads all four), and the positional file filters.
|
|
* `-x`, the one short option of `playwright test` with no value, can lead the
|
|
* same token: commander reads `-xG@a11y` as `-x -G@a11y`.
|
|
* A bare token after any other option counts as a file filter: the parser
|
|
* cannot tell whether that option takes a value, and a filter it missed would
|
|
* count tests that do not run.
|
|
*/
|
|
export const DEFAULT_PLAYWRIGHT_CONFIG = "playwright.config.ts";
|
|
|
|
export type PlaywrightTestRun = Readonly<{
|
|
/** The `&&` part of the command that is this run. */
|
|
segment: string;
|
|
config: string;
|
|
grep: readonly string[];
|
|
grepInvert: readonly string[];
|
|
files: readonly string[];
|
|
/** Options it does not read, as written. */
|
|
otherOptions: readonly string[];
|
|
}>;
|
|
|
|
const VALUE_OPTIONS: Readonly<Record<string, "config" | "grep" | "grepInvert">> = {
|
|
"-c": "config",
|
|
"--config": "config",
|
|
"-g": "grep",
|
|
"--grep": "grep",
|
|
"-G": "grepInvert",
|
|
"--grep-invert": "grepInvert",
|
|
};
|
|
|
|
export function playwrightTestRuns(command: string): PlaywrightTestRun[] {
|
|
const runs: PlaywrightTestRun[] = [];
|
|
for (const part of command.split("&&")) {
|
|
const segment = part.trim();
|
|
const tokens = segment.split(/\s+/u);
|
|
const test = tokens.findIndex((token, index) => token === "test" && tokens[index - 1] === "playwright");
|
|
if (test >= 0) runs.push(parseRun(segment, tokens.slice(test + 1)));
|
|
}
|
|
return runs;
|
|
}
|
|
|
|
function parseRun(segment: string, args: readonly string[]): PlaywrightTestRun {
|
|
const values = { config: [] as string[], grep: [] as string[], grepInvert: [] as string[] };
|
|
const files: string[] = [];
|
|
const otherOptions: string[] = [];
|
|
for (let index = 0; index < args.length; index += 1) {
|
|
let token = args[index]!;
|
|
if (token === "--") {
|
|
files.push(...args.slice(index + 1));
|
|
break;
|
|
}
|
|
while (/^-x[^-]/u.test(token)) {
|
|
otherOptions.push("-x");
|
|
token = `-${token.slice(2)}`;
|
|
}
|
|
// Where a value written in the same token starts: after `=` of `--config=X`,
|
|
// after the letter of `-cX`.
|
|
const long = token.startsWith("--");
|
|
const split = long ? token.indexOf("=") : /^-[^-]./u.test(token) ? 2 : -1;
|
|
const key = VALUE_OPTIONS[split >= 0 ? token.slice(0, split) : token];
|
|
const value = key === undefined ? undefined : split >= 0 ? token.slice(long ? split + 1 : split) : args[index + 1];
|
|
if (key !== undefined && value !== undefined) {
|
|
values[key].push(value);
|
|
if (split < 0) index += 1;
|
|
} else if (token.startsWith("-")) {
|
|
otherOptions.push(token);
|
|
} else {
|
|
files.push(token);
|
|
}
|
|
}
|
|
return {
|
|
segment,
|
|
config: values.config.at(-1) ?? DEFAULT_PLAYWRIGHT_CONFIG,
|
|
grep: values.grep,
|
|
grepInvert: values.grepInvert,
|
|
files,
|
|
otherOptions,
|
|
};
|
|
}
|