Files
clean-architecture-frontend…/tests/unit/playwright-test-args.test.ts
DongHyeonka 32982e5547 ci(gates): FE-GATE-029가 --grep-invert 실행마다 같은 testDir의 --grep 짝을 요구한다
문제: 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개 통과.
2026-11-21 00:36:39 +09:00

83 lines
4.1 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { playwrightTestRuns } from "../../scripts/lib/playwright-test-args.ts";
/**
* fe-ci-next-12. FE-GATE-029 read only `--config X`, so a gate run with
* `-c X` or `--config=X` counted the e2e config's testDir, and it read no
* `--grep`, `--grep-invert` or file filter. The result path test read the
* three config spellings on its own. Both now read the runs here.
*/
const run = (segment: string, fields: Partial<ReturnType<typeof playwrightTestRuns>[number]> = {}) => ({
segment,
config: "playwright.config.ts",
grep: [],
grepInvert: [],
files: [],
otherOptions: [],
...fields,
});
describe("playwright test runs", () => {
it.each([
["playwright test", [run("playwright test")]],
["playwright test -c a.config.ts", [run("playwright test -c a.config.ts", { config: "a.config.ts" })]],
["playwright test --config a.config.ts", [run("playwright test --config a.config.ts", { config: "a.config.ts" })]],
["playwright test --config=a.config.ts", [run("playwright test --config=a.config.ts", { config: "a.config.ts" })]],
["playwright test -ca.config.ts", [run("playwright test -ca.config.ts", { config: "a.config.ts" })]],
["playwright test -g@a11y", [run("playwright test -g@a11y", { grep: ["@a11y"] })]],
["playwright test -G@a11y", [run("playwright test -G@a11y", { grepInvert: ["@a11y"] })]],
["playwright test -x -j2", [run("playwright test -x -j2", { otherOptions: ["-x", "-j2"] })]],
// commander reads the letters after `-x` (no value) as the next short option.
["playwright test -xG@a11y", [run("playwright test -xG@a11y", { grepInvert: ["@a11y"], otherOptions: ["-x"] })]],
["playwright test -xg @smoke", [run("playwright test -xg @smoke", { grep: ["@smoke"], otherOptions: ["-x"] })]],
[
"playwright test -xcplaywright.storybook.config.ts",
[
run("playwright test -xcplaywright.storybook.config.ts", {
config: "playwright.storybook.config.ts",
otherOptions: ["-x"],
}),
],
],
["playwright test -xxj2", [run("playwright test -xxj2", { otherOptions: ["-x", "-x", "-j2"] })]],
["playwright test -g @a11y", [run("playwright test -g @a11y", { grep: ["@a11y"] })]],
["playwright test --grep @a11y", [run("playwright test --grep @a11y", { grep: ["@a11y"] })]],
["playwright test --grep=@a11y", [run("playwright test --grep=@a11y", { grep: ["@a11y"] })]],
["playwright test -G @a11y", [run("playwright test -G @a11y", { grepInvert: ["@a11y"] })]],
["playwright test --grep-invert @a11y", [run("playwright test --grep-invert @a11y", { grepInvert: ["@a11y"] })]],
["playwright test --grep-invert=@a11y", [run("playwright test --grep-invert=@a11y", { grepInvert: ["@a11y"] })]],
[
"playwright test tests/e2e/app-shell.spec.ts --config a.config.ts",
[
run("playwright test tests/e2e/app-shell.spec.ts --config a.config.ts", {
config: "a.config.ts",
files: ["tests/e2e/app-shell.spec.ts"],
}),
],
],
["playwright test -- --odd-name.spec.ts", [run("playwright test -- --odd-name.spec.ts", { files: ["--odd-name.spec.ts"] })]],
// It cannot tell `--project`'s value from a file filter, so it counts a filter.
[
"playwright test --update-snapshots --project chromium",
[
run("playwright test --update-snapshots --project chromium", {
files: ["chromium"],
otherOptions: ["--update-snapshots", "--project"],
}),
],
],
["playwright test --grep", [run("playwright test --grep", { otherOptions: ["--grep"] })]],
[
"CI=1 playwright test -c a.config.ts --grep @a11y && node report.ts && pnpm exec playwright test --config=b.config.ts",
[
run("CI=1 playwright test -c a.config.ts --grep @a11y", { config: "a.config.ts", grep: ["@a11y"] }),
run("pnpm exec playwright test --config=b.config.ts", { config: "b.config.ts" }),
],
],
["node scripts/build.ts && playwright show-report && playwright install --with-deps", []],
])("reads %s", (command, runs) => {
expect(playwrightTestRuns(command)).toEqual(runs);
});
});