snapshot testing companion for node:test.
npm i @matteo.collina/snap
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('https://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.
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('https://example.com')).text()
const snapshot = await snap(actual)
deepEqual(actual, snapshot)
})
MIT