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; diff --git a/src/utils.js b/src/utils.js index f8d428c6..f7882904 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', (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'))); }); }); }