@matteo.collina/snap
v0.3.0
Published
snapshot testing companion for node:test
Downloads
1,266
Maintainers
Readme
@matteo.collina/snap
snapshot testing companion for node:test.
Install
npm i @matteo.collina/snap
Usage
import Snap from '@matteo.collina/snap'
import { test } from 'node:test'
import { deepEqual } from 'node:assert/strict'
const snap = Snap(import.meta.url)
test('a snapshot', async (t) => {
const actual = await (await fetch('http://example.com')).text()
const snapshot = await snap(actual)
deepEqual(actual, snapshot)
})
On the first execution, the snapshot will be taked and stored in
the .snapshots
folder in the same directory of package.json
.
To update the snapshot, run with the SNAP_UPDATE=1
env variable set.
Usage with CommonJS
const Snap = require('@matteo.collina/snap')
const { test } = require('node:test')
const { deepEqual } = require('node:assert/strict')
const snap = Snap(__filename)
test('a snapshot', async (t) => {
const actual = await (await fetch('http://example.com')).text()
const snapshot = await snap(actual)
deepEqual(actual, snapshot)
})
License
MIT