GithubHelp home page GithubHelp logo

danyellow / storybook-addon-jest Goto Github PK

View Code? Open in Web Editor NEW

This project forked from storybook-eol/storybook-addon-jest

0.0 3.0 0.0 4.96 MB

React storybook addon that show component jest report

Home Page: https://renaudtertrais.github.io/storybook-addon-jest

JavaScript 100.00%

storybook-addon-jest's Introduction

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

"scripts": {
  "test": "jest --json --outputFile=.jest-test-results.json"
}

Add it the result file to .gitignore:

.jest-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:

"scripts": {
  "test:output": "jest --json --outputFile=.jest-test-results.json",
  "test": "jest",
  "prebuild:storybook": "npm run test",
  "build:storybook": "build-storybook -c .storybook -o build/",
  "predeploy": "npm run build:storybook",
  "deploy": "gh-pages -d build/",
}

Then in dev use:

npm run test:output -- --watch

When deploying:

npm run deploy

Register

Register addon at .storybook/addons.js

import 'storybook-addon-jest/register';

Usage

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

In your story.js

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

storiesOf('MyComponent', module)
  .addDecorator(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:

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

export default withTests(jestTestResults, {
  filesExt: '.test.js',
});

Then in your story:

// import your file
import withTests from '.withTests';

storiesOf('MyComponent', module)
  .addDecorator(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

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

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

TODO

  • Add coverage
  • Display nested test better (describe)
  • Display the date of the test
  • Add unit tests
  • Add linting
  • Split

Contributing

Every ideas and contributions are welcomed.

Licence

MIT © 2017-present Renaud Tertrais

storybook-addon-jest's People

Contributors

renaudtertrais avatar ndelangen avatar

Watchers

James Cloos avatar Jean-Louis Danielo avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.