Skip to content
Back to skills

Vitest Knowledge Patch

ASecurity

Vitest

  • 25 stars
  • 0 votes
  • 0 copies
  • 4 views
  • Added September 5, 2026
developmentnodeexpressdebuggingapi

Works with

  • cli
  • api

Security analysis

A100/100

Pro scans all 8 files and shows the line behind each finding

Scanned December 1, 2026

npx -y skills add Nevaberry/nevaberry-plugins --skill vitest-knowledge-patch --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Vitest Knowledge Patch?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Vitest Knowledge Patch
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/nevaberry-vitest-knowledge-patch-nevaberry-plugins/badge)](https://www.skillsdirectory.com/skills/nevaberry-vitest-knowledge-patch-nevaberry-plugins)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: vitest-knowledge-patch
description: Vitest
version: "5.1.2"
license: MIT
metadata:
  author: Nevaberry
---


# Vitest Knowledge Patch

Load this skill when migrating Vitest configuration, writing tests and fixtures,
configuring Browser Mode, diagnosing runs, or integrating reporters and coverage.
Use the quick reference for common changes and the topic files for full examples
and version-specific behavior.

## Reference index

| Reference | Topics |
| --- | --- |
| [Browser Mode](references/browser-mode.md) | Providers, instances, locators, screenshots, traces, browser mocks, renderers, debugging |
| [Experimental features](references/experimental-features.md) | Cache migration, transform cache keys, native execution, OpenTelemetry, import durations, change providers, experimental UI theme |
| [Migration and configuration](references/migration-and-configuration.md) | Runtime requirements, imports, config discovery, VM behavior, concurrency, CLI selection, watching |
| [Projects and coverage](references/projects-and-coverage.md) | Project discovery, inheritance, ordering, coverage providers, exclusions, thresholds, HTML integration |
| [Reporters and integrations](references/reporters-and-integrations.md) | Reporter migration, destinations, annotations, attempt results, UI authentication, runner APIs, editor integration |
| [Test APIs](references/test-apis.md) | Fixtures, hooks, signals, tags, matchers, mocks, fake timers, snapshots, benchmarks |

## Breaking changes and deprecations

### Runtime, imports, and configuration

Vitest 5 requires Node.js 22+ and Vite 6.4+. It stops publishing `@vitest/runner`;
use public exports from `vitest` for direct imports of test and assertion APIs.
Config discovery searches the current root without walking up parent directories.
From a child package, pass a shared config explicitly:

```sh
vitest run --config ../vitest.config.ts
```

Inline projects inherit the root config and share its Vite server by default.
Remove redundant `extends: true` and check for project-local plugins duplicating
inherited plugins. Keep `test.coverage`, `test.reporters`, and
`test.resolveSnapshotPath` in the root config.

Move `fsModuleCache` from `test.experimental` to `test.fsModuleCache`.
Vitest 5.0.4 enables this cache by default; set `test.fsModuleCache: false` to
disable it. The experimental reference retains the earlier configuration details.

### Test execution, mocks, and assertions

Replace sequential test and suite options with `{ concurrent: false }`.
This also works on a top-level test when `test.sequence.concurrent` is enabled.
The `maxConcurrency` limit includes per-test setup and teardown hooks.

Vitest clears mock call history before each test. Set `test.clearMocks: false`
when tests depend on calls from suite setup or earlier tests. Vitest 5 errors on
hoistable calls such as `vi.mock` and `vi.hoisted` inside tests, hooks, or other
nested scopes; move them to module scope.

Migrate deprecated `toBeCalled*` spy aliases to `toHaveBeenCalled*`.
Vitest fails a test for an unawaited asynchronous assertion. An `expect.poll`
timeout also fails if its callback is still pending at the deadline.
Vitest 5 rejects snapshot assertions in `test.fails` tests.

### Browser migration

Vitest 5 removes `@vitest/browser-webdriverio`. Migrate headless browser projects
to the Playwright provider. Preview simulates browser interactions; use Playwright
for CI and headless runs.

Browser Mode enables `test.browser.locators.exact` by default. For substring
locators, use an explicit option such as `page.getByText('Save', { exact: false })`.
Use `toHaveTextContent('Saved')` for exact text and
`toMatchTextContent('Saved')` for a substring.

Locators are structured objects; update custom integrations that treat them as
selector strings. Browser instances run as workers and count toward `maxWorkers`;
upgrading can reduce how many browsers run at once, including with default settings.
As of Vitest 5.1.0, the Browser Mode server defaults to port `23315`; `test.browser.api` changes it.

### Reports, listing, and CLI changes

Replace the removed `basic` reporter with `default` and `summary: false`.
`tree` always shows the test tree; `verbose` prints each test as it finishes in
local and CI runs. The root-only `test.attachmentsDir` defaults to
`.vitest/attachments/`, including Browser Mode failure screenshots.
The blob reporter and `--merge-reports` default to `.vitest/blob/`; JSON, JUnit,
and HTML reporter output defaults under `.vitest/`.

`vitest list` parses test files statically by default. Use
`vitest list --no-static-parse` for runtime-generated tests. The programmatic
parser is `parseSpecifications`. As of 5.0.1, listing exits with status 1 if
collection fails. As of 5.1.2, `vitest related` rejects `--changed`.

## Tags, selection, and reruns

Declare tags under `test.tags` with a `name`, optional `description`, and shared
test options such as `timeout` or `retry`. A test can inherit several tags.
Unregistered tags throw unless `test.strictTags: false` is set.
Unprioritized tags merge first; lower numeric `priority` takes precedence over
higher values. Explicit test options override tag defaults.

```sh
vitest run --tags-filter='db and !flaky'
vitest run --last-failed
vitest run --since-last-run
```

Tag expressions support `and`/`&&`, `or`/`||`, `not`/`!`, parentheses, and `*`
wildcards. Repeated `--tags-filter` flags combine with AND. Use `tag:` in the UI
filter field and `vitest --list-tags=json` to list tags with configured options.

`--last-failed` selects failures from the previous run. `--since-last-run`
selects tests affected by changes since that run. `--changed` tracks project files
and mocks, runs setup files for selected tests, and includes tests affected by
deleted imports. Change-detection or source-location-filter errors fail the run.
Use `test.watchTriggerPatterns` for changed files outside the import graph.

## Fixtures, hooks, and cancellation

In `test.extend`, use `[fixture, { scope: 'file' }]` for one initialization per
file using the fixture, or `{ scope: 'worker' }` for one per worker. Disable
isolation to reuse worker-scoped fixtures across test files.
`test.extend(name, value)` adds a constant; `test.extend(name, options, factory)`
infers a scoped fixture from the factory return value. `onCleanup` callbacks run
when its scope ends; omit options for a test-scoped factory.

Register `beforeEach` and `afterEach` on the extended test object for typed fixtures.
`beforeAll`, `afterAll`, and `aroundAll` can access file- and worker-scoped fixtures.
Their context replaces the former undocumented `Suite` argument to `beforeAll`
and `afterAll`. `aroundEach` must invoke its first argument to run the test;
`aroundAll` uses the same callback pattern for a suite.

Pass the test context's `signal` to cancellable work. Vitest aborts it on timeout,
when a failure triggers `--bail`, or on Ctrl+C. Cancellation reaches all running
tests, including concurrent tests. In 5.1.1, each attempt gets a fresh signal,
and local `expect.assertions()` and `expect.hasAssertions()` counts reset per retry.

## Browser screenshots and tracing

`toMatchScreenshot` captures the page or the asserted locator. The first run
creates a missing baseline and fails for review. Review and commit the PNG;
use `vitest --update` after intentional changes. Set defaults under
`test.browser.expect.toMatchScreenshot` and override them in assertion options.
Use `test.browser.expect.toMatchScreenshot.screenshotDirectory` to choose the
reference-image directory.

With Playwright, screenshot assertions default to
`screenshotOptions.animations: 'disabled'`. Mask dynamic content with locators in
`screenshotOptions.mask`, and set the viewport with `page.viewport(1280, 720)` or
an instance's `viewport: { width: 1280, height: 720 }`.

Enable Playwright traces with `vitest --browser.trace=on`. Selective modes include
`'on-first-retry'`, `'on-all-retries'`, and `'retain-on-failure'`.
Use `page.mark(name)` or `locator.mark(name)` for markers and
`page.mark(name, callback)` to group actions. `vi.defineHelper()` attributes helper
trace entries to the test's call site and trims helper frames from assertion errors.

The stable Browser Mode trace viewer defaults to failed tests and captures ARIA
snapshots. On failure, Vitest can print each attempt's trace step timeline.
Node trace timelines and the Browser Mode `pointer` API are experimental.

## Mocks, timers, and snapshots

With explicit resource management support, `using mock = vi.fn()` restores the
mock on block exit; the same disposal works with `vi.spyOn`. A disposable from
`vi.doMock` unregisters its mock for subsequent imports when its `using` scope ends.
`vi.when()` configures conditional results; `thenResolve(value)` takes the
resolved value for promise-returning mocks.

After `vi.useFakeTimers()`, `vi.setTimerTickMode('nextTimer')` advances
automatically to scheduled timers; `'manual'` restores explicit advancement.
Fake timers include imports from `node:timers` and `node:timers/promises`.
Use `vi.useFakeTimers({ toNotFake: ['Date'] })` to leave a specific API real.
`vi.setSystemTime()` accepts `Temporal.Instant` and `Temporal.ZonedDateTime`.
Browser actions and `expect.element()` advance the fake clock when fake timers are enabled.

Use `vitest --update=new` for missing snapshots, `vitest --update=all` to refresh
snapshots and remove obsolete ones, or `test.update: 'none'` to disable writes.
Vitest can review failed snapshots interactively. As of 5.1.2, snapshots newly
created by a failed retry attempt are removed.

## Coverage, annotations, and diagnostics

V8 coverage needs a coverage profiler; use `test.coverage.provider: 'istanbul'`
in environments without V8 profiling. Concurrent runs need distinct
`test.coverage.reportsDirectory` paths because sharing a destination fails.
`vitest run --coverage.enabled --coverage.changed` runs all tests and limits
coverage output to changed files.

Use `annotate(message, type)` for a typed message or
`annotate(message, { body: file })` for an attachment. Await it when later work
depends on completion; otherwise Vitest waits before the test finishes.
`verbose` displays passing-test annotations. UI and HTML annotations appear at
call sites in the test file; calls from other files are absent there.
Custom reporters receive annotations through `onTestAnnotate`.
Vitest exposes a result for each retry and repeat.

Run `vitest --detect-async-leaks` for leaked resources and source locations.
`test.experimental.importDurations` supports printing slow imports and failing
on thresholds. Native execution uses `test.experimental.viteModuleRunner: false`,
bypasses Vite transforms, plugins, aliases, and `import.meta.env`.
Use the `v8` coverage provider in this mode; consult the experimental reference
for loader and Node requirements.

Files in this skill

  • SKILL.md10.1 KB
  • coverage.json1.2 KB
  • references/browser-mode.md7.3 KB
  • references/experimental-features.md4.3 KB
  • references/migration-and-configuration.md3.2 KB
  • references/projects-and-coverage.md4.6 KB
  • references/reporters-and-integrations.md3.5 KB
  • references/test-apis.md7.2 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.