Skip to content

Commit

Permalink
🐛 ✨Fix eval setCurrentStory error + make logging better (#837)
Browse files Browse the repository at this point in the history
* fix: load existing story instead of iframe.html

* fix: reject with reason instead of nothing (undefined)

* fix: reject with Error object instead of string

* test: update expectations for storyErrored event

* feat: throw error or constant string when err missing
  • Loading branch information
nilshah98 authored Nov 9, 2023
1 parent 83b5369 commit 1fd15cb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/snapshots.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 4 additions & 4 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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')));
});
});
}

0 comments on commit 1fd15cb

Please sign in to comment.