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 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
e8b116306c
commit
72e7ae1139
@@ -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 <file>` skips that step and fails there with
|
||||
`Failed to resolve import "../.generated/product-feature-index.ts"`.
|
||||
`pnpm test:unit -- <file>` 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.
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user