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

@testplane/storybook

v1.1.0

Published

Testplane plugin that enables runtime screenshot storybook tests autogeneration

Downloads

82

Readme

@testplane/storybook

A Testplane plugin that makes it easy to write Testplane tests on storybook components:

  • Adds automatic screenshot tests for storybook stories;
  • Adds an ability to write Testplane tests for storybook stories right inside of the stories.

Installation

npm install @testplane/storybook --save-dev

Usage

⚠️ Storybook 6.4+ is required to use this plugin.

Storybook

If you use storybook@6, you will need to enable buildStoriesJson feature in your storybook config:

// .storybook/main.js
export default {
    // ...
    features: {
        // ...
        buildStoriesJson: true
    }
}

You don't need to do this with storybook@7 or storybook@8.

Testplane

Add @testplane/storybook plugin into your Testplane config:

// .testplane.conf.ts
export default {
    plugins: {
        '@testplane/storybook': {},

        // other Testplane plugins...
    },

    // other Testplane settings...
}

With this minimal config, you will be able to run npx testplane --storybook to autotest each storybook story with Testplane assertView command. Testplane will open each story, wait for play function to finish (if defined), and then call assertView command. These tests would be generated in runtime.

Full plugin config:

| Parameter | Type | Default value | Description | | ------------------ | ----------------------- | ---------------------- | --------------------------------------------------------------------------- | | enabled | Boolean | true | Enable / disable the plugin | | storybookConfigDir | String | ".storybook" | Path to the storybook configuration directory | | autoScreenshots | Boolean | true | Enable / disable auto-screenshot tests | | localport | Number | 6006 | Port to launch storybook dev server on | | remoteStorybookUrl | String | "" | URL of the remote Storybook. If specified, local storybook dev sever would not be launched | | browserIds | Array<String | RegExp> | [] | Array of browserId to run storybook tests on. By default, all of browsers, specified in Testplane config would be used |

⚠️ Storybook tests performance greatly depends on Testplane testsPerSession parameter, as these tests speeds up on reusing existing sessions, so setting values around 20+ is preferred

⚠️ These tests ignore Testplane isolation. It would be turned off unconditionally

Advanced usage

If you have ts-node in your project, you can write your Testplane tests right inside of storybook story files:

⚠️ Storybook story files must have .js or .ts extension for this to work

import type { StoryObj } from "@storybook/react";
import type { WithTestplane } from "@testplane/storybook"

export const Primary: WithTestplane<StoryObj> = {
    args: {
        primary: true,
        label: "Button",
    },
    testplane: {
        "my test": async ({browser, expect}) => {
            const element = await browser.$(".storybook-button");

            await expect(element).toHaveText("Button");
        }
    }
};

You can also specify extra options in story default config:

import type { WithTestplane } from "@testplane/storybook"
import type { Meta, StoryObj } from "@storybook/react";

const meta: WithTestplane<Meta<typeof Button>> = {
    title: "Example/Button",
    component: Button,
    testplane: {
        skip: false, // if true, skips all Testplane tests from this story file
        browserIds: ["chrome"], // Testplane browsers to run tests from this story file
        assertViewOpts: { // override default assertView options for tests from this file
            ignoreDiffPixelCount: 5
        }
    }
};

export default meta;

If you decide to create separate config for storybook auto-tests (which is suggested), you need to specify config path via CLI option. For example:

npx testplane --storybook -c .testplane.storybook.conf.ts

This allows you to store references next to your story files:

// .testplane.conf.ts
import path from "path";
import { getStoryFile } from "@testplane/storybook";

export default {
    screenshotsDir: (test) => {
        const relativeStoryFilePath = getStoryFile(test);
        const relativeStoryFileDirPath = path.dirname(relativeStoryFilePath);

        return path.join(relativeStoryFileDirPath, "screens", test.id, test.browserId);
    },
    // other Testplane settings...
}

In this example, screenshot references would be stored in screens/<testId>/<browserId> folder, next to each of your story files.