Back to Dagger

Vitest

docs/current_docs/modules/vitest.mdx

0.21.52.3 KB
Original Source

Vitest

Official module: dagger/vitest

Install with dagger mod install github.com/dagger/vitest.

What It Is

The Vitest module runs Vitest tests for JavaScript and TypeScript projects.

Use it when the project uses Vitest, especially Vite apps and modern frontend packages.

Use It For

  • Run Vitest as a workspace check.
  • Validate frontend packages and libraries.
  • List discovered tests when test selection is unclear.

Main Workflows

  • test: run the Vitest suite.
  • list: show which tests Vitest sees.

How to Use It

Install the module, then run its check:

bash
dagger mod install github.com/dagger/vitest

dagger check            # run every check in the workspace
dagger check vitest:test # run the Vitest suite

test installs dependencies and runs the Vitest suite over the workspace (excluding node_modules, dist, and build). It automatically registers an OpenTelemetry hook, so individual tests appear as spans in the Dagger TUI and Dagger Cloud without changing the project's Vitest config.

Settings

List the current settings and their values with dagger settings vitest, then set one with dagger settings vitest <key> <value>. Settings are stored in .dagger/config.toml under [modules.vitest.settings].

  • packageManager (default npm): the package manager used to install dependencies before testing. Set it to yarn or pnpm to match the project; with pnpm, the module enables Corepack automatically.
  • baseImageAddress (default node:25-alpine): the Node base image tests run in. Pin it to the project's Node version, for example node:22-alpine.
toml
[modules.vitest.settings]
packageManager = "pnpm"
baseImageAddress = "node:22-alpine"

Test options

The vitest:test check runs with default options. Call the test function directly with dagger function call to override them:

  • files: limit the run to specific test files.
  • build: run the project's build script before testing.
  • flags: extra flags passed through to vitest.

Use list to print the tests Vitest discovers when test selection is unclear.

Workspace Fit

Use this module when Vitest is the test runner. Use Jest instead for projects that already depend on Jest conventions and config.

Source

Source repo: github.com/dagger/vitest