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

@kadira/storyshots

v2.1.0

Published

StoryShots - Snapshot Testing for React Storybook.

Downloads

71

Readme

StoryShots CircleCI

Snapshot Testing for React Storybook

StoryShots in use

With StoryShots, you could use your existing Storybook stories, as the input for snapshot testing. We do it by integrating Jest's snapshot testing support, directly into Storybook.

Read This: Snapshot Testing in React Storybook

Migrating to version 2: If you are already using version 1.x.x, follow these steps to migrate safely to 2.x.x.

Getting Started

First of all, you need to use the latest version of React Storybook. So, do this:

npm update @kadira/storybook

Then add the following NPM module into your app.

npm i -D @kadira/storyshots

Then, add a NPM script as follows:

"scripts": {
  "test-storybook": "storyshots"
}

Then, run the following command:

npm run test-storybook

After that, you can see an output like this:

First Run

This will create a set of snapshots, inside your Storybook config directory. You could publish them into GIT.

UI Changes

Once you did a UI change, you could run StoryShots again with:

npm run test-storybook

Then, you can see changes with a diff view, like the following:

UI Changes

If these changes are intentional, you could update snapshots with:

npm run test-storybook -- -u

If not, you could try to correct it and re-run the above command.

Key Features

StoryShots comes with some few features which help you to be productive and customize it, to suit your project.

Interactive Mode

When you have a lot of UI changes, it's a good idea to check and update them, one by one. That's where our interactive mode comes in. Run the following command:

npm run test-storybook -- -i

Watch files

It's pretty useful to watch files and re-run StoryShots again. You can do that with the -w flag.

npm run test-storybook -- -w

Grep Stories

You may don't want to storyshot each and every of your stories. If so, you could grep which stories you want to storyshot, by invoking the -g option:

npm run test-storybook -- -g "theme"

You can also use the -x option similarly to exclude some stories.

Provide Custom Loaders

When we are running your stories, we don't use Webpack. So, we can't import files other than .js and .json. This means actually, that we can't import your .css and .png files.

In order to fix this issue, we provide some mock loaders for few of the most common file types. Here are they.

But, we can't add all the loaders you might use. So, we allow you to customize it. Instead of using our loaders, you could use a set of loaders you want.

For that, first create a file called loaders.js in your project root. Then add support to few loaders like this:

var loaders = module.exports = {};

// to support css modules
loaders['css'] = function(path) {
  return {};
};

// to support jpeg files
loaders['jpeg'] = function(path) {
  return path;
}

Then, run StoryShots like this:

npm run test-storybook -- --loaders=loaders.js

You could also update your original NPM script, according to the following instead.

"test-storybook": "storyshots --loaders=loaders.js"

Add Window and Global Polyfills

StoryShot doesn't use an actual browser, to run your code. Since your UI components may use browser features, we try to create a minimal browser environment with JSDom and with some common polyfills.

You can see them here.

But, you may also use some other browser features. Then, we allow you to add custom polyfills, replacing our own config. Create a file like this with your own polyfills.

Then, run StoryShots like this:

npm run test-storybook -- --polyfills=polyfills.js

Other Features

Beside these main features, StoryShots comes with few other minor features. You could see them by looking at the help:

npm run test-storybook -- -h