Skip to content

Commit

Permalink
fix: Wait for storybook to actually mount the story (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
Auroratide authored and github_actions committed Sep 19, 2023
1 parent 27fd7ff commit 5251004
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ To include in a `batect.yml`, you need to add the following block:
include:
- type: git
repo: https://github.com/compoze-labs/storyshots.git
ref: 0.9.1
ref: 0.9.2
```
Once included, you will now have access to two tasks: `./batect storyshots` and `./batect storyshots-update`. However, these two commands will also need to know where to find your pre-built Storybook directory:
Expand Down
2 changes: 1 addition & 1 deletion batect-bundle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ config_variables:

containers:
storyshots:
image: eichelkrautadam/storyshots:0.9.1
image: eichelkrautadam/storyshots:0.9.2
volumes:
- local: <{batect.project_directory}/<{resultsDirectory}
container: /storyshots/storyshots
Expand Down
6 changes: 6 additions & 0 deletions runtime/storyshots.testStory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export async function testStory(page: Page, { storyshot, url, ignore, title }: S
}

await page.goto(url, { waitUntil: 'domcontentloaded' })
await waitForStoryReady(page)

if (waitForStableMillis > 0) {
await waitForStable(page, waitForStableMillis, waiting)
Expand Down Expand Up @@ -56,6 +57,11 @@ export async function testStory(page: Page, { storyshot, url, ignore, title }: S
return storyPassed
}

async function waitForStoryReady(page: Page) {
await page.locator('#storybook-root > *:first-child')
.waitFor({ state: 'attached', timeout: 5000 })
}

// continually take screenshots until the page is stable (i.e. no more animations)
async function waitForStable(page: Page, waitForStableMillis: number, waiting: (message: string) => Promise<void>) {
let stable = false
Expand Down

0 comments on commit 5251004

Please sign in to comment.