-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to use image snapshots to addon-storyshots #2413
Changes from 22 commits
b96345b
d5ce79e
edd03a9
c7c1ef1
6d0abf1
5759db9
6bea608
7a74298
724ab4c
2076574
03e47af
e9c2090
c124dd5
c798cdf
d94fa13
a63e1d8
fcce2cd
ddde721
5a24d9d
1df4c87
8a69e8b
ce9f389
2b2b03c
ca8b1cc
e5b3233
6dca7b9
9cae936
6a5911f
49e0338
28cb109
c5a1fa1
96a5df5
1a4d34c
b104897
425937a
57b06f8
797f2b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,11 +58,19 @@ jobs: | |
name: "Link packages" | ||
command: | | ||
yarn install | ||
- run: | ||
name: Workaround for https://github.com/GoogleChrome/puppeteer/issues/290 | ||
command: sh ./scripts/workaround-puppeteer-issue-290.sh | ||
- run: | ||
name: "Build react kitchen-sink" | ||
command: | | ||
cd examples/cra-kitchen-sink | ||
yarn build-storybook | ||
- run: | ||
name: "Build official-storybook" | ||
command: | | ||
cd examples/official-storybook | ||
yarn build-storybook | ||
- run: | ||
name: "Build vue kitchen-sink" | ||
command: | | ||
|
@@ -73,28 +81,24 @@ jobs: | |
command: | | ||
cd examples/angular-cli | ||
yarn build-storybook | ||
|
||
- run: | ||
name: "Run react kitchen-sink" | ||
name: "Run react kitchen-sink (smoke test)" | ||
command: | | ||
cd examples/cra-kitchen-sink | ||
yarn storybook | ||
background: true | ||
yarn storybook --smoke-test | ||
- run: | ||
name: "Run vue kitchen-sink" | ||
name: "Run vue kitchen-sink (smoke test)" | ||
command: | | ||
cd examples/vue-kitchen-sink | ||
yarn storybook | ||
background: true | ||
yarn storybook --smoke-test | ||
- run: | ||
name: "Run angular-cli" | ||
name: "Run angular-cli (smoke test)" | ||
command: | | ||
cd examples/angular-cli | ||
yarn storybook | ||
background: true | ||
yarn storybook --smoke-test | ||
- run: | ||
name: Workaround for https://github.com/GoogleChrome/puppeteer/issues/290 | ||
command: sh ./scripts/workaround-puppeteer-issue-290.sh | ||
name: "Run image snapshots" | ||
command: yarn test --image | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please store image diffs as artifacts (see below, plus docs) That way it would be much easier to find out why is the CI test failing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice, will do ! |
||
- run: | ||
name: Integration Test - Kichen sinks | ||
command: yarn test --integration | ||
|
@@ -195,6 +199,11 @@ jobs: | |
name: "Link packages" | ||
command: | | ||
yarn install | ||
- run: | ||
name: "Build static React kitchen-sink" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's not add image snapshots to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we could even reuse some code between those two files: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this step be removed now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah no, it can't since the "integration" test is relying on it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is |
||
command: | | ||
cd examples/cra-kitchen-sink | ||
yarn build-storybook | ||
- run: | ||
name: "Run unit tests" | ||
command: | | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import puppeteer from 'puppeteer'; | ||
import { toMatchImageSnapshot } from 'jest-image-snapshot'; | ||
|
||
expect.extend({ toMatchImageSnapshot }); | ||
|
||
export const imageSnapshot = ({ | ||
storybookUrl = 'http://localhost:6006', | ||
getMatchOptions = () => {}, | ||
}) => { | ||
let browser; // holds ref to browser. (ie. Chrome) | ||
let page; // Hold ref to the page to screenshot. | ||
|
||
const testFn = ({ context }) => { | ||
if (context.isRNStorybook) { | ||
// Skip tests since we de not support RN image snapshots. | ||
console.error( | ||
"It seems you are running imageSnapshot on RN app and it's not supported. Skipping test." | ||
); | ||
return Promise.resolve(); | ||
} | ||
|
||
const encodedKind = encodeURIComponent(context.kind); | ||
const encodedStoryName = encodeURIComponent(context.story); | ||
const storyUrl = `/iframe.html?selectedKind=${encodedKind}&selectedStory=${encodedStoryName}`; | ||
const url = storybookUrl + storyUrl; | ||
if (!browser || !page) { | ||
console.error( | ||
`Error when generating image snapshot for test ${context.kind} - ${ | ||
context.story | ||
} : It seems the headless browser is not running.` | ||
); | ||
return Promise.reject(new Error('no-headless-browser-running')); | ||
} | ||
|
||
expect.assertions(1); | ||
return page | ||
.goto(url) | ||
.catch(e => { | ||
console.error( | ||
`ERROR WHILE CONNECTING TO ${url}, did you start or build the storybook first ? A storybook instance should be running or a static version should be built when using image snapshot feature.`, | ||
e | ||
); | ||
throw e; | ||
}) | ||
.then(() => | ||
page.screenshot().then(image => { | ||
expect(image).toMatchImageSnapshot(getMatchOptions({ context, url })); | ||
}) | ||
); | ||
}; | ||
|
||
testFn.beforeEach = () => | ||
puppeteer | ||
// add some options "no-sandbox" to make it work properly on some Linux systems as proposed here: https://github.com/Googlechrome/puppeteer/issues/290#issuecomment-322851507 | ||
.launch({ args: ['--no-sandbox ', '--disable-setuid-sandbox'] }) | ||
.then(b => { | ||
browser = b; | ||
}) | ||
.then(() => browser.newPage()) | ||
.then(p => { | ||
page = p; | ||
}); | ||
|
||
testFn.afterEach = () => browser.close(); | ||
|
||
return testFn; | ||
}; |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const path = require('path'); | ||
const globalJestConfig = require('../../../jest.config'); | ||
|
||
const finalJestConfig = globalJestConfig; | ||
|
||
finalJestConfig.rootDir = path.join(__dirname, '../../..'); | ||
finalJestConfig.testMatch = [ | ||
'<rootDir>/examples/official-storybook/image-snapshots/storyshots-image.runner.js', | ||
]; | ||
|
||
module.exports = finalJestConfig; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's run
yarn storybook --smoke-test
(withoutbackground: true
) just to check that devserver starts successfully)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allright, will re-add this.