Skip to content

Commit

Permalink
Merge pull request #67 from happo/fix-storybook-v5
Browse files Browse the repository at this point in the history
Add linting and fix issues
  • Loading branch information
trotzig authored Jan 11, 2022
2 parents 1d13590 + 7aedd7c commit 356999b
Show file tree
Hide file tree
Showing 6 changed files with 1,655 additions and 1,303 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
register.js
17 changes: 17 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = {
env: {
browser: true,
es2021: true,
node: true,
},
extends: ['eslint:recommended', 'plugin:react/recommended'],
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 13,
sourceType: 'module',
},
plugins: ['react'],
rules: {},
};
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ jobs:
node-version: 14
- run: yarn install --frozen-lockfile
- run: yarn add @storybook/addons@${{ matrix.storybook-version }} @storybook/react@${{ matrix.storybook-version }} && rm -rf node_modules && yarn install && yarn build && yarn happo run
- run: yarn lint
- run: HAPPO_USE_PREBUILT_PACKAGE=yes yarn build-storybook && yarn happo run
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "A happo.io plugin for projects using Storybook",
"main": "index.js",
"scripts": {
"lint": "eslint .",
"test": "jest",
"happo": "happo",
"build": "babel register.es6.js --out-file register.js",
Expand Down Expand Up @@ -50,6 +51,8 @@
"@storybook/addons": "^6.0.13",
"@storybook/react": "^6.0.13",
"babel-loader": "^8.0.5",
"eslint": "^8.6.0",
"eslint-plugin-react": "^7.28.0",
"file-loader": "^3.0.1",
"happo.io": "^5.1.3",
"raw-loader": "^1.0.0",
Expand Down
10 changes: 6 additions & 4 deletions register.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async function waitForWaitFor(waitFor, start = time.originalDateNow()) {
}

function getExamples() {
const storyStore = __STORYBOOK_CLIENT_API__._storyStore;
const storyStore = window.__STORYBOOK_CLIENT_API__._storyStore;
if (storyStore.extract) {
return Object.values(storyStore.extract())
.map(({ id, kind, story, parameters }) => {
Expand Down Expand Up @@ -77,14 +77,16 @@ function getExamples() {

const result = [];

for (let story of __STORYBOOK_CLIENT_API__.getStorybook()) {
for (let story of window.__STORYBOOK_CLIENT_API__.getStorybook()) {
const component = story.kind;
for (let example of story.stories) {
const { name: variant } = example;
let delay = defaultDelay;
let waitForContent;
let waitFor;
let targets;
let beforeScreenshot;
let afterScreenshot;
if (storyStore.getStoryAndParameters) {
const { parameters } = storyStore.getStoryAndParameters(
story.kind,
Expand Down Expand Up @@ -185,7 +187,7 @@ window.happo.nextExample = async () => {
console.error('Failed to invoke afterScreenshot hook', e);
}
}
__STORYBOOK_ADDONS_CHANNEL__.emit('setCurrentStory', {
window.__STORYBOOK_ADDONS_CHANNEL__.emit('setCurrentStory', {
kind: component,
story: variant,
storyId,
Expand All @@ -195,7 +197,7 @@ window.happo.nextExample = async () => {
if (/sb-show-errordisplay/.test(document.body.className)) {
// It's possible that the error is from unmounting the previous story. We
// can try re-rendering in this case.
__STORYBOOK_ADDONS_CHANNEL__.emit('forceReRender');
window.__STORYBOOK_ADDONS_CHANNEL__.emit('forceReRender');
await waitForSomeContent(rootElement);
}
await new Promise(resolve => time.originalSetTimeout(resolve, delay));
Expand Down
Loading

0 comments on commit 356999b

Please sign in to comment.