@agentable/vitest-config
v0.6.0
Published
Shared Vitest presets for Fleet-family TypeScript libraries, DOM tests, Browser Mode, and packed artifacts.
Maintainers
Readme
@agentable/vitest-config
Shared Vitest 5 presets for source, DOM, browser, and packed-artifact tests.
Installation
pnpm add -D @agentable/vitest-config vitest viteTest a library
import { libraryPreset } from "@agentable/vitest-config";
import { defineConfig } from "vitest/config";
export default defineConfig({
test: { ...libraryPreset },
});libraryPreset uses Node.js and prepares source coverage globs; coverage is opt-in. Type-test
collection and the test tsconfig remain owned by the consumer, which can run
vitest run --typecheck.only with its real project config.
Test DOM behavior
Install jsdom, then use domPreset for React hooks, components, or other lightweight DOM behavior.
pnpm add -D jsdomimport { domPreset } from "@agentable/vitest-config";
import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
...domPreset,
setupFiles: ["./src/test/setup.ts"],
},
});Test in a real browser
Install the Playwright provider and pass the provider plus browser instances to browserPreset.
pnpm add -D @vitest/browser-playwright playwright
pnpm exec playwright install chromiumimport { browserPreset } from "@agentable/vitest-config";
import { playwright } from "@vitest/browser-playwright";
import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
...browserPreset({
provider: playwright(),
instances: [{ browser: "chromium" }],
}),
include: ["src/**/*.browser.test.ts"],
},
});Use --browser.headless in CI. Browser lifecycle and isolation remain owned by Vitest and the
provider.
Collect coverage
Install the coverage provider at the same version as Vitest, then enable coverage explicitly. For Vitest 5.0.3:
pnpm add -D @vitest/[email protected]
pnpm exec vitest run --coverageThe source presets select src/**/*.{js,jsx,ts,tsx}, excluding declarations, tests and mocks. V8 is
Vitest's default provider and supports Node.js and Chromium; Firefox and WebKit require the matching
@vitest/coverage-istanbul package and coverage.provider: "istanbul".
With test.projects, configure coverage on the root test.coverage; project-level coverage options
are ignored. Set coverage.include relative to that root, for example
packages/*/src/**/*.{js,jsx,ts,tsx} for a workspace. Inline projects inherit root configuration, and
arrays such as setupFiles are merged. Keep artifact checks in a separate run so source coverage,
aliases and setup do not carry into them.
Test packed artifacts
Use artifactPreset at the root of a standalone config in a workspace that installs and imports
final tarballs. Run that config independently with vitest run --config vitest.artifact.config.ts.
Do not add source aliases or source coverage to this run; nesting it under a source run cannot
disable the root's coverage.
// vitest.artifact.config.ts
import { artifactPreset } from "@agentable/vitest-config";
import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
...artifactPreset,
include: ["**/*.artifact.test.ts"],
},
});Presets
| Preset | Environment | Project name | Coverage |
| ------------------------ | ------------ | ------------ | --------------------- |
| libraryPreset | Node.js | Consumer | Source globs, opt-in |
| domPreset | jsdom | Consumer | Source globs, opt-in |
| browserPreset(options) | Browser Mode | Consumer | Source globs, opt-in |
| artifactPreset | Node.js | artifact | Disabled (standalone) |
Presets keep Vitest's explicit-import, parallel, reporter, timeout, and mock-lifecycle defaults. Vitest 5 clears mock call history before each test while retaining implementations, uses exact browser locators, and shares the Vite server for eligible inline projects by default.
The Node, DOM and artifact presets disable CommonJS variable injection into ES modules. Use native
ESM APIs such as import.meta.dirname, or createRequire for explicit CommonJS loading. CommonJS
modules retain their own module scope.
Use vitest doctor on the consumer's real suite before selecting a pool or enabling fsModuleCache.
Browser tracing is opt-in through browserPreset({ provider, instances, traceView: true }); it adds
no separate shared API or default recording cost.
Keep optional Vitest providers, coverage packages, and the runner on matching versions. Vitest 5 requires Vite as a host peer; its version range is declared by Vitest.
License
This project is licensed under the MIT License - see the LICENSE file for details.
