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

bats-snapshot

v0.2.0

Published

Snapshot test for bats

Downloads

1

Readme

bats-snapshot

bats-snapshot is a helper library providing snapshot assertions for Bats. This package is based on bats-assert

Dependencies:

  • [bats-support][bats-support] (formerly bats-core) - output formatting
  • [bats-assert][bats-assert] (formerly bats-core) - assertions

Install

In bats test

load '../node_modules/bats-support/load'
load '../node_modules/bats-assert/load'
load '../node_modules/bats-snapshot/load'

Usage

assert_snapshot

Fail if the output is not the same as snapshot

In first time calling, it will save the status and output into ./__snapshot__. In the second time, it will load the snapshot and try to match the current status and output

@test 'assert()' {
  run echo 'foo'
  assert_snapshot
}

On failure, the failed expression is displayed.

   -- output differs --
   expected : foo
   actual   : bar
   --

Partial matching

Partial matching can be enabled with the --partial option (-p for short). When used, the assertion fails if the expected substring is not found in $output.

@test 'assert_snapshot() partial matching' {
  run echo 'SUCCESS'
  assert_snapshot
  run echo 'ERROR: no such file or directory'
  assert_snapshot --partial
}

On failure, the substring and the output are displayed.

-- output does not contain substring --
substring : SUCCESS
output    : ERROR: no such file or directory
--

This option and regular expression matching (--regexp or -e) are mutually exclusive. An error is displayed when used simultaneously.

Regular expression matching

Regular expression matching can be enabled with the --regexp option (-e for short). When used, the assertion fails if the extended regular expression does not match $output.

Note: The anchors ^ and $ bind to the beginning and the end of the entire output (not individual lines), respectively.

@test 'assert_snapshot() regular expression matching' {
  run echo '^Foobar v[0-9]+\.[0-9]+\.[0-9]$'
  assert_snapshot
  run echo 'Foobar 0.1.0'
  assert_snapshot --regexp 
}

On failure, the regular expression and the output are displayed.

-- regular expression does not match output --
regexp : ^Foobar v[0-9]+\.[0-9]+\.[0-9]$
output : Foobar 0.1.0
--

An error is displayed if the specified extended regular expression is invalid.

This option and partial matching (--partial or -p) are mutually exclusive. An error is displayed when used simultaneously.