문제: 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
79 lines
2.4 KiB
TypeScript
79 lines
2.4 KiB
TypeScript
import type {
|
|
Reporter,
|
|
TestModule,
|
|
TestSpecification,
|
|
Vitest,
|
|
} from "vitest/node";
|
|
|
|
/**
|
|
* 10-04. Vitest counts a skipped or todo test as a pass, so an `it.skip` left
|
|
* behind merges with exit code 0 and the rule that test kept quietly goes
|
|
* away. scripts/run-vitest.ts adds this reporter to every run. It fails the
|
|
* run when a test did not run (`skip`, `todo`, `context.skip()`).
|
|
*
|
|
* A run the caller narrowed on purpose (`-t`, a tag filter, `file:line`)
|
|
* leaves the rest out by design and is exempt. No gate narrows its run.
|
|
* `.only` is refused separately by `allowOnly: false` in vitest.config.ts.
|
|
*/
|
|
|
|
type RunFilters = Readonly<{
|
|
testNamePattern?: RegExp | undefined;
|
|
tagsFilter?: readonly string[] | undefined;
|
|
}>;
|
|
|
|
export function isNarrowedRun(
|
|
config: RunFilters,
|
|
specifications: readonly TestSpecification[],
|
|
): boolean {
|
|
return (
|
|
config.testNamePattern !== undefined ||
|
|
(config.tagsFilter?.length ?? 0) > 0 ||
|
|
specifications.some(
|
|
(specification) =>
|
|
specification.testNamePattern !== undefined ||
|
|
(specification.testLines?.length ?? 0) > 0 ||
|
|
(specification.testIds?.length ?? 0) > 0 ||
|
|
(specification.testTagsFilter?.length ?? 0) > 0,
|
|
)
|
|
);
|
|
}
|
|
|
|
export function unrequestedSkips(
|
|
testModules: readonly TestModule[],
|
|
): string[] {
|
|
return testModules.flatMap((testModule) =>
|
|
[...testModule.children.allTests()]
|
|
.filter((test) => test.result().state === "skipped")
|
|
.map((test) => `${testModule.relativeModuleId} > ${test.fullName}`),
|
|
);
|
|
}
|
|
|
|
export default class NoSkippedTestsReporter implements Reporter {
|
|
#vitest: Vitest | undefined;
|
|
#narrowed = false;
|
|
|
|
onInit(vitest: Vitest): void {
|
|
this.#vitest = vitest;
|
|
}
|
|
|
|
onTestRunStart(specifications: readonly TestSpecification[]): void {
|
|
this.#narrowed = isNarrowedRun(this.#vitest?.config ?? {}, specifications);
|
|
}
|
|
|
|
onTestRunEnd(testModules: readonly TestModule[]): void {
|
|
if (this.#narrowed) return;
|
|
const skipped = unrequestedSkips(testModules);
|
|
if (skipped.length === 0) return;
|
|
process.exitCode = 1;
|
|
process.stderr.write(
|
|
[
|
|
"",
|
|
`${skipped.length} test(s) did not run. A skipped or todo test fails the run (10-04):`,
|
|
...skipped.map((name) => ` - ${name}`),
|
|
"Make the test pass or delete it. To run part of a file on purpose, narrow the run with -t or file:line.",
|
|
"",
|
|
].join("\n"),
|
|
);
|
|
}
|
|
}
|