From 72e7ae1139ee8ff82580cb9f3f29a92c5f69cad8 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Sat, 26 Sep 2026 00:22:16 +0900 Subject: [PATCH] test(vitest): collect only Vitest files and document running one file (10-05) A bare vitest run collected 26 Playwright specs and the host-bound system suite. The documented one-file command goes through run-vitest.ts, which renders the gitignored product index a fresh clone lacks. Co-Authored-By: Claude Opus 5.5 --- docs/testing/taxonomy.md | 18 ++++++++++++ tests/integration/vitest-collection.test.ts | 31 +++++++++++++++++++++ vitest.config.ts | 10 +++++++ 3 files changed, 59 insertions(+) create mode 100644 tests/integration/vitest-collection.test.ts diff --git a/docs/testing/taxonomy.md b/docs/testing/taxonomy.md index 421a3d6d..d1ce9feb 100644 --- a/docs/testing/taxonomy.md +++ b/docs/testing/taxonomy.md @@ -37,6 +37,24 @@ That runner: `vitest.config.ts` also fixes `NODE_ENV=test` so a direct Vitest invocation cannot accidentally select React's production behavior. +To run one test file, use the same runner: + +```sh +node scripts/run-vitest.ts run tests/component/router.test.tsx +``` + +The runner renders the gitignored `src/.generated/` product index first +(`scripts/run-vitest.ts`), so this works in a fresh clone. A direct +`pnpm exec vitest run ` skips that step and fails there with +`Failed to resolve import "../.generated/product-feature-index.ts"`. +`pnpm test:unit -- ` does not narrow the run, because the script already +passes the whole `tests/unit` directory. + +`vitest.config.ts` collects only `tests/**/*.test.{ts,tsx}`; Playwright +`*.spec.ts` files are not Vitest tests. `tests/system/` is collected only when +the command names it, as `test:system` does, so a bare `vitest` run does not +start the CI-runner suite. + The system suite additionally runs `scripts/check-system-test-prerequisites.ts` and fails with one prerequisite report when the CI-runner host does not provide its required Linux facilities. diff --git a/tests/integration/vitest-collection.test.ts b/tests/integration/vitest-collection.test.ts new file mode 100644 index 00000000..7ca0cfe4 --- /dev/null +++ b/tests/integration/vitest-collection.test.ts @@ -0,0 +1,31 @@ +import { spawnSync } from "node:child_process"; + +import { describe, expect, it } from "vitest"; + +function listTestFiles(...filters: string[]): string[] { + const result = spawnSync( + process.execPath, + ["node_modules/vitest/vitest.mjs", "list", "--filesOnly", ...filters], + { encoding: "utf8" }, + ); + expect(result.status, result.stderr).toBe(0); + return result.stdout.split("\n").filter((line) => line.length > 0); +} + +describe("Vitest file collection", () => { + it("leaves Playwright specs and host system tests out of a bare run", () => { + const files = listTestFiles(); + + expect(files).toContain("tests/integration/vitest-collection.test.ts"); + expect(files.filter((file) => file.endsWith(".spec.ts"))).toEqual([]); + expect(files.filter((file) => file.startsWith("tests/system/"))).toEqual( + [], + ); + }, 30_000); + + it("still collects system tests when test:system names them", () => { + expect(listTestFiles("tests/system")).toContain( + "tests/system/ci-runner/ci-evidence-freshness.test.ts", + ); + }, 30_000); +}); diff --git a/vitest.config.ts b/vitest.config.ts index b46a2507..9235ef63 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -6,6 +6,13 @@ import { configDefaults, defineConfig } from "vitest/config"; // protects direct `vitest` invocations as well. process.env.NODE_ENV = "test"; +// 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, @@ -14,6 +21,8 @@ export default defineConfig({ clearMocks: true, mockReset: true, testTimeout: 10_000, + // Playwright specs (*.spec.ts) share tests/ but belong to Playwright. + include: ["tests/**/*.test.{ts,tsx}"], exclude: [ ...configDefaults.exclude, ".tmp/**", @@ -22,6 +31,7 @@ export default defineConfig({ // reports failures that belong to neither. ".worktrees/**", "tests/fixtures/v8-coverage-counter-semantics/**", + ...(systemTestsRequested ? [] : ["tests/system/**"]), ], coverage: { provider: "v8",