@wtf/project-vitest
Documentation / @wtf/project-vitest
The shared Vitest configs for a pnpm workspace. They run every package’s tests from the root, from
source with nothing built first, or from the build (TEST_FROM=dist), with coverage for either.
Vitest ^5.0.5 is a peer dependency. @vitest/coverage-v8 and @vitest/browser-playwright, at
the same version, and playwright are optional peers, for coverage and for browser tests. A repo
names each at its root by the one exact version, 5.0.5, since the configs run in the Vitest that
runs them. Vite comes from @wtf/project-vite, a dependency.
| Subpath | What you get |
|---|---|
./config | rootConfig(), packageConfig(), integrationConfig(), integration, FROM_DIST, GUARD_TIMEOUT |
./process | childEnv(): the environment for a process a test starts, without the resolve hook |
./browser | browserConfig() and browserRootConfig(): browser tests, in Chromium |
./storybook | storybookConfig(): for a package whose stories are its tests, each in Chromium |
// vitest.config.ts, at the rootimport { rootConfig } from '@wtf/project-vitest/config'
export default rootConfig()import { packageConfig } from '@wtf/project-vitest/config'
export default packageConfig()packageConfig(test, config) takes the test options, and a Vite config to merge, such as
{ resolve: { dedupe: ['react'] } }.
The guards, in the root’s root project, get 30 seconds per test, GUARD_TIMEOUT, the same as a
package’s tests, instead of Vitest’s 5. Pass another with rootConfig({ testTimeout: 60_000 }).
When tests run from source, Vite resolves each workspace package through an alias from each export
to its @wtf/source, and each test worker registers @wtf/project-resolve’s resolve hook, in
Node’s environment or in jsdom’s. See the tests guide.
A package whose stories are its tests runs them with storybookConfig({ storybook }) from
./storybook. It is a browserConfig() named storybook, whose tests are the stories that
@storybook/addon-vitest’s plugin, storybookTest(), finds in the package’s .storybook. The repo
installs the addon at its Storybook’s version; nothing here depends on Storybook.
