Skip to content

fix(test): correct Storybook serve config so visual stories actually render#1094

Merged
TaprootFreak merged 1 commit into
test/modal-visual-regressionfrom
test/modal-visual-baseline-seed
May 12, 2026
Merged

fix(test): correct Storybook serve config so visual stories actually render#1094
TaprootFreak merged 1 commit into
test/modal-visual-regressionfrom
test/modal-visual-baseline-seed

Conversation

@TaprootFreak

Copy link
Copy Markdown
Collaborator

Stacked on top of #1093.

What

Two correctness bugs discovered while extracting the initial baselines from the first CI run of #1093:

1. serve strips .html and drops the query string

npx serve storybook-static defaults to cleanUrls: true — it 301-redirects /iframe.html?id=…&viewMode=story to /iframe, losing the query string in the redirect. Storybook receives no story id and falls back to its "No Preview" screen.

Effect on the previous baseline run: all three stories captured the same empty fallback page. The test would have been green for any future Modal regression because every snapshot was already identical garbage.

Fix: Ship .storybook/static/serve.json with cleanUrls: false via Storybook's staticDirs, so the built bundle is self-contained and serves correctly to anything that reads serve.json.

2. snapshotPathTemplate mismatch with actuals

The template included {projectName} (→ …-chromium-linux.png), but the -actual.png files Playwright writes on snapshot mismatch carry no project suffix. Re-shaping them into the baseline directory produced filenames the next run wouldn't look for.

Fix: Drop -{projectName} from the template. Single-project setup; if we add Firefox/WebKit later we re-add the segment.

Verified locally

  • npm run build-storybook ships serve.json into storybook-static/.
  • curl -I http://localhost:6006/iframe.html?id=… returns 200, not 301.
  • playwright test --update-snapshots produces three visually distinct PNGs:
    • Default and Fullscreen are byte-identical (by design — that's the regression guard).
    • Dialog renders the centered card on the dim backdrop.

Next step

Once this PR is merged into test/modal-visual-regression, the parent PR's next CI run will produce real baselines in visual-regression-diff.zip that can then be committed to seed the snapshots directory.

Two correctness bugs found while seeding the initial baselines:

1. `npx serve storybook-static` strips `.html` extensions by default
   and 301-redirects `/iframe.html?id=…` to `/iframe`, dropping the
   query string. Storybook then has no story to render and falls back
   to its "No Preview" screen — every story was captured as the same
   empty page, so the test could not have detected any layout drift.

   Fix: ship a `serve.json` (cleanUrls: false) as a Storybook static
   asset via `staticDirs`, so the built bundle is self-contained and
   serves correctly to any tool that reads `serve.json`.

2. The snapshot path template referenced `{projectName}` but the
   `<name>-actual.png` files Playwright emits on failure carry no
   project suffix. Re-shaping the actuals into the baseline directory
   layout produced filenames that the next run would not look for.

   Fix: drop `-{projectName}` from snapshotPathTemplate. We only run a
   single project (chromium-linux); adding more later means re-adding
   the segment.

Verified locally that the three stories now render distinctly
(Default == Fullscreen by design, Dialog with backdrop + centered
card), so the regression guard is actually load-bearing.
@TaprootFreak TaprootFreak marked this pull request as ready for review May 12, 2026 15:25
@TaprootFreak TaprootFreak requested a review from davidleomay as a code owner May 12, 2026 15:25
@TaprootFreak TaprootFreak merged commit 1c74af4 into test/modal-visual-regression May 12, 2026
@TaprootFreak TaprootFreak deleted the test/modal-visual-baseline-seed branch May 12, 2026 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant