Skip to content

Commit

Permalink
adding wait for stories to be ready
Browse files Browse the repository at this point in the history
  • Loading branch information
AlfieJones committed May 29, 2024
1 parent 821e076 commit d1da2c3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/violet-ways-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@pixeleye/storybook": patch
---

Adding wait for stories to be ready
1 change: 1 addition & 0 deletions integrations/storybook/src/browser/stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ interface Channel {
export type SBWindow = typeof window & {
__STORYBOOK_CLIENT_API__: API;
__STORYBOOK_PREVIEW__: {
ready: () => boolean;
channel: Channel;
storyStoreValue?: {
cacheAllCSFFiles: () => Promise<void>;
Expand Down
11 changes: 9 additions & 2 deletions integrations/storybook/src/capture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,21 @@ export async function captureStories({
}
);

await page.waitForFunction(
() => (window as SBWindow).__STORYBOOK_PREVIEW__?.ready?.(),
{
timeout: 60_000,
}
);

await Promise.race([
page
.waitForFunction(
() =>
(window as SBWindow).__STORYBOOK_CLIENT_API__._storyStore!
.cacheAllCSFFiles,
{
timeout: 60_000,
timeout: 30_000,
}
)
.catch(() => {}),
Expand All @@ -61,7 +68,7 @@ export async function captureStories({
(window as SBWindow).__STORYBOOK_PREVIEW__.storyStoreValue!
.cacheAllCSFFiles,
{
timeout: 60_000,
timeout: 30_000,
}
)
.catch(() => {}),
Expand Down

0 comments on commit d1da2c3

Please sign in to comment.