From 25c2b8a257e0ad01e03bfa8b719d9f3474289925 Mon Sep 17 00:00:00 2001 From: Ninad Sheth Date: Fri, 13 Oct 2023 17:00:33 +0530 Subject: [PATCH] Added a comment and fixed test --- src/snapshots.js | 8 ++++++++ test/storybook.test.js | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/snapshots.js b/src/snapshots.js index 97d0adc0..2b56d426 100644 --- a/src/snapshots.js +++ b/src/snapshots.js @@ -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 diff --git a/test/storybook.test.js b/test/storybook.test.js index da407177..628bd3ac 100644 --- a/test/storybook.test.js +++ b/test/storybook.test.js @@ -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' ]); }); });