storybooks/storybook-addon-jest

Name: storybook-addon-jest

Owner: Storybook

Description: React storybook addon that show component jest report

Created: 2017-11-09 17:31:12.0

Updated: 2018-05-22 07:01:19.0

Pushed: 2018-05-01 01:18:25.0

Homepage: https://renaudtertrais.github.io/storybook-addon-jest

Size: 4963

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Storybook addon Jest

Brings Jest results in storybook.

Storybook Jest Addon Demo

Checkout the above Live Storybook.

Getting started
Install

npm install --save-dev storybook-addon-jest

or

yarn add --dev storybook-addon-jest

Jest Configuration

When running Jest, be sure to save the results in a json file:

package.json

ipts": {
est": "jest --json --outputFile=.jest-test-results.json"

Add it the result file to .gitignore:

t-test-results.json

Known issue: if you use a deploy script using for example gh-pages, be sure to not put the test script that write the result in part of the script process (in predeploy for example). Instead use a different script:

ipts": {
est:output": "jest --json --outputFile=.jest-test-results.json",
est": "jest",
rebuild:storybook": "npm run test",
uild:storybook": "build-storybook -c .storybook -o build/",
redeploy": "npm run build:storybook",
eploy": "gh-pages -d build/",

Then in dev use:

run test:output -- --watch

When deploying:

run deploy
Register

Register addon at .storybook/addons.js

rt 'storybook-addon-jest/register';
Usage

Assuming that you have created a test files MyComponent.test.js and MyOtherComponent.test.js

In your story.js

rt jestTestResults from '../.jest-test-results.json';
rt withTests from 'storybook-addon-jest';

iesOf('MyComponent', module)
ddDecorator(withTests(jestTestResults, { filesExt: '.test.js' })('MyComponent', 'MyOtherComponent'));

Or in order to avoid importing .jest-test-results.json in each story, you can create a simple file withTests.js:

rt jestTestResults from '../.jest-test-results.json';
rt withTests from 'storybook-addon-jest';

rt default withTests(jestTestResults, {
lesExt: '.test.js',

Then in your story:

mport your file
rt withTests from '.withTests';

iesOf('MyComponent', module)
ddDecorator(withTests('MyComponent', 'MyOtherComponent'));
Styling

The panel comes with a basic design. If you want to make it look a bit nicer, you add github markdown style by importing it in .storybook/addons.js

rt 'storybook-addon-jest/register';
rt 'storybook-addon-jest/styles';

If you already use storybook-readme addon, you do not need to import it.

TODO
Contributing

Every ideas and contributions are welcomed.

Licence

MIT © 2017-present Renaud Tertrais


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.