@matteo.collina/snap
TypeScript icon, indicating that this package has built-in type declarations

0.3.0 • Public • Published

@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

/@matteo.collina/snap/

    Package Sidebar

    Install

    npm i @matteo.collina/snap

    Weekly Downloads

    149

    Version

    0.3.0

    License

    MIT

    Unpacked Size

    13 kB

    Total Files

    14

    Last publish

    Collaborators

    • matteo.collina