-
-
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
Merged
Hypnosphi
merged 37 commits into
storybookjs:master
from
thomasbertet:storyshots-add-image-snapshots
Jan 11, 2018
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
b96345b
add jest-image-snapshot to storyshots
d5ce79e
use custom jest config for storyshots with image snapshots & re-add a…
edd03a9
clean circleci config for image snapshots
c7c1ef1
Update image snapshots test config for angular-cli
6d0abf1
reorder cicleci goals
5759db9
Merge branch 'master' into storyshots-add-image-snapshots
thomasbertet 6bea608
Add missing snapshot
7a74298
Merge branch 'master' into storyshots-add-image-snapshots
ndelangen 724ab4c
improve image snapshots stories, remove deprecated use to please linter
2076574
Merge branch 'master' into storyshots-add-image-snapshots
ndelangen 03e47af
Merge branch 'master' into storyshots-add-image-snapshots
ndelangen e9c2090
Merge branch 'master' into storyshots-add-image-snapshots
thomasbertet c124dd5
update snapshots with the correct ones
c798cdf
Merge branch 'master' into storyshots-add-image-snapshots
thomasbertet d94fa13
remove transformIgnorePatterns since lodash-es has been reverted
a63e1d8
put image-storyshots to official-storybook & update scripts
fcce2cd
Merge branch 'master' into storyshots-add-image-snapshots
thomasbertet ddde721
Merge branch 'master' into storyshots-add-image-snapshots
thomasbertet 5a24d9d
remove unused code & fix image-snapshots script
1df4c87
Add official-storybook static build to CI
8a69e8b
re-move addon-jest config & script to official-storybook
ce9f389
Merge branch 'master' into storyshots-add-image-snapshots
ndelangen 2b2b03c
store image snapshots on CI for official-storybook
ca8b1cc
re-add coverage config to addon-jest.config.js
e5b3233
Merge branch 'master' into storyshots-add-image-snapshots
thomasbertet 6dca7b9
re-add cra-kitchen-sink to CI build for integration tests
9cae936
Merge branch 'master' into storyshots-add-image-snapshots
thomasbertet 6a5911f
Merge branch 'master' into storyshots-add-image-snapshots
thomasbertet 49e0338
Merge branch 'master' into storyshots-add-image-snapshots
thomasbertet 28cb109
Merge branch 'master' into storyshots-add-image-snapshots
igor-dv c5a1fa1
Merge branch 'master' into storyshots-add-image-snapshots
thomasbertet 96a5df5
Add more details in READMEfor image snapshots
1a4d34c
Merge branch 'master' into storyshots-add-image-snapshots
thomasbertet b104897
Merge branch 'master' into storyshots-add-image-snapshots
thomasbertet 425937a
Merge branch 'master' into storyshots-add-image-snapshots
thomasbertet 57b06f8
remove extra CI step to build static storybook on unit-test
797f2b7
Merge branch 'master' into storyshots-add-image-snapshots
thomasbertet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, will do !