CodeVetter · Repo Unpack · Testing signals
vitejs/vite
Testing is Vitest-only, split into two configs. `vitest.config.ts` collects 68 unit specs from `**/__tests__/**/*.spec.[tj]s` inside `packages/`, running with `isolate: false` and a 20s timeout. `vitest.config.e2e.ts` collects 109 integration specs from `playground/**`, driving a real Playwright Chromium browser against real Vite servers. The integration suite is the primary correctness net and runs three times in CI — serve, bundled-dev, and build — across Node 20/22/24/26 on Ubuntu plus macOS and Windows. The weakest spot is that unit coverage of the largest files is thin relative to their size: `css.ts` (3685 lines) and `hmr.ts` (1193 lines) have no dedicated unit spec, and are covered only indirectly through playground fixtures.
- Unit tests use `vitest.config.ts` with `include: ['**/__tests__/**/*.spec.[tj]s']`, explicitly excluding `./playground/**` and `./playground-temp/**`, `testTimeout: 20000`, `isolate: false`, and an alias mapping `vite/module-runner` to the TypeScript source rather than `dist`.
- There are 68 unit spec files under `packages/**/__tests__/`, concentrated in `packages/vite/src/node/__tests__/` (config, build, dev, env, html, http, resolve, scan, utils, oxc, packages, shortcuts, external, environment, filterRegex, assetSource) plus `plugins/`, `optimizer/` and `utils/` subdirectories.
- Integration tests use `vitest.config.e2e.ts` with `include: ['./playground/**/*.spec.[tj]s']`, `globalSetup: playground/vitestGlobalSetup.ts`, `setupFiles: playground/vitestSetup.ts`, `reporters: 'dot'`, and a timeout of 50s on CI / 30s locally (Infinity under `PWDEBUG`).
- `vitestGlobalSetup.ts` launches a shared `chromium.launchServer()` (headed when `VITE_DEBUG_SERVE` is set, `--no-sandbox` on CI), shares the endpoint via `project.provide('wsEndpoint', ...)`, then copies only the playground directories actually referenced by the selected test files into `playground-temp/`.
- `vitestSetup.ts` exposes the per-test harness — `page`, `viteTestUrl`, `browserLogs`, `browserErrors`, `serverLogs`, and mode flags `isBuild`/`isServe`/`isBundledDev`/`isBundled` — aliased in tests as `~utils`.
- The same 109 playground specs are executed under three different modes selected by env vars: default serve, `VITE_TEST_BUNDLED_DEV=1` (`test-serve-bundled`), and `VITE_TEST_BUILD=1` (`test-build`), with `NODE_ENV` set to `production` only in the build run.
- Known gaps in bundled-dev mode are tracked as an explicit 22-entry `bundledDevExclude` array in `vitest.config.e2e.ts` — including `fs-serve`, `csp`, `hmr-ssr`, `optimize-deps`, `tailwind` and all four `worker` variants — with the convention that partial failures use `test.skipIf(isBundledDev)` instead of listing the file.
- CI runs the full matrix Node 20/22/24/26 on ubuntu-latest plus macos-latest@24 and windows-latest@24.15.0 (pinned to work around nodejs/node#63638), with `fail-fast: false` and a 20-minute timeout per job.
- The CI `test` job runs all four suites sequentially — `test-unit`, `test-serve`, `test-serve-bundled`, `test-build` — after a `pnpm run build`, and a separate `lint` job runs eslint, `pnpm format && git diff --exit-code`, `pnpm typecheck`, and `pnpm test-docs`.
- CI skips the whole test matrix when only docs, `.github/**` (excluding `ci.yml`), `packages/create-vite/template**`, or `**.md` changed, via a `changed` job using `tj-actions/changed-files` with `only_changed`.
- Flakiness is managed with environment knobs rather than retries in test code: `VITEST_SEGFAULT_RETRY: 3` and `NODE_OPTIONS: --max-old-space-size=6144` are set globally in the workflow env block.
- A scheduled Semgrep scan (`--config auto`, weekly on Tuesdays) uploads SARIF to GitHub code scanning, but explicitly excludes `playground` and `__tests__` and disables the `detect-non-literal-regexp` rule — so dynamic regex construction in source is not flagged.
- Type-level tests exist as a separate mechanism: `src/node/__tests_dts__` and `src/module-runner/__tests_dts__` are compiled by the package `typecheck` script (`tsc -p src/node/__tests_dts__`), using `@type-challenges/utils`.
- Type output is separately validated after bundling: `build-types` runs `rolldown.dts.config.ts` then `tsc --project tsconfig.check.json`, and CONTRIBUTING documents `pnpm run build-types-check` as the guard against d.ts leaking devDependency types.