Skip to content

Commit

Permalink
Added a comment and fixed test
Browse files Browse the repository at this point in the history
  • Loading branch information
ninadbstack committed Oct 13, 2023
1 parent ed6f949 commit 25c2b8a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/snapshots.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@ export async function* takeStorybookSnapshots(percy, callback, { baseUrl, flags
// set storybook environment info
percy.client.addEnvironmentInfo(environmentInfo);

// We use an outer and inner loop on same snapshots.length
// - we create a new page and load one story on it at a time for snapshotting
// - if it throws exception then we want to catch it outside of `withPage` call as
// when `withPage` returns it closes the page
// - we want to make sure we close the page that had exception in story to make sure
// we dont reuse a page which is possibly in a weird state due to last exception
// - so post exception we come out of inner loop and skip the story, create new page
// using outer loop and continue next stories again on a new page
while (snapshots.length) {
try {
// use a single page to capture story snapshots without reloading
Expand Down
4 changes: 3 additions & 1 deletion test/storybook.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ describe('percy storybook', () => {
expect(logger.stderr).toEqual([
'[percy] Failed to capture story: foo: bar',
// error logs contain the client stack trace
jasmine.stringMatching(/^\[percy\] Error: Story Error\n.*\/iframe\.html.*$/s)
jasmine.stringMatching(/^\[percy\] Error: Story Error\n.*\/iframe\.html.*$/s),
// does not create a build if all stories failed [ 1 in this case ]
'[percy] Build not created'
]);
});
});
Expand Down

0 comments on commit 25c2b8a

Please sign in to comment.