CI workflow는 전체 env에 VITE_BUILD_ID=gitea-<run>-<attempt>와 VITE_COMMIT_SHA를 둔다. Vite는 이 값을 import.meta.env에 넣는다. 그래서 CI와 같은 env로 돌리면 앱을 local-build fixture release로 조립하는 시험 (runtime-application, boot-unexpected-failure, runtime-composition-service-worker-telemetry)이 CONFIG_BUILD_MISMATCH로 실패한다. 로컬에서는 값이 없어 늘 통과한다. 템플릿 af312dee를 그대로 가져온다. vitest.config.ts가 두 값을 지우고, dev server를 띄우는 Playwright 설정 둘은 webServer env로 VITE_BUILD_ID=local-build, VITE_COMMIT_SHA=local을 준다. build·preview를 쓰는 설정은 빌드가 같은 값으로 config.json을 만들므로 그대로 둔다. 위험·한계: vitest 안에서 CI 빌드 식별값을 검사하려는 시험은 값을 직접 넣어야 한다(지금은 없다). capability e2e(FE-GATE-008)는 돌리지 않았다. 검증: VITE_BUILD_ID를 준 채로 세 component 시험이 통과한다.
63 lines
2.7 KiB
TypeScript
63 lines
2.7 KiB
TypeScript
import { configDefaults, defineConfig } from "vitest/config";
|
|
|
|
// Tests must not inherit a caller's production React/runtime selection.
|
|
// Package scripts also launch Vitest through scripts/run-vitest.ts, which owns
|
|
// NODE_ENV before the Vitest process starts. Keeping the config deterministic
|
|
// protects direct `vitest` invocations as well.
|
|
process.env.NODE_ENV = "test";
|
|
|
|
// Template af312dee. CI sets VITE_BUILD_ID and VITE_COMMIT_SHA for the whole
|
|
// workflow (.gitea/workflows/quality-gates.yml). Vite builds them into
|
|
// `import.meta.env`, so a test that composes the app against its local-build
|
|
// fixture release saw CONFIG_BUILD_MISMATCH in CI and passed everywhere else.
|
|
// Tests start with the local build identity.
|
|
delete process.env["VITE_BUILD_ID"];
|
|
delete process.env["VITE_COMMIT_SHA"];
|
|
|
|
// tests/system needs CI-runner host facilities (see docs/testing/taxonomy.md).
|
|
// It runs only when a caller names it, as `test:system` does; a bare `vitest`
|
|
// run leaves it out.
|
|
const systemTestsRequested = process.argv.some((argument) =>
|
|
argument.replaceAll("\\", "/").replace(/^\.\//u, "").startsWith("tests/system"),
|
|
);
|
|
|
|
export default defineConfig({
|
|
test: {
|
|
globals: false,
|
|
setupFiles: ["./tests/setup.ts"],
|
|
restoreMocks: true,
|
|
clearMocks: true,
|
|
mockReset: true,
|
|
testTimeout: 10_000,
|
|
// A runaway serialization inside a worker (the classic case: an assertion
|
|
// library inspecting a React-rendered DOM node, whose `__reactFiber$*`
|
|
// graph re-expands per traversal path) allocates until the machine's OOM
|
|
// killer takes the whole run down -- 29.5GB and ~40s here, reported as a
|
|
// bare "worker exited" with no failing test named. Capping the worker's
|
|
// old-space turns that into a `Reached heap limit` abort in ~3s, next to
|
|
// the file that caused it. The ceiling is chosen well above real demand:
|
|
// the heaviest suite (`tests/unit`, 126 files) peaks near 1.3GB RSS, of
|
|
// which old-space is only a fraction.
|
|
execArgv: ["--max-old-space-size=2048"],
|
|
// Playwright specs (*.spec.ts) share tests/ but belong to Playwright.
|
|
include: ["tests/**/*.test.{ts,tsx}"],
|
|
exclude: [
|
|
...configDefaults.exclude,
|
|
".tmp/**",
|
|
// A git worktree inside the repository is a different checkout of a
|
|
// different branch. Running its tests against this checkout's config
|
|
// reports failures that belong to neither.
|
|
".worktrees/**",
|
|
"tests/fixtures/v8-coverage-counter-semantics/**",
|
|
...(systemTestsRequested ? [] : ["tests/system/**"]),
|
|
],
|
|
coverage: {
|
|
provider: "v8",
|
|
reportsDirectory: "artifacts/tests/coverage",
|
|
reporter: ["text", "json-summary", "lcov"],
|
|
include: ["src/**/*.{ts,tsx}"],
|
|
exclude: ["**/*.d.ts", "**/*.stories.*"],
|
|
},
|
|
},
|
|
});
|