문제: Vitest는 skip·todo 테스트를 통과로 센다. `it.skip`이나
`it.todo`가 든 파일은 CI=true에서도 종료 코드 0으로 끝난다.
`context.skip()`도 같다. `.only`는 Vitest 기본값 때문에 CI에서만 막히고,
로컬에서는 같은 파일의 나머지 테스트를 조용히 건너뛴다.
check:test-evidence의 소스 검사가 quarantine 주석 없는 `.skip(`·`.only(`
글자를 잡지만, `it.todo`, `context.skip()`, `skipIf`는 보지 못한다.
고른 방법:
- vitest.config.ts에 allowOnly: false를 둬 `.only`를 어디서나 막는다.
- scripts/lib/no-skipped-tests-reporter.ts reporter가 실행 끝에
state가 skipped인 테스트를 찾으면 이름을 출력하고 exitCode를 1로 둔다.
-t, 태그 필터, file:line처럼 호출자가 일부러 좁힌 실행은 예외다.
게이트는 실행을 좁히지 않는다.
- reporter는 scripts/run-vitest.ts가 붙인다. CLI --reporter는 config의
reporters를 대체하므로 config에 두면 package script에서 빠진다.
run-vitest.ts는 package script와 scale tier가 모두 거치는 입구다.
호출자가 reporter를 하나도 주지 않으면 default를 함께 붙인다.
버린 대안:
- 리뷰 최소 개선안의 junit `skipped > 0` 검사: Vitest junit은 mode가
skip·todo인 테스트만 <skipped/>로 적고 `context.skip()`은 통과처럼
적는다. junit을 쓰지 않는 실행(scale tier, http-scenario-catalog,
로컬 단일 파일)은 아예 보지 못한다.
- tests/setup.ts의 afterAll 검사: 모든 테스트가 skip인 파일은 hook이
돌지 않아 잡지 못한다.
- eslint-plugin-vitest no-disabled-tests: 새 의존성이 생기고
`context.skip()`을 못 잡는다.
위험·한계:
- run-vitest.ts를 거치지 않는 직접 `vitest` 실행에는 reporter가 붙지
않는다. allowOnly는 config라서 그때도 적용된다.
- 호출자가 reporter를 주지 않으면 default reporter를 고정해서 붙인다.
Vitest가 AI 에이전트 환경에서 고르는 agent reporter 대신 default가
나온다.
- 본문 없는 `describe.todo`처럼 테스트가 없는 묶음은 세지 않는다.
- check:test-evidence는 quarantine 주석이 있는 `.skip(`을 허용하지만
이 reporter는 Vitest에서 그것도 실패시킨다. 지금 quarantine은
Playwright spec에만 있어 충돌하는 테스트는 없다. 전략 문서 16.5절에
"quarantine은 Vitest 테스트를 통과시키지 않는다"고 적었다. Vitest에도
quarantine이 필요해지면 허용 목록을 따로 둬야 한다.
- 지금 저장소의 Vitest 테스트에는 skip·todo·only가 없다.
검증:
- RED(P-B 재현, run-vitest.ts로 skip+todo, only, context.skip() 파일을
CI 없음/CI=true로): 수정 전 6경우 중 5경우 exit 0("1 passed | 1
skipped | 1 todo"). only+CI=true만 exit 1.
- 새 tests/unit/no-skipped-tests-reporter.test.ts는 수정 전 "Cannot find
module ../../scripts/lib/no-skipped-tests-reporter.ts"로 실패.
- GREEN: 같은 6경우 모두 exit 1. skip·todo·context.skip()은 "N test(s)
did not run" 목록, only는 "Unexpected .only modifier". junit reporter를
준 실행도 exit 1. -t로 좁힌 실행과 file:line 실행은 exit 0. 새 테스트
11 passed.
- 빠른 계층 전체(unit·component·integration·contract·runtime-schema·
platform·architecture·features·release·scripts·recipes, pnpm 설치를
하는 fixture-node-modules.test.ts 제외, maxWorkers 4): 3,228 passed,
1 failed. 실패는 provider-guardian-transaction의 fs.watch ENOSPC(호스트
inotify 한도)이고 reporter 없이 vitest를 직접 돌려도 같다. skip 목록
출력은 없었다.
- tsc -p tsconfig.node.json, tsconfig.test.json, eslint(바꾼 4파일),
check-ci-contract, generate-ci-workflow --check,
verify-documentation-readiness(PASS_SCOPED) 통과.
Refs: docs/reviews/2026-11-01-maturity-review/10-tests-fast-layers.md 10-04
99 lines
2.8 KiB
TypeScript
99 lines
2.8 KiB
TypeScript
import { readFileSync } from "node:fs";
|
|
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import vitestConfig from "../../vitest.config.ts";
|
|
import {
|
|
isNarrowedRun,
|
|
unrequestedSkips,
|
|
} from "../../scripts/lib/no-skipped-tests-reporter.ts";
|
|
|
|
// 10-04. A skipped or todo test must fail the run, unless the caller asked
|
|
// for a narrower run on purpose.
|
|
|
|
function testModule(
|
|
relativeModuleId: string,
|
|
tests: readonly (readonly [string, string])[],
|
|
) {
|
|
return {
|
|
relativeModuleId,
|
|
children: {
|
|
*allTests() {
|
|
for (const [fullName, state] of tests) {
|
|
yield { fullName, result: () => ({ state }) };
|
|
}
|
|
},
|
|
},
|
|
};
|
|
}
|
|
|
|
describe("unrequestedSkips", () => {
|
|
it("names every test that did not run, whatever skipped it", () => {
|
|
expect(
|
|
unrequestedSkips([
|
|
testModule("tests/unit/a.test.ts", [
|
|
["runs", "passed"],
|
|
["it.skip", "skipped"],
|
|
["it.todo", "skipped"],
|
|
]),
|
|
testModule("tests/unit/b.test.ts", [
|
|
["fails", "failed"],
|
|
["context.skip()", "skipped"],
|
|
]),
|
|
] as never),
|
|
).toEqual([
|
|
"tests/unit/a.test.ts > it.skip",
|
|
"tests/unit/a.test.ts > it.todo",
|
|
"tests/unit/b.test.ts > context.skip()",
|
|
]);
|
|
});
|
|
|
|
it("is empty when every test ran", () => {
|
|
expect(
|
|
unrequestedSkips([
|
|
testModule("tests/unit/a.test.ts", [
|
|
["runs", "passed"],
|
|
["fails", "failed"],
|
|
]),
|
|
] as never),
|
|
).toEqual([]);
|
|
});
|
|
});
|
|
|
|
describe("isNarrowedRun", () => {
|
|
const whole = { testNamePattern: undefined, tagsFilter: undefined };
|
|
const spec = {
|
|
testLines: undefined,
|
|
testIds: undefined,
|
|
testNamePattern: undefined,
|
|
testTagsFilter: undefined,
|
|
};
|
|
|
|
it("treats a run of whole files as not narrowed", () => {
|
|
expect(isNarrowedRun(whole, [spec, spec] as never)).toBe(false);
|
|
expect(isNarrowedRun(whole, [] as never)).toBe(false);
|
|
});
|
|
|
|
it.each([
|
|
["-t <pattern>", { ...whole, testNamePattern: /name/u }, spec],
|
|
["--tags-filter", { ...whole, tagsFilter: ["slow"] }, spec],
|
|
["file:line", whole, { ...spec, testLines: [12] }],
|
|
["test ids", whole, { ...spec, testIds: ["abc_0"] }],
|
|
["a per-file name pattern", whole, { ...spec, testNamePattern: /x/u }],
|
|
["a per-file tag filter", whole, { ...spec, testTagsFilter: ["a"] }],
|
|
])("treats %s as a run narrowed on purpose", (_label, config, narrowed) => {
|
|
expect(isNarrowedRun(config, [spec, narrowed] as never)).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe("wiring", () => {
|
|
it("refuses .only locally as well as in CI", () => {
|
|
expect(vitestConfig.test?.allowOnly).toBe(false);
|
|
});
|
|
|
|
it("adds the reporter to every run that goes through run-vitest.ts", () => {
|
|
const runner = readFileSync("scripts/run-vitest.ts", "utf8");
|
|
expect(runner).toContain("./lib/no-skipped-tests-reporter.ts");
|
|
});
|
|
});
|