npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tapshot

v2.2.0

Published

Snapshot assertions for TAP

Downloads

10

Readme

tapshot

Greenkeeper badge Build Status

Tapshot is a helper module for snapshot testing when you are using tools like tap and tape. Tapshot can be used to test any serializable object.

tapshot

Install

$ npm install --save-dev tapshot

Usage

As of V2, tapshot will not automatically add new snapshots or snapshot files. You'll need to pass the 'update' option to save them. See Updating Snapshots for how to do this.

API

tapshot(tap, object[, options])

  • tap object or function: A tap class that has the equal and pass methods. If you're not setting name in options, this also needs to contain a name, which will be provided if you use it within a named subtest
  • object any: The object that you want to snapshot. This can be any serializable object. If it is a non-standard object, a serializer must be provided in options.
  • options object: The options to run the test with. These are all optional:
    • name string: The name for the snapshot
    • file string: The location of the snapshot file you wish to use
    • serializer string or function: The serializer for the object provided if it is a non-standard object. If passed as a string, it will call that method on the object, if passed as a function, the funtion will be called with the object as the only argument.
    • update boolean: If set to true, the snapshot for this test will be updated

tapshot.configure(options)

This will return a tapshot instance that is configured to use the options passed in as defaults. This instance can be used the same as above.

  • options object: The options to configure the tapshot instance with. These are optional:
    • file string: The location of the snapshot file you wish to use
    • update boolean: If set to true, the snapshots will be updated

Updating Snapshots

If you change the structure of the object being snapshotted, you will need to update your snapshots. There are 3 ways to do this:

update Option

Set the update option when calling tapshot. Like so:

tapshot(t, `console.log('this is a string of text')`, {update: true});

This will only update the snapshot for that specific test.

update Configuration Option

Set the update option when calling tapshot.configure(). Like so:

tapshot.configure({update: true});

This will update the snapshots for any tests that use that instance.

Examples

const tap = require(`tap`);
const tapshot = require(`tapshot`);

tap.test(`Generated code is as expected`, (t) => {
    tapshot(t, `console.log('this is a string of text')`);
    t.end();
});
const tap = require(`tap`);
const tapshot = require(`tapshot`);

tap.test(`Generated code is as expected`, (t) => {
    tapshot(t, `console.log('this is a string of text')`, {name: 'generated-code'});
    t.end();
});
const tap = require(`tap`);
const tapshot = require(`tapshot`).configure({update: true});

tap.test(`Generated code is as expected`, (t) => {
    tapshot(t, `console.log('this is a string of text')`);
    t.end();
});

License

MIT © Luke Bonaccorsi