From d1da2c325cd2bc75fbde4368609946ed18751918 Mon Sep 17 00:00:00 2001 From: Alfie Jones Date: Wed, 29 May 2024 15:53:21 +0100 Subject: [PATCH] adding wait for stories to be ready --- .changeset/violet-ways-run.md | 5 +++++ integrations/storybook/src/browser/stories.ts | 1 + integrations/storybook/src/capture.ts | 11 +++++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 .changeset/violet-ways-run.md diff --git a/.changeset/violet-ways-run.md b/.changeset/violet-ways-run.md new file mode 100644 index 00000000..d6be863c --- /dev/null +++ b/.changeset/violet-ways-run.md @@ -0,0 +1,5 @@ +--- +"@pixeleye/storybook": patch +--- + +Adding wait for stories to be ready diff --git a/integrations/storybook/src/browser/stories.ts b/integrations/storybook/src/browser/stories.ts index 931763e4..392b7947 100644 --- a/integrations/storybook/src/browser/stories.ts +++ b/integrations/storybook/src/browser/stories.ts @@ -30,6 +30,7 @@ interface Channel { export type SBWindow = typeof window & { __STORYBOOK_CLIENT_API__: API; __STORYBOOK_PREVIEW__: { + ready: () => boolean; channel: Channel; storyStoreValue?: { cacheAllCSFFiles: () => Promise; diff --git a/integrations/storybook/src/capture.ts b/integrations/storybook/src/capture.ts index 209f9239..10884774 100644 --- a/integrations/storybook/src/capture.ts +++ b/integrations/storybook/src/capture.ts @@ -44,6 +44,13 @@ export async function captureStories({ } ); + await page.waitForFunction( + () => (window as SBWindow).__STORYBOOK_PREVIEW__?.ready?.(), + { + timeout: 60_000, + } + ); + await Promise.race([ page .waitForFunction( @@ -51,7 +58,7 @@ export async function captureStories({ (window as SBWindow).__STORYBOOK_CLIENT_API__._storyStore! .cacheAllCSFFiles, { - timeout: 60_000, + timeout: 30_000, } ) .catch(() => {}), @@ -61,7 +68,7 @@ export async function captureStories({ (window as SBWindow).__STORYBOOK_PREVIEW__.storyStoreValue! .cacheAllCSFFiles, { - timeout: 60_000, + timeout: 30_000, } ) .catch(() => {}),