Skip to content
/ snap Public
forked from mcollina/snap

snapshot testing companion for node:test

License

Notifications You must be signed in to change notification settings

MoLow/snap

 
 

Repository files navigation

@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('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.

Usage with CommonJS

const Snap = require('@matteo.collina/snap')
const { test } = require('node:test')
const { deepEqual } = require('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)
})

License

MIT

About

snapshot testing companion for node:test

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages

  • JavaScript 88.0%
  • TypeScript 12.0%