Skip to content

Conversation

@jandrade
Copy link
Member

@jandrade jandrade commented Dec 3, 2025

Summary:

Some time ago, we disabled Storybook CI tests because of an issue with
Chromatic. This PR re-enables the tests to ensure that the tests are run
when we publish a new build to Chromatic using the latest Storybook version (v10).

As part of the fix, I've moved the SB testing workflow to a separate GH job. By doing this, I finally identified the issue and made changes to fix this job.

Next PR will include enabling a11y automated tests via CI (and locally).

Issue: https://khanacademy.atlassian.net/browse/WB-1936

Test plan:

Verify that the Storybook CI tests are run when we publish a new Chromatic build
and that the tests pass.

@jandrade jandrade self-assigned this Dec 3, 2025
@changeset-bot
Copy link

changeset-bot bot commented Dec 3, 2025

🦋 Changeset detected

Latest commit: 21261f0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Dec 3, 2025

npm Snapshot: NOT Published

🤕 Oh noes!! We couldn't find any changesets in this PR (ef65cd5). As a result, we did not publish an npm snapshot for you.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 3, 2025

Size Change: 0 B

Total Size: 109 kB

ℹ️ View Unchanged
Filename Size
packages/wonder-blocks-accordion/dist/es/index.js 3 kB
packages/wonder-blocks-announcer/dist/es/index.js 1.74 kB
packages/wonder-blocks-badge/dist/es/index.js 2.02 kB
packages/wonder-blocks-banner/dist/es/index.js 2.01 kB
packages/wonder-blocks-birthday-picker/dist/es/index.js 1.92 kB
packages/wonder-blocks-breadcrumbs/dist/es/index.js 755 B
packages/wonder-blocks-button/dist/es/index.js 4.25 kB
packages/wonder-blocks-card/dist/es/index.js 1.06 kB
packages/wonder-blocks-cell/dist/es/index.js 2.18 kB
packages/wonder-blocks-clickable/dist/es/index.js 2.66 kB
packages/wonder-blocks-core/dist/es/index.js 2.48 kB
packages/wonder-blocks-data/dist/es/index.js 5.48 kB
packages/wonder-blocks-dropdown/dist/es/index.js 19.4 kB
packages/wonder-blocks-form/dist/es/index.js 6.2 kB
packages/wonder-blocks-grid/dist/es/index.js 1.24 kB
packages/wonder-blocks-icon-button/dist/es/index.js 3.2 kB
packages/wonder-blocks-icon/dist/es/index.js 1.91 kB
packages/wonder-blocks-labeled-field/dist/es/index.js 3.48 kB
packages/wonder-blocks-layout/dist/es/index.js 1.63 kB
packages/wonder-blocks-link/dist/es/index.js 1.52 kB
packages/wonder-blocks-modal/dist/es/index.js 7.06 kB
packages/wonder-blocks-pill/dist/es/index.js 1.31 kB
packages/wonder-blocks-popover/dist/es/index.js 4.3 kB
packages/wonder-blocks-progress-spinner/dist/es/index.js 1.48 kB
packages/wonder-blocks-search-field/dist/es/index.js 1.1 kB
packages/wonder-blocks-styles/dist/es/index.js 464 B
packages/wonder-blocks-switch/dist/es/index.js 1.55 kB
packages/wonder-blocks-tabs/dist/es/index.js 3.74 kB
packages/wonder-blocks-testing-core/dist/es/index.js 3.25 kB
packages/wonder-blocks-testing/dist/es/index.js 978 B
packages/wonder-blocks-theming/dist/es/index.js 384 B
packages/wonder-blocks-timing/dist/es/index.js 1.37 kB
packages/wonder-blocks-tokens/dist/es/index.js 5.01 kB
packages/wonder-blocks-toolbar/dist/es/index.js 906 B
packages/wonder-blocks-tooltip/dist/es/index.js 6.4 kB
packages/wonder-blocks-typography/dist/es/index.js 1.57 kB

compressed-size-action

@github-actions
Copy link
Contributor

github-actions bot commented Dec 3, 2025

A new build was pushed to Chromatic! 🚀

https://5e1bf4b385e3fb0020b7073c-qcidnnemwq.chromatic.com/

Chromatic results:

Metric Total
Captured snapshots 448
Tests with visual changes 0
Total stories 747
Inherited (not captured) snapshots [TurboSnap] 0
Tests on the build 448

@jandrade jandrade changed the title [WB-1936] Re-enable Storybook CI tests [WB-1936] Re-enable Storybook CI tests + Storybook v10 Dec 5, 2025
Comment on lines +99 to +101
# Exit with status 0 (OK) once the built version has been published to
# Chromatic.
exitOnceUploaded: true
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: Added this as we don't have to wait for the build process to finish. We already have the info we need at this point.

# See: https://www.chromatic.com/docs/turbosnap
onlyChanged: true

# TODO(WB-1936): Re-enable this check once the issue with Chromatic
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: Moved this to chromatic-pr.yml as a separate job, that way we can isolate testing failures from the build step.

Comment on lines +108 to +119
# Install Playwright browsers so Vitest browser mode can run story tests
- name: Install playwright dependencies
run: pnpm exec playwright install chromium --with-deps

# Build the project
- name: Generate WB build artifacts
run: pnpm build

- name: Run Storybook tests
run: pnpm test:storybook
env:
SB_URL: '${{ needs.chromatic_review.outputs.storybookUrl }}'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: This is what I moved from chromatic-build.yml. The other steps are requirements for this to succeed.

},
},
docs: {
codePanel: true,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: Learned about this and added it to the project: https://storybook.js.org/docs/writing-docs/code-panel

Screenshot 2025-12-05 at 10 06 27 AM

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool!

Comment on lines -147 to -157
if (enableRenderStateRootDecorator) {
return (
<RenderStateRoot key={localTheme}>
<ThemeSwitcherContext.Provider value={theme}>
<ThemeSwitcher theme={theme}>
<Story />
</ThemeSwitcher>
</ThemeSwitcherContext.Provider>
</RenderStateRoot>
);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: This is no longer used, so I got rid of it.

Comment on lines +19 to +21
args: {
locale: "en-US",
},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: I highly suspect this was the step that was causing the testing timeouts that led us to disable SB tests in CI months ago.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh interesting! Before we introduced the locale prop, we were using navigator.language to get the locale (which wasn't the same locale as the user's kaLocale). Was the SB test issue related to navigator.language?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so.... I checked in the console and navigator.language was returning en, and Intl.DateTimeFormat expects the local to follow BCP 47 language format: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#locales

According to the docs, en should be valid, but for some reason, SB tests break b/c it expects the region part of the locale to be present: https://developer.mozilla.org/en-US/docs/Glossary/BCP_47_language_tag#bcp_47_syntax

My guess is that the headless browser triggered by Playwright fails to process the date correctly, and that's why we have to provide the both the language and region subtags.

e.g. en-US instead of en.

Comment on lines +650 to +652
field={
<TextField id="foo" value="bar" onChange={() => {}} />
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: Refactored this to remove some warnings in the console (adds noise to the test logs).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: Same reason.... added these keys to prevent warnings in the browser (you can see similar changes in other files).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hehe thanks!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: As part of figuring out the SB test issue, I decided to upgrade to v10, and as I noticed that the changes were minimal, I decided to go with it in this PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: Refactored this file to adopt the most up-to-date recommendations from the Storybook team.

https://storybook.js.org/docs/writing-tests/integrations/vitest-addon#example-configuration-files

@jandrade jandrade changed the title [WB-1936] Re-enable Storybook CI tests + Storybook v10 [WB-1936.1] Re-enable Storybook CI tests + Storybook v10 Dec 5, 2025
@jandrade jandrade marked this pull request as ready for review December 5, 2025 15:11
@khan-actions-bot khan-actions-bot requested a review from a team December 5, 2025 15:12
@khan-actions-bot
Copy link
Contributor

khan-actions-bot commented Dec 5, 2025

Gerald

Required Reviewers
  • @Khan/wonder-blocks for changes to package.json, pnpm-lock.yaml, pnpm-workspace.yaml, vitest.config.ts, .changeset/sour-dingos-play.md, .storybook/main.ts, .storybook/preview.tsx, .storybook/vitest.setup.ts, .github/workflows/chromatic-build.yml, .github/workflows/chromatic-pr.yml, __docs__/components/icons-for-testing.tsx, __docs__/wonder-blocks-birthday-picker/birthday-picker.stories.tsx, __docs__/wonder-blocks-button/button.stories.tsx, __docs__/wonder-blocks-tabs/navigation-tabs-testing-snapshots.stories.tsx, __docs__/wonder-blocks-tabs/navigation-tabs-utils.tsx, __docs__/wonder-blocks-tabs/navigation-tabs.stories.tsx, packages/wonder-blocks-popover/src/components/__tests__/popover.test.tsx

Don't want to be involved in this pull request? Comment #removeme and we won't notify you of further changes.

Copy link
Member

@beaesguerra beaesguerra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Thanks for these fixes and upgrades! Left some non-blocking questions :)

},
},
docs: {
codePanel: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool!

Comment on lines +19 to +21
args: {
locale: "en-US",
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh interesting! Before we introduced the locale prop, we were using navigator.language to get the locale (which wasn't the same locale as the user's kaLocale). Was the SB test issue related to navigator.language?

"../__docs__/**/*.mdx",
],
addons: [
getAbsolutePath("@storybook/addon-a11y"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh interesting, I thought the getAbsolutePath changes were auto-generated when we used storybook to migrate versions for us! (Looks like we ran pnpm dlx @storybook/latest upgrade in 4c03506 last time!)

Were you able to use the migration tool also to upgrade to Storybook 10? Or is it something we should do manually instead!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question! I used the upgrade tool for it, but I then I got rid of the require part manually as we don't need it. (I still think running the upgrade script is the recommended solution!).

<rect id="path-1" x="0" y="0" width="256" height="256" rx="8" />
</defs>
<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g stroke="none" strokeWidth="1" fill="none" fillRule="evenodd">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hehe thanks!

import {View} from "@khanacademy/wonder-blocks-core";
import Button from "@khanacademy/wonder-blocks-button";

import {fireEvent} from "storybook/test";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh interesting! How do we know when we should import from @testing-library/react vs storybook/test?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should always use @tl/react in *.test.tsx files and use storybook/test in *.stories.tsx files that contain interaction tests. I'm not sure why this was working before tbh :)

"remark-gfm": "^4.0.0",
"rollup": "^2.79.2",
"rollup-plugin-node-externals": "^8.0.0",
"storybook": "catalog:",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove storybook from pnpm-workspace.yaml? Or keep versions in that file and use catalog:? (I'm still not 100% sure when should define version numbers in the catalog!)

storybook: ^9.1.8

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh good call! I'll remove it from the catalog. I think for the storybook case, it is better to keep versions in package.json directly for the following reasons:

  1. The SB upgrade migration tool makes changes directly in package.json (it doesn't support workspaces).
  2. Unfortunately, pnpm doesn't have a way to update pnpm-workspace versions when running pnpm add or pnpm up (at least in the pnpm version we use). It looks like a newer version kinda does that: https://pnpm.io/cli/add#--save-catalog, but I don't think the SB update tool supports it.

@jandrade jandrade merged commit c7175d0 into main Dec 5, 2025
16 checks passed
@jandrade jandrade deleted the sb-ci-fix branch December 5, 2025 18:34
@codecov
Copy link

codecov bot commented Dec 8, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 0.00%. Comparing base (5036747) to head (21261f0).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@     Coverage Diff      @@
##   main   #2887   +/-   ##
============================
============================

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5036747...21261f0. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants