문제: 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
92 lines
2.7 KiB
TypeScript
92 lines
2.7 KiB
TypeScript
import { spawnSync } from "node:child_process";
|
|
import { existsSync } from "node:fs";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
function assertSupportedNode(): void {
|
|
const [majorText = "0", minorText = "0"] = process.versions.node.split(".");
|
|
const major = Number(majorText);
|
|
const minor = Number(minorText);
|
|
|
|
if (major !== 24 || minor < 11) {
|
|
process.stderr.write(
|
|
[
|
|
`Unsupported Node.js runtime for tests: ${process.versions.node}`,
|
|
"Required by package.json: >=24.11.0 <25.0.0",
|
|
"Use the repository-supported Node.js runtime before running a test suite.",
|
|
"",
|
|
].join("\n"),
|
|
);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
assertSupportedNode();
|
|
|
|
const vitestEntry = fileURLToPath(
|
|
new URL("../node_modules/vitest/vitest.mjs", import.meta.url),
|
|
);
|
|
if (!existsSync(vitestEntry)) {
|
|
process.stderr.write(
|
|
"Vitest is not installed. Run the repository package installation first.\n",
|
|
);
|
|
process.exit(1);
|
|
}
|
|
|
|
const testEnvironment: NodeJS.ProcessEnv = {
|
|
...process.env,
|
|
NODE_ENV: "test",
|
|
};
|
|
for (const key of [
|
|
"npm_config_userconfig",
|
|
"npm_config_prefix",
|
|
"npm_config_globalconfig",
|
|
"NPM_CONFIG_USERCONFIG",
|
|
"NPM_CONFIG_PREFIX",
|
|
"NPM_CONFIG_GLOBALCONFIG",
|
|
]) {
|
|
delete testEnvironment[key];
|
|
}
|
|
|
|
// src/.generated is gitignored; every suite imports the product index, so a
|
|
// fresh checkout must render it before Vitest resolves the module graph.
|
|
const generated = spawnSync(
|
|
process.execPath,
|
|
[fileURLToPath(new URL("./generate-product-feature-index.ts", import.meta.url))],
|
|
{ stdio: "inherit", env: testEnvironment },
|
|
);
|
|
if (generated.status !== 0) {
|
|
process.stderr.write("Product feature index generation failed.\n");
|
|
process.exit(generated.status ?? 1);
|
|
}
|
|
|
|
// 10-04. Every run fails when a test was skipped or left as todo. A CLI
|
|
// --reporter replaces the config's reporters, so the reporter is added here,
|
|
// where every package script and scale tier starts Vitest. When the caller
|
|
// names no reporter, the default one is kept next to it.
|
|
const callerNamesReporter = process.argv
|
|
.slice(2)
|
|
.some((argument) => argument === "--reporter" || argument.startsWith("--reporter="));
|
|
const reporterArguments = [
|
|
...(callerNamesReporter ? [] : ["--reporter=default"]),
|
|
`--reporter=${fileURLToPath(new URL("./lib/no-skipped-tests-reporter.ts", import.meta.url))}`,
|
|
];
|
|
|
|
const result = spawnSync(
|
|
process.execPath,
|
|
[vitestEntry, ...process.argv.slice(2), ...reporterArguments],
|
|
{
|
|
stdio: "inherit",
|
|
env: testEnvironment,
|
|
},
|
|
);
|
|
|
|
if (result.error) {
|
|
throw result.error;
|
|
}
|
|
if (result.signal) {
|
|
process.stderr.write(`Vitest terminated by signal ${result.signal}.\n`);
|
|
process.exit(1);
|
|
}
|
|
|
|
process.exit(result.status ?? 1);
|