Socket
Book a DemoInstallSign in
Socket

@onigoetz/ntr-expect-snapshot

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@onigoetz/ntr-expect-snapshot

Node.js Test Runner is great, Expect is great, Snapshots are great.

0.4.0
latest
npmnpm
Version published
Maintainers
1
Created
Source

Node.js Test Runner - expect().toMatchSnapshot() integration

Node.js Test Runner is great, Expect is great, Snapshots are great.

But using them all together at the moment is ... not so great.

This package aims to provide an easy approach to use .toMatchSnapshot with Node.js Test Runner.

Install

yarn add @onigoetz/ntr-expect-snapshot expect

Usage

import { test } from "node:test";

import initializeSnapshot from "@onigoetz/ntr-expect-snapshot";
import { expect } from "expect";

initializeSnapshot(import.meta.url);

test("a snapshot", async () => {
  const response = await fetch("http://example.com");
  const actual = await response.text();

  expect(actual).toMatchSnapshot();
});

Updating snapshots

Updating snapshots is enabled if the --test-update-snapshots (Possible statring with Node.js 22.3.0) flag is passed or the SNAPSHOT_UPDATE environment variable is set to "true"

Shortcomings

Snapshot management is usually tightly integrated within the test runner to offer features such as partial updates when tests are skipped or removing snapshot files when they're no longer needed.

This package can't be integrated tightly with Node.js test runner and here are some things that will probably not be possible to implement:

Remove a snapshot file if the test file is deleted

We are only aware of the current running test files, not other test files so we don't know which other files are or are not present

Remove a snapshot after a test is removed

The fact that a snapshot isn't used in a test run can be due to the test being currently skipped, or tests being filtered. For this reason we can't decide to remove all snapshots for a test at this stage.

Credits / Previous work in the domain

The initial implementation is for most parts a fork of AVA's implementation.

I also checked how other tools in the space work to build a coherent approach

Keywords

snapshot

FAQs

Package last updated on 29 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.