Skip to main content
Install @varianz/vitest (instructions) and wire it up once:
The re-exports above are deliberate. @varianz/vitest exports varianzVitest, cel and the matchers — not test or expect. Take test from varianzVitest({...}) and expect / describe from vitest itself. The example inside the package’s own shipped fixture.d.ts JSDoc says import { test, expect, cel } from "@varianz/vitest"; that line is wrong and does not resolve.
If your tsconfig has declaration: true — the default for anything emitting .d.ts — this snippet fails to compile:
Exclude the test tsconfig from declaration emit ("declaration": false), which is what you almost certainly want for tests anyway.
Run with the standard environment (VARIANZ_ENABLED=true, and VARIANZ_INSECURE_ALLOW_PLAINTEXT=true for a plaintext local coordinator) — the fixture throws a clear error if the SDK is disabled.

Writing tests

Fixtures:
  • varianz — per-test VarianzTestSession. It installs a session-ID fallback in AsyncLocalStorage for the whole test body, so in-process VPoint calls match your stages automatically.
  • varianzClient — worker-scoped client for advanced coordinator assertions (most tests don’t need it).

Custom matchers

Installed by the @varianz/vitest/setup file:

Session API

Concurrency

In describe.concurrent / it.concurrent blocks, the module-level session fallback is last-write-wins and races under true parallelism. Re-establish the scope locally:
And keep fileParallelism: false — the native initCoordinator binding can only initialize once per process.