by Naima B.

Vitest is a blazing-fast unit and browser testing framework built on Vite, offering Jest-compatible APIs, native ESM support, smart watch mode, code coverage, and component testing for Vue, React, Svelte, and more.
This block delivers the Vitest 5.x core source (packages/vitest/src) — the runtime, node-side orchestration, reporters, environment adapters, and chai/expect integration that make up the Vitest test framework. It is intended for teams embedding or extending Vitest programmatically: custom runners, monorepo tooling, plugin authors, and CI infrastructure builders.
api/ — RPC API surface (check.ts, setup.ts, types.ts) for client-server communication between the test runner and dev toolscreate/ — browser project scaffolding helpers (creator.ts, examples.ts)integrations/chai/ — createExpect factory, chai setup, assertion pollingintegrations/css/ — CSS module scoped-class-name generationintegrations/env/ — built-in environment adapters: node, jsdom, happy-dom, edge-runtimeintegrations/mock/ — date and timer mocking implementationsintegrations/snapshot/ — snapshot chai plugin and environment resolverintegrations/coverage.ts — coverage provider integration pointintegrations/globals.ts — global injection helpersintegrations/spy.ts — spy/mock utilitiesintegrations/vi.ts — the vi global object implementationintegrations/wait.ts — waitFor / waitUntil helpersnode/browser/ — browser mode orchestrationnode/cache/ — VitestCache, result and file-stats cachesnode/cli/ — CLI argument parsing and entrynode/config/ — config resolution pipelinenode/environments/ — node-side environment lifecyclenode/plugins/ — Vite plugin collection (VitestPlugin)node/pools/ — worker pool implementations (vm, threads, forks)node/projects/ — multi-project workspace supportnode/reporters/ — all built-in reporters (, , etc.)Spin up an isolated sandbox and run it server-side — no local setup.
Tetrees AI Review of this version
This TypeScript cli / script completed archive review. Structure, dependency manifests, documentation, functional source, and common risk patterns were checked by the Tetrees verification pipeline; runtime phases are stated separately.
Deterministic AVCP artifact review
Pipeline avcp-2026-08-04.1 · SHA-256 fe3590093e367bff…
This version-scoped review deterministically inspects the submitted archive for structure, dependencies, documentation, functional source, and common malicious or high-risk signals. Build and test phases are reported as passed only after an isolated sandbox audition. It is not a guarantee of perfect security.
Reviewed Aug 4, 2026
Push this product straight into your AI IDE, web builder or cloud IDE.
Connect Tetrees to a compatible AI IDE, list products you own, and request the verified ZIP without exposing seller upload controls.
No reviews yet.
Sign in to join the discussion
Loading discussion…
DefaultReporterJsonReporternode/sequencers/ — test-file ordering strategiesnode/core.ts — Vitest orchestrator classnode/logger.ts — Logger used across node-side codenode/state.ts — global runner stateconstants.ts — shared compile-time constants (defaultPort, etc.)defaults.ts — configDefaults objectpaths.ts — canonical path helpersnpm install vite@^6.0.0 @vitest/expect @vitest/runner @vitest/utils pathe tinybench
npm install --save-dev typescript @types/node
Optional environment packages (install only what you need):
npm install jsdom # for jsdom environment
npm install happy-dom # for happy-dom environment
npm install @edge-runtime/vm # for edge-runtime environment
npm install @vitest/coverage-v8 # v8 coverage
npm install @vitest/coverage-istanbul # istanbul coverage
npm install @vitest/ui # UI reporter
No native build steps are required. Node >= 20.0.0 is mandatory.
Drop the source — copy the source/ directory into your project, e.g. src/vitest-core/.
Alias in tsconfig.json:
{
"compilerOptions": {
"moduleResolution": "bundler",
"target": "ES2022",
"module": "ESNext",
"paths": {
"vitest-core/*": ["./src/vitest-core/*"]
}
}
}
vite.config.ts:import { defineConfig } from 'vite'
export default defineConfig({
resolve: {
alias: {
'vitest-core': '/src/vitest-core',
},
},
})
Environment variables — no required env vars. Optional:
VITEST_MAX_THREADS — override default thread countVITEST_SEGFAULT_RETRY — retry count on segfaultNode version check — assert process.version >= 20.0.0 before bootstrapping.
createExpectimport type { Test, TaskPopulated } from '@vitest/runner'
import type { ExpectStatic } from '@vitest/expect'
function createExpect(test?: Test | TaskPopulated): ExpectStatic
Creates a scoped expect instance bound to an optional test task. The returned object is fully compatible with Jest's expect API. Use this when building a custom test runner that needs assertion counting and snapshot state isolated per test.
environmentsimport type { Environment } from './types/environment'
const environments: {
'node': Environment
'jsdom': Environment
'happy-dom': Environment
'edge-runtime': Environment
}
const envs: string[] = Object.keys(environments)
A map of all built-in test environment adapters keyed by their canonical name. Use environments when implementing a custom project loader that must resolve which DOM/runtime environment to boot for a given test file.
VitestCacheclass VitestCache {
results: ResultsCache
stats: FilesStatsCache
constructor(logger: Logger)
getFileTestResults(key: string): SuiteResultCache | undefined
getFileStats(key: string): { size: number } | undefined
static resolveCacheDir(
root: string,
dir?: string,
projectName?: string
): string
}
Manages persisted test results and file-stat caches across runs. resolveCacheDir computes a deterministic, project-name-hashed subdirectory under node_modules/.vite/vitest/. Use this to implement cache invalidation or to query prior run results without launching the full runner.
VitestPluginimport type { Plugin as VitePlugin } from 'vite'
import type { UserConfig } from './node/types/config'
import { Vitest } from './node/core'
async function VitestPlugin(
options?: UserConfig,
vitest?: Vitest
): Promise<VitePlugin[]>
Returns the full array of Vite plugins that constitute the Vitest build pipeline. Use this when you need to compose Vitest's transform and resolve behaviour into a custom Vite server or plugin chain.
ReportersMapconst ReportersMap: {
'default': typeof DefaultReporter
'agent': typeof AgentReporter
'minimal': typeof AgentReporter
'blob': typeof BlobReporter
'verbose': typeof VerboseReporter
'dot': typeof DotReporter
'json': typeof JsonReporter
'tap': typeof TapReporter
'tap-flat': typeof TapFlatReporter
'junit': typeof JUnitReporter
// ...
}
A string-keyed registry of all built-in reporter constructors. Use this when implementing a reporter loader that resolves reporter names from user config strings to class instances.
A script that exercises createExpect outside of the full test runner, suitable for embedding assertion logic in a CI check tool.
import { createExpect } from './src/vitest-core/integrations/chai/index'
const expect = createExpect()
expect.setState({ assertionCalls: 0 })
expect(1 + 1).toEqual(2)
expect('vitest').toContain('test')
const { assertionCalls } = expect.getState()
console.log(`Assertions executed: ${assertionCalls}`) // 2
Inspect cached results for a file without starting the runner, e.g. in a pre-push hook.
import { resolve } from 'pathe'
import { VitestCache } from './src/vitest-core/node/cache/index'
import type { Logger } from './src/vitest-core/node/logger'
// Minimal logger shim
const logger = {
log: console.log,
error: console.error,
} as unknown as Logger
const root = resolve(process.cwd())
const cacheDir = VitestCache.resolveCacheDir(root, undefined, 'my-project')
console.log('Cache directory:', cacheDir)
const cache = new VitestCache(logger)
await cache.results.readFromCache(cacheDir)
const results = cache.getFileTestResults('src/utils/format.test.ts')
if (results) {
console.log('Last result:', results)
} else {
console.log('No cached result for this file.')
}
Resolve an environment adapter from a user config string and read its name.
import { environments, envs } from './src/vitest-core/integrations/env/index'
console.log('Available environments:', envs)
// ['node', 'jsdom', 'happy-dom', 'edge-runtime']
const envName = (process.env.TEST_ENV ?? 'node') as keyof typeof environments
const env = environments[envName]
if (!env) {
throw new Error(`Unknown environment "${envName}". Valid: ${envs.join(', ')}`)
}
console.log(`Using environment: ${env.name}`)
// Boot the environment for a test suite:
// const ctx = await env.setup(global, options)
Build a custom run pipeline that collects test output as JSON without the CLI.
import { JsonReporter } from './src/vitest-core/node/reporters/index'
import type { Reporter } from './src/vitest-core/node/types/reporter'
const reporter: Reporter = new JsonReporter({ outputFile: 'results.json' })
// Wire into your custom Vitest instance:
// const vitest = await createVitest('test', { reporters: [reporter] })
// await vitest.start()
api/ — Defines the typed RPC channel (check.ts validates the connection, setup.ts registers handlers, types.ts holds shared message types).create/ — Browser project creation wizard: creator.ts scaffolds config, examples.ts provides template strings.integrations/chai/ — Wraps @vitest/expect / chai into the Vitest expect API; poll.ts provides expect.poll for retrying assertions.integrations/css/ — Generates deterministic scoped class names for CSS Modules in tests.integrations/env/ — One file per built-in environment; index.ts exports the keyed map and envs array.integrations/mock/ — date.ts mocks Date; timers.ts implements fake timers via @sinonjs/fake-timers.integrations/snapshot/ — Chai snapshot plugin and environment-aware snapshot resolver.integrations/vi.ts — Implements the vi helper object exposed to test files.integrations/wait.ts — waitFor / waitUntil polling utilities.node/cache/ — VitestCache wraps ResultsCache and FilesStatsCache for incremental runs.node/cli/ — CLI option definitions and the startVitest entry-point wiring.node/config/ — Resolves and validates UserConfig into ResolvedConfig.node/plugins/ — Assembles the Vite plugin array (VitestPlugin) including transform, mock, optimizer plugins.node/pools/ — Thread, fork, and VM-based worker pools.node/reporters/ — All built-in reporters plus ReportersMap registry.node/core.ts — Vitest class: owns the Vite server, projects, reporters, and test lifecycle.node/logger.ts — Logger abstraction used throughout node-side code.node/state.ts — Mutable global runner state shared between orchestrator and pools.constants.ts — defaultPort and other compile-time constants.defaults.ts — configDefaults: the baseline UserConfig applied before user config.paths.ts — Canonical path resolution helpers used across the codebase.--experimental-vm-modules and modern structuredClone; enforce engines: { node: ">=20" } in your package.json."type": "module" or transpile with esbuild/tsup targeting esm.@vitest/expect or @vitest/runner — These are separate workspace packages; install them explicitly — they are not bundled into the source block.jsdom / happy-dom not found at runtime — Environment adapters do a dynamic import(); install the matching package or the environment will throw a module-not-found error at test startup.VitestPlugin requires Vite >= 6 — Passing it to a Vite 5 server will produce type and runtime mismatches; pin vite@^6.0.0.VitestCache.resolveCacheDir hashes the projectName; always pass a unique, stable project name per workspace package to avoid result cache bleed-through.I have dropped the Vitest core source into `src/vitest-core/` in my project.
The integration guide is in `USAGE.md` at the project root.
The upstream package is `@vitest/monorepo` (vitest 5.0.0-beta.1).
Please help me integrate this source step by step:
1. Read `USAGE.md` for the full API reference and working examples.
2. Read `src/vitest-core/node/core.ts` to understand the `Vitest` orchestrator class.
3. Read `src/vitest-core/integrations/chai/index.ts` for `createExpect` usage.
4. Read `src/vitest-core/node/reporters/index.ts` for available reporters.
5. Based on the above, wire up a programmatic Vitest run in `scripts/run-tests.ts`
that: resolves config from `vitest.config.ts`, uses `VitestPlugin` in a Vite
server, selects `JsonReporter` as the output reporter, and writes results to
`test-results.json`.
6. Show me the full `scripts/run-tests.ts` file with correct imports from
`src/vitest-core/`, respecting the ESM-first module system.
7. List any additional `npm install` commands needed beyond what is in `USAGE.md`.
Vitest is released under the MIT License — see source/LICENSE if present, or the canonical copy at github.com/vitest-dev/vitest. Upstream package: vitest / @vitest/monorepo@5.0.0-beta.1.
This product’s unique contribution is clean room implementation of valuable code block into AVCP compatible standard.
The full install guide and integration prompts unlock after purchase.
Automation, Utilities & Developer Tools
Free