Skip to content

Commit 970f2c6

Browse files
committed
Add storybook
1 parent 1b6f427 commit 970f2c6

File tree

7 files changed

+215
-193
lines changed

7 files changed

+215
-193
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ npm-debug.log*
44
*.sublime*
55

66
.*
7+
!.storybook
78
!.gitignore
89
!.gitattributes
910
!.npmignore
@@ -19,3 +20,5 @@ accessTokens.js
1920
yarn.lock
2021
yarn-error.log
2122
package-lock.json
23+
24+
storybook-static

.storybook/config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import {configure, getStorybook, setAddon} from '@storybook/react';
2+
3+
function loadStories() {
4+
require('../src/__stories__/index.js');
5+
// You can require as many stories as you need.
6+
}
7+
import createPercyAddon from '@percy-io/percy-storybook';
8+
const {percyAddon, serializeStories} = createPercyAddon();
9+
setAddon(percyAddon);
10+
11+
configure(loadStories, module);
12+
13+
// NOTE: if you're using the Storybook options addon, call serializeStories *BEFORE* the setOptions call
14+
serializeStories(getStorybook);

.storybook/webpack.config.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const path = require('path');
2+
3+
module.exports = {
4+
module: {
5+
rules: [
6+
{
7+
test: /\.(css|scss)?$/,
8+
loaders: ['style-loader', 'css-loader', 'sass-loader'],
9+
include: path.resolve(__dirname, '../'),
10+
},
11+
],
12+
},
13+
};

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"@babel/preset-env": "^7.3.4",
4040
"@babel/preset-react": "^7.0.0",
4141
"@babel/traverse": "^7.3.4",
42-
"@percy/react": "^0.4.6",
42+
"@percy-io/percy-storybook": "^2.1.0",
43+
"@storybook/react": "^4.1.13",
4344
"autoprefixer": "^9.4.9",
4445
"babel-eslint": "^10.0.1",
4546
"babel-jest": "^24.1.0",
@@ -119,12 +120,13 @@
119120
"make:translation-keys": "node scripts/findTranslationKeys.js",
120121
"prepublishOnly": "npm run make:lib",
121122
"start": "webpack-dev-server --hot",
123+
"storybook": "start-storybook -p 9001 -c .storybook",
122124
"test": "npm run test:lint && npm run test:pretty && npm run test:js",
123125
"test:js": "jest --setupTestFrameworkScriptFile=raf/polyfill --maxWorkers=2",
124126
"test:lint": "eslint \"src/**/*.js\" && echo -e '\\033[0;32m'PASS'\\033[0m'",
125127
"test:pretty": "prettier -l \"src/**/*.js\" && echo -e '\\033[0;32m'PASS'\\033[0m'",
126-
"test:percy": "react-percy",
127-
"test:percy-local": "react-percy --debug",
128+
"test:percy": "build-storybook && percy-storybook --widths=500",
129+
"test:percy-local": "build-storybook",
128130
"watch": "babel src --watch --out-dir lib --source-maps | node-sass -w src/styles/main.scss lib/react-chart-editor.css",
129131
"watch-test": "jest --watch"
130132
}

src/__percy__/panels.percy.js renamed to src/__stories__/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import * as panels from '../default_panels/';
77

88
import '../../dev/styles.css';
99
import '../styles/main.scss';
10-
import './percy.css';
10+
import './stories.css';
11+
12+
import React from 'react';
13+
import {storiesOf} from '@storybook/react';
1114

1215
/**
1316
* To add more Percy tests - add a mock file to /dev/percy, add it to /dev/percy/index.js
@@ -49,7 +52,7 @@ const panelFixture = (Panel, group, name, figure) => {
4952
);
5053
};
5154

52-
const snapshotWidth = 500;
55+
let stories = storiesOf('Panels', module);
5356

5457
Object.keys(mocks).forEach(m => {
5558
const selectedPanels = panelsToTest[m] ? panelsToTest[m] : Object.keys(panels);
@@ -59,7 +62,7 @@ Object.keys(mocks).forEach(m => {
5962
const panelGroup = words[0];
6063
const panelName = words.slice(1, -1).join(' ');
6164

62-
percySnapshot(`Panels: ${m}_${p}`, {widths: [snapshotWidth]}, () =>
65+
stories = stories.add(`${m}_${p}`, () =>
6366
panelFixture(panels[p], panelGroup, panelName, mocks[m])
6467
);
6568
});
File renamed without changes.

0 commit comments

Comments
 (0)