All skills
onmax avatar

/vitest

@de09c7b official
by Maxonmax/nuxt-skills715 stars
38

Vitest fast unit testing framework powered by Vite with Jest-compatible API. Use when writing tests, mocking, configuring coverage, or working with test filtering and fixtures.

Use this Skill: https://skilld.dev/gh/onmax/nuxt-skills/vitest

This session only. Nothing lands on disk.

referencesfeatures-concurrency.md

≈1.2k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Concurrency & Parallelism

File Parallelism

By default, Vitest runs test files in parallel across workers:

defineConfig({
  test: {
    // Run files in parallel (default: true)
    fileParallelism: true,

    // Max concurrent workers (v4: replaces maxThreads/maxForks; minWorkers removed)
    maxWorkers: 4,

    // Pool type: 'forks' (default), 'threads', 'vmForks', 'vmThreads'
    pool: 'forks',
  },
})

v4 pool rework: poolOptions was removed — all pool settings are now top-level. singleThread/singleFork become maxWorkers: 1, isolate: false. VM memoryLimit is vmMemoryLimit. These can now be set per project.

Concurrent Tests

Run tests within a file in parallel:

// Individual concurrent tests
test.concurrent('test 1', async ({ expect }) => {
  expect(await fetch1()).toBe('result')
})

test.concurrent('test 2', async ({ expect }) => {
  expect(await fetch2()).toBe('result')
})

// All tests in suite concurrent
describe.concurrent('parallel suite', () => {
  test('test 1', async ({ expect }) => {})
  test('test 2', async ({ expect }) => {})
})

Important: Use { expect } from context for concurrent tests.

Opting Out of Concurrency

test.sequential/describe.sequential were removed in v5. Use { concurrent: false }:

describe.concurrent('mostly parallel', () => {
  test('parallel 1', async () => {})

  // Opt this test out of inherited concurrency
  test('must run alone', { concurrent: false }, async () => {})
})

// Or an entire suite
describe('sequential suite', { concurrent: false }, () => {
  test('first', () => {})
  test('second', () => {})
})

Set sequence.concurrent: true to make all tests concurrent by default.

Max Concurrency

Limit concurrent tests:

defineConfig({
  test: {
    maxConcurrency: 5, // Max concurrent tests per file
  },
})

Isolation

Each file runs in isolated environment by default:

defineConfig({
  test: {
    // Disable isolation for faster runs (less safe)
    isolate: false,
  },
})

Sharding

Split tests across machines:

# Machine 1
vitest run --shard=1/3

# Machine 2
vitest run --shard=2/3

# Machine 3
vitest run --shard=3/3

CI Example (GitHub Actions)

jobs:
  test:
    strategy:
      matrix:
        shard: [1, 2, 3]
    steps:
      - run: vitest run --shard=${{ matrix.shard }}/3 --reporter=blob

  merge:
    needs: test
    steps:
      - run: vitest --merge-reports --reporter=junit

Merge Reports

# Each shard outputs blob
vitest run --shard=1/3 --reporter=blob --coverage
vitest run --shard=2/3 --reporter=blob --coverage

# Merge all blobs
vitest --merge-reports --reporter=json --coverage

Test Sequence

Control test order:

defineConfig({
  test: {
    sequence: {
      // Run tests in random order
      shuffle: true,

      // Seed for reproducible shuffle
      seed: 12345,

      // Hook execution order
      hooks: 'stack', // 'stack', 'list', 'parallel'

      // All tests concurrent by default
      concurrent: true,

      // Order projects/groups run in (3.2+); lower runs first
      groupOrder: 0,
    },
  },
})

Shuffle Tests

Randomize to catch hidden dependencies:

// Via CLI
vitest --shuffle

// Per suite
describe.shuffle('random order', () => {
  test('test 1', () => {})
  test('test 2', () => {})
  test('test 3', () => {})
})

Pools (v4)

poolOptions was removed; pool settings are now top-level and can be set per project:

defineConfig({
  test: {
    pool: 'forks',     // 'forks' (default) | 'threads' | 'vmForks' | 'vmThreads'
    maxWorkers: 8,
    isolate: true,     // threads/forks only; vm* pools are always isolated
    vmMemoryLimit: '512MB',
  },
})

For per-project parallelism/isolation settings, see advanced-projects.

Bail on Failure

Stop after first failure:

vitest --bail 1    # Stop after 1 failure
vitest --bail      # Stop on first failure (same as --bail 1)

Key Points

  • Files run in parallel by default (pool: 'forks'); tests within a file run sequentially unless .concurrent
  • concurrent only speeds up tests that await (I/O, timers); pure sync tests still block the thread
  • Always use context's expect in concurrent tests
  • Use { concurrent: false } (not .sequential) to opt out
  • maxWorkers (not maxThreads/maxForks); poolOptions removed in v4
  • Sharding splits tests across CI machines; --merge-reports combines blob results
<!-- Source references: - https://vitest.dev/guide/parallelism.html - https://vitest.dev/guide/improving-performance.html -->

Source: SKILL.md on GitHub

No alerts9d5 checks · Risk SAFE
  • Gen Agent Trust Hub9d

    The skill is a comprehensive documentation set for the Vitest testing framework, providing configuration examples, API references, and CLI usage. No security issues were identified.

  • Socket9d

    No alerts

  • Snyk9d

    Risk: LOW · No issues

  • Runlayer7mo

    1/6 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at de09c7b. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 3 days ago.

Activeupdated last week
Other metadata
metadata
{
  "author": "Anthony Fu",
  "version": "2026.6.22",
  "source": "Generated from https://github.com/vitest-dev/vitest, scripts located at https://github.com/antfu/skills"
}

README badge

README badge for onmax/nuxt-skills/vitest

Configures and runs Vitest for unit and integration testing in Vite projects, with Jest-compatible syntax for writing test suites, mocking modules and timers, and executing tests in parallel. Use this when setting up test infrastructure for Vue, React, or Svelte components, or when writing type tests with TypeScript.

Generated from the current SKILL.md.

Does Vitest work with Vue, React, and Svelte components?
Yes. Vitest can test components from Vue, React, and Svelte. For component-specific patterns, the skill references a separate `vue` skill.
What environments does Vitest support for testing?
Vitest supports `node` and `jsdom` environments by default, with additional options for browser mode and type testing covered in the advanced reference.
Can I use Jest syntax with Vitest?
Yes. Vitest has a Jest-compatible API, so you can use familiar patterns like describe, it, expect, vi.fn, and vi.mock without syntax changes.
Does this skill cover mocking and test fixtures?
Yes. The skill includes reference files for mocking modules and timers with vi.fn and vi.mock, as well as test hooks and fixtures.

Generated from the current SKILL.md. These answers refresh after source changes.