From c76d9ec60b26ac24f377165d3293b824002788fc Mon Sep 17 00:00:00 2001 From: nilshah98 Date: Tue, 31 Oct 2023 20:54:22 +0530 Subject: [PATCH 1/5] fix: load existing story instead of iframe.html --- src/snapshots.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/snapshots.js b/src/snapshots.js index 2b56d426..d02fad32 100644 --- a/src/snapshots.js +++ b/src/snapshots.js @@ -199,7 +199,9 @@ export async function* takeStorybookSnapshots(percy, callback, { baseUrl, flags while (snapshots.length) { try { // use a single page to capture story snapshots without reloading - yield* withPage(percy, previewUrl, async function*(page) { + // loading an existing story instead of just iframe.html as that triggers `storyMissing` event + // This in turn leads to promise rejection and failure + yield* withPage(percy, `${previewUrl}?id=${snapshots[0].id}&viewMode=story`, async function*(page) { // determines when to retry page crashes lastCount = snapshots.length; From 36a5dcedf51048f4e78816afc43dfbec514d5915 Mon Sep 17 00:00:00 2001 From: nilshah98 Date: Tue, 31 Oct 2023 21:03:22 +0530 Subject: [PATCH 2/5] fix: reject with reason instead of nothing (undefined) --- src/utils.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/utils.js b/src/utils.js index f8d428c6..3ae765f6 100644 --- a/src/utils.js +++ b/src/utils.js @@ -142,7 +142,7 @@ export async function* withPage(percy, url, callback, retry) { return yield* yieldTo(callback(page)); } catch (error) { // if the page crashed and retry returns truthy, try again - if (error?.message?.includes('crashed') && retry?.()) { + if (error.message?.includes('crashed') && retry?.()) { return yield* withPage(...arguments); } @@ -247,9 +247,9 @@ export function evalSetCurrentStory({ waitFor }, story) { // resolve when rendered, reject on any other renderer event return new Promise((resolve, reject) => { channel.on('storyRendered', resolve); - channel.on('storyMissing', reject); - channel.on('storyErrored', reject); - channel.on('storyThrewException', reject); + channel.on('storyMissing', () => reject('Story Missing')); + channel.on('storyErrored', () => reject('Story Errored')); + channel.on('storyThrewException', () => reject('Story Threw Exception')); }); }); } From d55f7c076b8f465850adfb7bbed0c0d9dc8db88f Mon Sep 17 00:00:00 2001 From: nilshah98 Date: Tue, 31 Oct 2023 21:12:56 +0530 Subject: [PATCH 3/5] fix: reject with Error object instead of string --- src/utils.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils.js b/src/utils.js index 3ae765f6..3459fed0 100644 --- a/src/utils.js +++ b/src/utils.js @@ -247,9 +247,9 @@ export function evalSetCurrentStory({ waitFor }, story) { // resolve when rendered, reject on any other renderer event return new Promise((resolve, reject) => { channel.on('storyRendered', resolve); - channel.on('storyMissing', () => reject('Story Missing')); - channel.on('storyErrored', () => reject('Story Errored')); - channel.on('storyThrewException', () => reject('Story Threw Exception')); + channel.on('storyMissing', () => reject(new Error('Story Missing'))); + channel.on('storyErrored', () => reject(new Error('Story Errored'))); + channel.on('storyThrewException', () => reject(new Error('Story Threw Exception'))); }); }); } From 254b3266ea3e645c87eab7b3430564cf30a49526 Mon Sep 17 00:00:00 2001 From: nilshah98 Date: Tue, 31 Oct 2023 21:26:41 +0530 Subject: [PATCH 4/5] test: update expectations for storyErrored event --- test/storybook.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/storybook.test.js b/test/storybook.test.js index d652ddef..4f09ff1d 100644 --- a/test/storybook.test.js +++ b/test/storybook.test.js @@ -156,12 +156,12 @@ describe('percy storybook', () => { await expectAsync(storybook(['http://localhost:8000'])) // message contains the client stack trace - .toBeRejectedWithError(/^Story Error\n.*\/iframe\.html.*$/s); + .toBeRejectedWithError(/^Story Errored\n.*\/iframe\.html.*$/s); expect(logger.stderr).toEqual([ '[percy] Build not created', // message contains the client stack trace - jasmine.stringMatching(/^\[percy\] Error: Story Error\n.*\/iframe\.html.*$/s) + jasmine.stringMatching(/^\[percy\] Error: Story Errored\n.*\/iframe\.html.*$/s) ]); }); @@ -191,7 +191,7 @@ 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 Errored\n.*\/iframe\.html.*$/s), // does not create a build if all stories failed [ 1 in this case ] '[percy] Build not created' ]); From 6376d33c2e41882767d99521f0a22511ba2ff28d Mon Sep 17 00:00:00 2001 From: nilshah98 Date: Fri, 3 Nov 2023 00:11:59 +0530 Subject: [PATCH 5/5] feat: throw error or constant string when err missing --- src/utils.js | 6 +++--- test/storybook.test.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/utils.js b/src/utils.js index 3459fed0..f7882904 100644 --- a/src/utils.js +++ b/src/utils.js @@ -247,9 +247,9 @@ export function evalSetCurrentStory({ waitFor }, story) { // resolve when rendered, reject on any other renderer event return new Promise((resolve, reject) => { channel.on('storyRendered', resolve); - channel.on('storyMissing', () => reject(new Error('Story Missing'))); - channel.on('storyErrored', () => reject(new Error('Story Errored'))); - channel.on('storyThrewException', () => reject(new Error('Story Threw Exception'))); + channel.on('storyMissing', (err) => reject(err || new Error('Story Missing'))); + channel.on('storyErrored', (err) => reject(err || new Error('Story Errored'))); + channel.on('storyThrewException', (err) => reject(err || new Error('Story Threw Exception'))); }); }); } diff --git a/test/storybook.test.js b/test/storybook.test.js index 4f09ff1d..d652ddef 100644 --- a/test/storybook.test.js +++ b/test/storybook.test.js @@ -156,12 +156,12 @@ describe('percy storybook', () => { await expectAsync(storybook(['http://localhost:8000'])) // message contains the client stack trace - .toBeRejectedWithError(/^Story Errored\n.*\/iframe\.html.*$/s); + .toBeRejectedWithError(/^Story Error\n.*\/iframe\.html.*$/s); expect(logger.stderr).toEqual([ '[percy] Build not created', // message contains the client stack trace - jasmine.stringMatching(/^\[percy\] Error: Story Errored\n.*\/iframe\.html.*$/s) + jasmine.stringMatching(/^\[percy\] Error: Story Error\n.*\/iframe\.html.*$/s) ]); }); @@ -191,7 +191,7 @@ 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 Errored\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' ]);