diff --git a/src/snapshots.js b/src/snapshots.js index 0a087609..961c13b1 100644 --- a/src/snapshots.js +++ b/src/snapshots.js @@ -225,17 +225,15 @@ export async function* takeStorybookSnapshots(percy, callback, { baseUrl, flags return lastCount > snapshots.length; }); } catch (e) { - // if we get an exception while capturing a story - // - we want to print error - // - skip story - // - continue capturing stories on a new page to avoid weird page states - let { name } = snapshots[0]; - - log.error(`Failed to capture story: ${name}`); - log.error(e); - - // ignore story - snapshots.shift(); + if (process.env.PERCY_SKIP_STORY_ON_ERROR == 'true') { + let { name } = snapshots[0]; + log.error(`Failed to capture story: ${name}`); + log.error(e); + // ignore story + snapshots.shift(); + } else { + throw e; + } } } diff --git a/test/storybook.test.js b/test/storybook.test.js index 51bf551e..d60da94b 100644 --- a/test/storybook.test.js +++ b/test/storybook.test.js @@ -155,6 +155,37 @@ describe('percy storybook', () => { ]); }); + describe('with PERCY_SKIP_STORY_ON_ERROR set to true', () => { + beforeAll(() => { + process.env.PERCY_SKIP_STORY_ON_ERROR = true; + }); + + afterAll(() => { + delete process.env.PERCY_SKIP_STORY_ON_ERROR; + }); + + it('skips the story and logs the error but does not break build', async () => { + server.reply('/iframe.html', () => [200, 'text/html', [ + ``, + `` + ].join('')]); + + // does not reject + await storybook(['http://localhost:8000']); + + // contains logs of story error + 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) + ]); + }); + }); + it('uses the preview dom when javascript is enabled', async () => { let previewDOM = '

This is the preview

'; let i = 0;