• Stars
    star
    145
  • Rank 254,144 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Percy's Storybook SDK.

@percy/storybook

Version Test

Percy visual testing for Storybook.

Installation

$ npm install --save-dev @percy/cli @percy/storybook

Usage

Before running the following commands, make sure your project's PERCY_TOKEN is properly configured.
# Unix
$ export PERCY_TOKEN="<your-project-token>"

# Windows
$ set PERCY_TOKEN="<your-project-token>"

# Powershell
$ $Env:PERCY_TOKEN="<your-project-token>"

With a static Storybook build:

$ percy storybook ./storybook-build

With a local or live Storybook URL:

$ percy storybook http://localhost:9009
$ percy storybook https://storybook.foobar.com

Automatically run start-storybook:

$ percy storybook:start --port=9009 --static-dir=./public

Commands:

percy storybook

Snapshot static or hosted Storybook stories

Usage:
  $ percy storybook [options] <url|directory>

Arguments:
  url|directory                      Storybook url or build output directory

Subcommands:
  storybook:start [options]          Run start-storybook to snapshot stories
  help [command]                     Display command help

Options:
  -i, --include <pattern>            Pattern matching story names to include in snapshots
  -e, --exclude <pattern>            Pattern matching story names to exclude from snapshots
  --shard-count <number>             Number of shards to split snapshots into
  --shard-size <number>              Size of each shard to split snapshots into
  --shard-index <index>              Index of the shard to take snapshots of
  --partial                          Marks the build as a partial build

Percy options:
  -c, --config <file>                Config file path
  -d, --dry-run                      Print snapshot names only
  -h, --allowed-hostname <hostname>  Allowed hostnames to capture in asset discovery
  --disallowed-hostname <hostname>   Disallowed hostnames to abort in asset discovery
  -t, --network-idle-timeout <ms>    Asset discovery network idle timeout
  --disable-cache                    Disable asset discovery caches
  --debug                            Debug asset discovery and do not upload snapshots

Global options:
  -v, --verbose                      Log everything
  -q, --quiet                        Log errors only
  -s, --silent                       Log nothing
  --help                             Display command help

Examples:
  $ percy storybook ./build
  $ percy storybook http://localhost:9000/

percy storybook:start

Run start-storybook to snapshot stories

Usage:
  $ percy storybook:start [options]

Options:
  -i, --include <pattern>            Pattern matching story names to include in snapshots
  -e, --exclude <pattern>            Pattern matching story names to exclude from snapshots
  --shard-count <number>             Number of shards to split snapshots into
  --shard-size <number>              Size of each shard to split snapshots into
  --shard-index <index>              Index of the shard to take snapshots of
  --partial                          Marks the build as a partial build
  --port [number]                    Port to start Storybook (default: 9000)
  --host [hostname]                  Host to start Storybook (default: "localhost")

Percy options:
  -c, --config <file>                Config file path
  -d, --dry-run                      Print snapshot names only
  -h, --allowed-hostname <hostname>  Allowed hostnames to capture in asset discovery
  --disallowed-hostname <hostname>   Disallowed hostnames to abort in asset discovery
  -t, --network-idle-timeout <ms>    Asset discovery network idle timeout
  --disable-cache                    Disable asset discovery caches
  --debug                            Debug asset discovery and do not upload snapshots

Global options:
  -v, --verbose                      Log everything
  -q, --quiet                        Log errors only
  -s, --silent                       Log nothing
  --help                             Display command help

Examples:
  $ percy storybook:start
  $ percy storybook:start --port 9000
  $ percy storybook:start --static-dir public

Configuration

Storybook parameters are a set of static, named metadata about a story, used to control the behavior of Storybook features and addons. The percy parameter can be provided to add per-snapshot configuration options to a story or set of stories.

// individual stories
MyStory.parameters = {
  percy: { ... }
};
// .storybook/preview.js
export const parameters = {
  percy: { ... }
};

The following percy Storybook parameters are accepted in addition to common per-snapshot options:

  • skip - Boolean indicating whether or not to skip this story.
  • name - Snapshot name. (default: ${story.kind}: ${story.name})
  • args - Story args to use when taking the snapshot.
  • globals - Story globals to use when taking the snapshot.
  • queryParams - Query parameters to use when snapshotting.
  • waitForTimeout - Wait for a timeout before taking the snapshot.
  • waitForSelector - Wait for a selector to exist before taking the snapshot.
  • include - An array of regex patterns matching story names to only include for snapshotting.
  • exclude - An array of regex patterns matching story names to always exclude from snapshotting.
  • additionalSnapshots - An array of additional snapshots to take of this story.
    • prefix - A prefix added to this additional snapshot's name.
    • suffix - A suffix added to this additional snapshot's name.
    • name - Snapshot name. Replaces the inherited name.
    • args - Additional story args for this additional snapshot.
    • globals - Additional story globals for this additional snapshot.
    • queryParams - Additional query parameters for this additional snapshot.
    • include - Only apply the additional snapshot to matching stories.
    • exclude - Do not apply the additional snapshot to matching stories.
Click to see an example story configuration
MyStory.parameters = {
  percy: {
    name: 'My snapshot',
    additionalSnapshots: [
      { prefix: '[Dark mode] ', args: { colorScheme: 'dark' } },
      { suffix: ' with a search', queryParams: { search: 'foobar' } }
    ]
  }
};

With this example, 3 snapshots will be taken of this story with args and query params appended to the URL of each snapshot:

# --dry-run will log snapshots without creating a new build
# --verbose will show debug logs, including the snapshot url
$ percy storybook --dry-run --verbose ./example-storybook
# ...
[percy] Snapshot found: My snapshot
[percy] -> url: [...]?id=component--my-story
[percy] Snapshot found: [Dark mode] My snapshot
[percy] -> url: [...]?id=component--my-story&args=colorScheme:dark
[percy] Snapshot found: My snapshot with a search
[percy] -> url: [...]?id=component--my-story&search=foobar

Percy config file options

In addition to common Percy config file options, this SDK also adds the following Storybook specific options:

# .percy.yml
version: 2
storybook:
  args: {}
  globals: {}
  queryParams: {}
  waitForTimeout: 0
  waitForSelector: ''
  additionalSnapshots: []
  include: []
  exclude: []

See the configuration options above for details about each accepted config file option (note: the skip and name parameters are not accepted as Percy config file options).

Upgrading

Prior versions of the Storybook SDK were drastically different than the current version. The command, it's arguments, and how the SDK works internally have changed completely. Using the old command with new versions will now result in an error message. The new command is now integrated into @percy/cli as a plugin.

To use new versions of this SDK, you will have to also install the CLI with the SDK:

$ npm install --save-dev @percy/cli @percy/storybook

Since both the command and arguments have changed, you'll need to replace your existing usage with the new usage described above. For some projects, this may require setting additional configuration options. See the list of breaking changes below for details.

Breaking changes

Most importantly, the command itself has changed and all previous arguments are no longer accepted.

  • The percy-storybook command has been replaced with a percy CLI subcommand, percy storybook.

  • The previous --build_dir flag is now a command argument and there is no default build directory. If you relied on the default, it must now be explicitly provided.

    # before
    $ percy-storybook
    # after
    $ percy storybook ./storybook-static
    
    # before
    $ percy-storybook --build_dir ./build
    # after
    $ percy storybook ./build
  • The --widths flag is no longer accepted. Widths can be set using the respective widths Percy config file snapshot option or percy Storybook parameter.

  • The --minimum_height flag is no longer accepted and therefore no longer defaults to 800px. The default minimum height shared by all SDKs is 1024px. The minimum height can be set using the respective min-height Percy config file snapshot option or percy Storybook parameter.

  • The --debug flag is now --verbose, inherited from the CLI.

  • The --output-format flag is no longer accepted and has no alternative. If you relied on this flag, please open an issue.

  • The --rtl and --rtl_regex flags are no longer accepted. The --rtl flag duplicated stories and set the direction=rtl query parameter for the duplicate's URL. The --rtl_regex flag was used to determine when to create this RTL duplicate story.

    Click here to see how to replicate the old behaviour with new configuration options
    // .storybook/preview.js
    
    export const parameters = {
      percy: {
        // tell percy to take an additional RTL snapshot for matching stories
        additionalSnapshots: [{
          suffix: ' [RTL]',
          queryParams: { direction: 'rtl' },
          include: ['^FormElement: .*']
        }]
      }
    };

Performance

The old SDK did not take DOM snapshots or perform asset discovery, as all other modern Percy SDKs do. This sometimes resulted in flakey snapshots or snapshots with missing assets. However, DOM snapshots and asset discovery add an overhead cost of performance. Where the old SDK was very quick to simply upload the local build directory, the new SDK can be a little slower while it is capturing the real DOM and relevant assets of each story.

Unexpected diffs

Because the old SDK did not take DOM snapshots, JavaScript had to be enabled in our rendering environment for Storybook to properly load. This is in contrast to all of our other SDKs, where JavaScript is disabled by default to prevent flakey diffs caused by animations or other JavaScript running on the page. With the new SDK and real DOM snapshots, JS is disabled by default. If you upgrade and experience diffs due to the lack of JavaScript, it can be re-enabled using the matching Percy config file or per-snapshot option, enableJavaScript.

More Repositories

1

percy-cypress

Visual testing with Cypress and Percy
JavaScript
321
star
2

percy-ember

Ember addon for visual regression testing with Percy
JavaScript
70
star
3

cli

The Percy CLI is used to interact with, and upload snapshots to, percy.io via the command line.
JavaScript
60
star
4

example-percy-cypress

Example app demonstrating Percy's Cypress integration.
JavaScript
57
star
5

percy-puppeteer

Visual testing with Puppeteer and Percy
JavaScript
47
star
6

percy-capybara

Visual testing for Capybara with Percy.
Ruby
45
star
7

react-percy

[Deprecated]
JavaScript
32
star
8

percy-js

[Deprecated] JavaScript API client library for Percy.
JavaScript
31
star
9

percy-webdriverio

Visual testing with WebdriverIO and Percy
JavaScript
26
star
10

percy-style

Percy shared style configs.
Ruby
25
star
11

percy-agent

[Deprecated in favor of `@percy/cli`] An agent process for integrating with Percy.
HTML
22
star
12

python-percy-client

[Deprecated] Python client library for visual regression testing with Percy.
Python
21
star
13

percy-cli-ruby

[Deprecated] Command-line interface for Percy.
Ruby
19
star
14

snapshot-action

[Deprecated] A GitHub action to visually test static sites with Percy
SCSS
14
star
15

example-percyscript

The easiest way to get started with visual testing and Percy.
HTML
13
star
16

percy-playwright

Playwright client library for visual testing with Percy
JavaScript
12
star
17

percy-selenium-java

Visual testing with Java Selenium and Percy
Java
11
star
18

storybook-action

[Deprecated] A GitHub action to run Percy with Storybook
JavaScript
11
star
19

percy-selenium-python

Percy visual testing for Python Selenium
Python
10
star
20

percy-testcafe

TestCafe client library for visual regression testing with Percy
JavaScript
9
star
21

percy-appium-wd

Webdriver & Appium client library for visual regression testing with Percy
JavaScript
8
star
22

percy-client

Low-level Ruby API client for Percy.
Ruby
8
star
23

exec-action

A (deprecated) GitHub action to run Percy Agent `percy exec` commands
JavaScript
8
star
24

example-percy-puppeteer

Example app showing integration of Percy visual testing into Puppeteer tests.
JavaScript
7
star
25

percy-nightwatch

Visual testing with Nightwatch and Percy
JavaScript
6
star
26

example-rails

Example app for Percy's Rails tutorial.
Ruby
5
star
27

example-percy-nightwatch

Example app demonstrating Percy's Nightwatch integration.
JavaScript
5
star
28

example-percy-java-selenium

Example app demonstrating Percy's Java Selenium integration.
JavaScript
5
star
29

example-percy-webdriverio

Example of how to integrate Percy visual test with WebdriverIO.
JavaScript
4
star
30

example-percy-testcafe

Example app demonstrating Percy's TestCafe integration.
JavaScript
4
star
31

example-percy-ember

Example app for Percy's Ember tutorial.
JavaScript
3
star
32

percy-common

Server-side common library for Percy.
Ruby
3
star
33

example-percy-selenium-dotnet

Example app demonstrating Percy's .NET selenium integration.
JavaScript
3
star
34

percy-protractor

Visual testing with Protractor and Percy
JavaScript
3
star
35

example-percy-jekyll

SCSS
3
star
36

percy-selenium-ruby

Visual testing with Selenium Ruby and Percy
Ruby
3
star
37

example-percy-puppeteer-standalone

Example app showing integration of Percy visual testing into Google Puppeteer scripts.
HTML
3
star
38

percy-poller

Poll the Percy API until a build is done, and then log the status as JSON. Also see Webhooks: https://docs.percy.io/docs/webhooks
JavaScript
3
star
39

gatsby-plugin-percy

Percy Plugin for Gatsby
JavaScript
2
star
40

percy-selenium-js

Selenium.js client library for visual regression testing with Percy
JavaScript
2
star
41

example-percy-cypress-typescript

Example Cypress and Percy usage with TypeScript
JavaScript
2
star
42

percy-script

[Deprecated] PercyScript is the easiest way to get started with visual testing and Percy.
JavaScript
2
star
43

example-percy-protractor

Example app demonstrating Percy's Protractor integration.
JavaScript
2
star
44

in-percy

@percy-io/in-percy NPM package
JavaScript
2
star
45

example-percy-storybook

Example app demonstrating Percy's Storybook integration.
JavaScript
2
star
46

percy-selenium-dotnet

Percy visual testing for .NET Selenium
C#
1
star
47

example-percy-anywhere

An example of Percy visual regression tests and Capybara/Selenium interaction with any static site.
JavaScript
1
star
48

example-quickstart

Simple example app with Percy visual regression tests.
Ruby
1
star
49

percy-appium-js

JavaScript
1
star
50

example-percy-appium-python

Python
1
star
51

example-percy-playwright

Example app showing integration of Percy visual testing into Puppeteer tests.
JavaScript
1
star
52

percy-appium-python

Python
1
star
53

example-percy-selenium-python

Example app demonstrating Percy's Python Selenium integration.
JavaScript
1
star
54

percy-nightmare

Visual testing with Nightmare and Percy
JavaScript
1
star
55

percy-migrate-sdk

@percy/migrate is used to upgrade and migrate your Percy SDK to the latest version.
JavaScript
1
star