https://github.com/barelyhuman/node-snapshot
A minimal Jest like snapshot testing helper for node:test
https://github.com/barelyhuman/node-snapshot
node snapshot snapshot-testing test testing
Last synced: 4 months ago
JSON representation
A minimal Jest like snapshot testing helper for node:test
- Host: GitHub
- URL: https://github.com/barelyhuman/node-snapshot
- Owner: barelyhuman
- License: mit
- Created: 2024-07-12T14:44:00.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-03-04T18:15:20.000Z (over 1 year ago)
- Last Synced: 2025-12-01T01:57:49.733Z (7 months ago)
- Topics: node, snapshot, snapshot-testing, test, testing
- Language: JavaScript
- Homepage:
- Size: 47.9 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# node-snapshot
> A minimal Jest like snapshot testing helper for node:test
> [!NOTE]
>
> This library is now ESM ONLY (since v1.0.0), use v0 if you wish to stick to
> CJS
> [!NOTE]
> The Library is under active development and might have bugs and issues, please
> report them at
> [barelyhuman/node-snapshot#issues](https://github.com/barelyhuman/node-snapshot/issues)
> to help mature the library
> [!IMPORTANT]
> The author of the library is trying to be a full time open source maintainer
> and your support would be greatly appreciated. You can find out how by reading
> the following [reaper.is/supporters](https://reaper.is/supporters)
### Installation
```sh
; npm install -D @barelyhuman/node-snapshot
```
### Usage
```js
// ESM
import { test } from 'node:test'
import { snapshot } from '@barelyhuman/node-snapshot'
test('foo', t => {
snapshot(t, 'bar')
t.test('foo bar', t => {
snapshot(t, [{ foo: 'bar' }])
})
})
```
- Snapshots are stored at `/snapshots` and should be checked into your
version control. This isn't configurable right now but will soon be.
- Snapshots can be updated by setting `UPDATE_SNAPSHOTS` environment variable to
`1` before running the test suite
```sh
# example
UPDATE_SNAPSHOTS=1 npm run test
```
### Links
- [mcollina/snap](http://github.com/mcollina/snap) - Alternative to this package
- [snapshot Testing](https://jestjs.io/docs/snapshot-testing) - If you wish to
learn more about snapshot testing
### LICENSE
[MIT](/LICENSE)