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-filtering.md

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

Test Filtering

CLI Filtering

By File Path

# Run files containing "user"
vitest user

# Multiple patterns
vitest user auth

# Specific file
vitest src/user.test.ts

# By line number
vitest src/user.test.ts:25

By Test Name

# Tests matching pattern
vitest -t "login"
vitest --testNamePattern "should.*work"

# Regex patterns
vitest -t "/user|auth/"

Changed Files

# Uncommitted changes
vitest --changed

# Since specific commit
vitest --changed HEAD~1
vitest --changed abc123

# Since branch
vitest --changed origin/main

Related Files

Run tests that import specific files:

vitest related src/utils.ts src/api.ts --run

Useful with lint-staged:

// .lintstagedrc.js
export default {
  '*.{ts,tsx}': 'vitest related --run',
}

Focus Tests (.only)

test.only('only this runs', () => {})

describe.only('only this suite', () => {
  test('runs', () => {})
})

In CI, .only throws error unless configured:

defineConfig({
  test: {
    allowOnly: true, // Allow .only in CI
  },
})

Skip Tests

test.skip('skipped', () => {})

// Conditional
test.skipIf(process.env.CI)('not in CI', () => {})
test.runIf(!process.env.CI)('local only', () => {})

// Dynamic skip
test('dynamic', ({ skip }) => {
  skip(someCondition, 'reason')
})

Tags

Tags must be declared in config, then applied to tests/suites and filtered with a tag expression:

// vitest.config.ts
defineConfig({
  test: {
    tags: [{ name: 'db' }, { name: 'slow' }, { name: 'flaky' }],
  },
})

// test file
test('database test', { tags: ['db'] }, () => {})
vitest --tagsFilter "db && !flaky"
vitest --tagsFilter "unit || e2e"
vitest --list-tags            # show defined tags

Full syntax, priority, and per-tag options: see features-test-tags.

Include/Exclude Patterns

defineConfig({
  test: {
    // Test file patterns
    include: ['**/*.{test,spec}.{ts,tsx}'],

    // Exclude patterns
    exclude: [
      '**/node_modules/**',
      '**/e2e/**',
      '**/*.skip.test.ts',
    ],

    // Include source for in-source testing
    includeSource: ['src/**/*.ts'],

    // Scope discovery to a directory (faster than broad excludes)
    dir: './src',
  },
})

v4 simplified default exclude to only node_modules/.git. Prefer test.dir to limit where tests are found; spread configDefaults.exclude to restore the old excludes.

Watch Mode Filtering

In watch mode, press:

  • p - Filter by filename pattern
  • t - Filter by test name pattern
  • a - Run all tests
  • f - Run only failed tests

Projects Filtering

Run specific project:

vitest --project unit
vitest --project integration --project e2e

Environment-based Filtering

const isDev = process.env.NODE_ENV === 'development'
const isCI = process.env.CI

describe.skipIf(isCI)('local only tests', () => {})
describe.runIf(isDev)('dev tests', () => {})

Combining Filters

# File pattern + test name + changed
vitest user -t "login" --changed

# Related files + run mode
vitest related src/auth.ts --run

List Tests Without Running

vitest list                 # Show all test names
vitest list -t "user"       # Filter by name
vitest list --filesOnly     # Show only file paths
vitest list --json          # JSON output

Key Points

  • Use -t for test name pattern filtering
  • --changed runs only tests affected by changes
  • --related runs tests importing specific files
  • Tags provide semantic test grouping
  • Use .only for debugging, but configure CI to reject it
  • Watch mode has interactive filtering
<!-- Source references: - https://vitest.dev/guide/filtering.html - https://vitest.dev/guide/cli.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 2 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.