Build: Use Playwright setup project for Storybook readiness#34123
Build: Use Playwright setup project for Storybook readiness#34123kasperpeulen wants to merge 3 commits into
Conversation
📝 WalkthroughWalkthroughIntroduces a Playwright e2e setup module that waits for Storybook server readiness by polling Changes
Sequence Diagram(s)sequenceDiagram
participant Test Setup as Playwright<br/>Setup
participant Storybook as Storybook<br/>Server
participant Page as Browser<br/>Page
participant Navigation as Stories<br/>Navigation
Test Setup->>Test Setup: Read STORYBOOK_URL & timeout
loop Poll until ready or timeout
Test Setup->>Storybook: GET /index.json
Storybook-->>Test Setup: Check for example-button--primary
end
Test Setup->>Page: Navigate to story URL
Test Setup->>Navigation: Locate navigation element
Test Setup->>Navigation: Locate selected story
Test Setup->>Page: Verify navigation visibility
Test Setup->>Page: Verify story visibility
Test Setup->>Page: waitUntilLoaded()
Page-->>Test Setup: Ready for tests
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
📝 Coding Plan
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
code/e2e-tests/storybook.setup.ts (1)
7-8: Extract the story id into one constant to prevent selector/assert drift.
example-button--primaryis duplicated across URL, poll assertion, and locator filters; a single constant reduces maintenance mistakes.Suggested refactor
const STORYBOOK_READY_TIMEOUT = 200000; +const READY_STORY_ID = 'example-button--primary'; const storybookUrl = process.env.STORYBOOK_URL || 'http://localhost:8001'; -const storybookReadyPath = `${storybookUrl}/?path=/story/example-button--primary`; +const storybookReadyPath = `${storybookUrl}/?path=/story/${READY_STORY_ID}`; @@ - return index?.entries?.['example-button--primary']?.id; + return index?.entries?.[READY_STORY_ID]?.id; @@ - .toBe('example-button--primary'); + .toBe(READY_STORY_ID); @@ const selectedStory = storiesNavigation.locator( - '[data-item-id="example-button--primary"][data-selected="true"]' + `[data-item-id="${READY_STORY_ID}"][data-selected="true"]` );Also applies to: 23-23, 31-31, 37-37
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@code/e2e-tests/storybook.setup.ts` around lines 7 - 8, Extract the story id string ("example-button--primary") into a single constant (e.g., const STORY_ID = 'example-button--primary') and use that constant everywhere the literal appears instead of repeating it: build storybookReadyPath using STORY_ID (replace storybookReadyPath), use STORY_ID in the poll/assert checks and in any locator/filter selectors referenced in this file (where the literal is currently duplicated). This ensures a single source of truth for the story id and prevents selector/assert drift.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@code/e2e-tests/storybook.setup.ts`:
- Around line 7-8: Extract the story id string ("example-button--primary") into
a single constant (e.g., const STORY_ID = 'example-button--primary') and use
that constant everywhere the literal appears instead of repeating it: build
storybookReadyPath using STORY_ID (replace storybookReadyPath), use STORY_ID in
the poll/assert checks and in any locator/filter selectors referenced in this
file (where the literal is currently duplicated). This ensures a single source
of truth for the story id and prevents selector/assert drift.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: f9e8b10d-198f-428d-b369-65796b5089c0
📒 Files selected for processing (2)
code/e2e-tests/storybook.setup.tscode/playwright.config.ts
Closes #
What I did
Moved Storybook readiness for Playwright browser tasks into a dedicated Playwright setup project. The setup test waits for
/index.jsonto exposeexample-button--primary, opens that route, verifies the manager has selected the story, and then waits for the preview to settle before the rest of the Playwright suite runs.This keeps the readiness check inside Playwright instead of mixing task-level waits with a separate browser bootstrap path.
Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
Caution
This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!
nx run vue3-vite/default-ts:e2e-tests-dev:production.setupproject first./index.json, opens/?path=/story/example-button--primary, and only then starts the main browser tests.I did not run this locally in this worktree because Yarn dependencies are not installed here.
Documentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal,ci:mergedorci:dailyGH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli-storybook/src/sandbox-templates.tsMake sure this PR contains one of the labels below:
Available labels
bug: Internal changes that fixes incorrect behavior.maintenance: User-facing maintenance tasks.dependencies: Upgrading (sometimes downgrading) dependencies.build: Internal-facing build tooling & test updates. Will not show up in release changelog.cleanup: Minor cleanup style change. Will not show up in release changelog.documentation: Documentation only changes. Will not show up in release changelog.feature request: Introducing a new feature.BREAKING CHANGE: Changes that break compatibility in some way with current major version.other: Changes that don't fit in the above categories.🦋 Canary release
This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the
@storybookjs/coreteam here.core team members can create a canary release here or locally with
gh workflow run --repo storybookjs/storybook publish.yml --field pr=<PR_NUMBER>