Skip to main content
AI agents are now live in Website Scanner! Enter your URL and fix website issues 3x faster with AI. Explore now!
No Result Found
Connect and get help from 7,000+ developers on our Discord community. Ask the CommunityAsk the Community

Integrate your React Styleguidist tests with Percy

A guide to integrating your React Styleguidist style guide with BrowserStack Percy. Catch visual differences in your component library on every change.

This integration uses the Percy CLI plugin @percy/styleguidist to capture snapshots of your React Styleguidist components and upload them to Percy for visual comparison.

Prerequisites

Before you start, ensure you have the following installed:

Create a Percy project
Sign in to Percy. In Percy, create a project of the type Web, and then name the project. After the project is created, Percy generates a token. Make a note of it. You have to use it to set your environment variable in the next step.

For details on creating a project, see Create a Percy project.

Set the project token as an environment variable
Run the given command to set PERCY_TOKEN as an environment variable:

Copy icon Copy
Copy icon Copy
Copy icon Copy

To learn about environment variables in Percy, see Percy environment variables.

Install Percy dependencies
In your React Styleguidist project, install the Percy CLI and the Styleguidist plugin:

Copy icon Copy

The @percy/styleguidist plugin requires:

  • @percy/cli ^1.31.0
  • react-styleguidist >=11 <14
  • Node.js >=18

Configure per-component snapshot options
To override the default Percy snapshot behavior for a single component, add a JSON sidecar file alongside the component. Percy reads <Component>.json from the same directory as the component file.

Copy icon Copy
Copy icon Copy

Components without a .json sidecar use the global Percy defaults from your .percy.yml (or .percy.json) configuration.

For the full list of allowlisted sidecar keys, additionalSnapshots options, and dropped-key warning behavior, see React Styleguidist advanced topics.

Run Percy
Build your style guide and run Percy against the output directory:

Copy icon Copy

Percy uploads the snapshots and returns a direct URL to the build on the Percy dashboard.

Congratulations! You have integrated React Styleguidist with Percy. When you run another build with visual changes to your components, Percy takes new snapshots and shows the comparison against the previous run.

For other ways to run Percy, see React Styleguidist advanced topics. It covers pointing at a running dev server, spawning the dev server in one step with percy styleguidist-start, filtering components with --include/--exclude, and driving captures from JavaScript.

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback!

Talk to an Expert
Download Copy Check Circle