# @vitest/snapshot

> Vitest snapshot manager

Latest version **5.0.1** (published 2026-09-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install @vitest/snapshot
pnpm add @vitest/snapshot
yarn add @vitest/snapshot
bun add @vitest/snapshot
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; popular repo.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 5.0.1 |
| Published | 2026-09-15 |
| First published | 2023-04-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 59.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 17123 |
| Maintainers | ariperkkio, antfu, hiogawa, oreanno, yyx990803 |
| Keywords | vitest, test, snapshot |

## Links

- npm: https://www.npmjs.com/package/@vitest/snapshot
- Repository: https://github.com/vitest-dev/vitest
- Homepage: https://vitest.dev/guide/snapshot
- Issues: https://github.com/vitest-dev/vitest/issues
- Funding: https://opencollective.com/vitest
- npm.io page: https://npm.io/package/@vitest/snapshot

## Dependencies (4)

- [pathe](https://npm.io/package/pathe.md) ^2.0.3
- [magic-string](https://npm.io/package/magic-string.md) ^1.2.3
- [@vitest/utils](https://npm.io/package/@vitest/utils.md) 5.0.1
- [@vitest/pretty-format](https://npm.io/package/@vitest/pretty-format.md) 5.0.1

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 5.0.1 (latest) — 2026-09-15
- 5.0.0-rc.4 (rc) — 2026-08-31
- 5.0.0-beta.7 (beta) — 2026-07-24
- 3.2.7 (V3) — 2026-07-06
- 5.0.0 — 2026-09-03
- 5.0.0-rc.3 — 2026-08-28
- 4.1.11 — 2026-08-18
- 5.0.0-rc.2 — 2026-08-17
- 5.0.0-rc.1 — 2026-08-11
- 5.0.0-beta.6 — 2026-07-06
- 4.1.10 — 2026-07-06
- 5.0.0-beta.5 — 2026-06-15
- 4.1.9 — 2026-06-15
- 3.2.6 — 2026-06-01
- 5.0.0-beta.4 — 2026-06-01
- … 173 more at https://npm.io/package/@vitest/snapshot/versions

## README

# @vitest/snapshot

[![NPM version](https://img.shields.io/npm/v/@vitest/snapshot?color=a1b858&label=)](https://npmx.dev/package/@vitest/snapshot)

Lightweight implementation of Jest's snapshots.

## Usage

```js
import { SnapshotClient } from '@vitest/snapshot'
import { NodeSnapshotEnvironment } from '@vitest/snapshot/environment'
import { SnapshotManager } from '@vitest/snapshot/manager'

const client = new SnapshotClient({
  // you need to provide your own equality check implementation if you use it
  // this function is called when `.toMatchSnapshot({ property: 1 })` is called
  isEqual: (received, expected) =>
    equals(received, expected, [iterableEquality, subsetEquality]),
})

// class that implements snapshot saving and reading
// by default uses fs module, but you can provide your own implementation depending on the environment
const environment = new NodeSnapshotEnvironment()

// you need to implement this yourselves,
// this depends on your runner
function getCurrentFilepath() {
  return '/file.spec.js'
}
function getCurrentTestName() {
  return 'test1'
}

// example for inline snapshots, nothing is required to support regular snapshots,
// just call `assert` with `isInline: false`
function wrapper(received) {
  function __INLINE_SNAPSHOT__(inlineSnapshot, message) {
    client.assert({
      received,
      message,
      isInline: true,
      inlineSnapshot,
      filepath: getCurrentFilepath(),
      name: getCurrentTestName(),
    })
  }
  return {
    // the name is hard-coded, it should be inside another function, so Vitest can find the actual test file where it was called (parses call stack trace + 2)
    // you can override this behaviour in SnapshotState's `_inferInlineSnapshotStack` method by providing your own SnapshotState to SnapshotClient constructor
    toMatchInlineSnapshot: (...args) => __INLINE_SNAPSHOT__(...args),
  }
}

const options = {
  updateSnapshot: 'new',
  snapshotEnvironment: environment,
}

await client.startCurrentRun(
  getCurrentFilepath(),
  getCurrentTestName(),
  options
)

// this will save snapshot to a file which is returned by "snapshotEnvironment.resolvePath"
client.assert({
  received: 'some text',
  isInline: false,
})

// uses "pretty-format", so it requires quotes
// also naming is hard-coded when parsing test files
wrapper('text 1').toMatchInlineSnapshot()
wrapper('text 2').toMatchInlineSnapshot('"text 2"')

const result = await client.finishCurrentRun() // this saves files and returns SnapshotResult

// you can use manager to manage several clients
const manager = new SnapshotManager(options)
manager.add(result)

// do something
// and then read the summary

console.log(manager.summary)
```

[GitHub](https://github.com/vitest-dev/vitest/tree/main/packages/snapshot) | [Documentation](https://vitest.dev/guide/snapshot)

---
_Source: https://npm.io/package/@vitest/snapshot · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
