Skip to content

Storybook: Test that component statuses match the use-recommended-components denylist - #86799

Merged
mirka merged 11 commits into
trunkfrom
test-component-status-denylist-consistency
Nov 23, 2026
Merged

mirka merged 11 commits into
trunkfrom
test-component-status-denylist-consistency

Conversation

@mirka

@mirka mirka commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

What?

Follow-up to #85764.

Adds a unit test that keeps the Storybook statuses of @wordpress/components stories consistent with the use-recommended-components denylist, the manifest tag, and the migration guide links. Also runs the unit tests in CI for changes to Storybook's tests and the modules they import. Apart from the NumberControl exception recorded in the test, trunk already passes.

Why?

#85764 documents that a legacy component's Storybook status, manifest tag, and denylist entry must agree, and that "a not-recommended status and a denylist entry always change together". Nothing enforced this, and these sources had drifted on trunk for Spinner, SelectControl, CustomGradientPicker, NumberControl, the private Menu, and the manifest tag of BaseControl. Most of those were fixed by hand. With this test, the next drift fails in the PR that introduces it.

The unit test workflow skipped every change under storybook/, so a PR that changes only this test or the status-indexer.ts it imports would not have run it.

How?

The test parses the stories with the same CSF parser and status reader as the Storybook sidebar, and matches a story to a denylist entry by its meta component name, without the __experimental export prefix. A story whose component is imported from another package is not matched, so the @wordpress/ui SelectControl in the CustomSelectControl migration examples does not count as a story of the legacy SelectControl.

Testing Instructions

  1. Make these temporary changes, run npm run test:unit -- storybook/test/component-status.test.ts, and confirm each one is reported with the file to change:
    1. Remove the Spinner entry from the denylist in packages/eslint-plugin/rules/use-recommended-components.js.
    2. Remove the migration guide link from the Tip denylist message.
    3. Remove FlexItem from the subcomponents of the Flex story.
    4. Add tags: [ 'manifest' ] to the Tooltip story meta.
    5. Change the TextControl story status to use-with-caution.
    6. Change the NumberControl story status to use-with-caution.
  2. Revert the changes.

With all six changes applied, five of the six tests failed with these messages:

"Spinner is \"not-recommended\" in packages/components/src/spinner/stories/index.story.tsx, but is not in DENYLIST in packages/eslint-plugin/rules/use-recommended-components.js. Add a denylist entry, or change the story's status."
"TextControl is in DENYLIST in packages/eslint-plugin/rules/use-recommended-components.js, but its status in packages/components/src/text-control/stories/index.story.tsx is \"use-with-caution\". Set the story's status to \"not-recommended\", or remove the denylist entry."
"NumberControl no longer needs an entry in NOT_RECOMMENDED_WITHOUT_DENYLIST_ENTRY in this test. Remove it."
"packages/components/src/tooltip/stories/index.story.tsx is \"not-recommended\" but has the `manifest` tag on its meta or a story. Remove the tag, then run `npm run storybook:build` and `npm run storybook:manifest-snapshot`."
"The Tip message in DENYLIST in packages/eslint-plugin/rules/use-recommended-components.js does not link packages/components/src/tip/stories/migration-guide.mdx. Add \"See the migration guide: https://wordpress.github.io/gutenberg/?path=/docs/components-tip--migration-guide\"."
"FlexItem is in DENYLIST in packages/eslint-plugin/rules/use-recommended-components.js, but no story under packages/components has it as its `component` or lists it in `subcomponents`. Keep a \"not-recommended\" story for it, list it in its parent story's `subcomponents`, or remove the denylist entry if the component no longer exists."

…ponents denylist

Check that a not-recommended @wordpress/components story has a denylist
entry and no manifest tag, that a denylisted component's story is
not-recommended, and that migration guides and their denylist links match.
NumberControl is recorded as the one deliberate exception.
@mirka mirka added the [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. label Nov 13, 2026
@mirka mirka self-assigned this Nov 13, 2026
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground Preview in Storybook

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: ciampo <mciampini@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

📦 Bundle size

Size Change: 0 B

Total Size: 8.69 MB

0a7a891 Run

Run unit tests for changes under storybook/, which now holds unit tests.
Exempt NumberControl only from a missing denylist entry, report stories
and guides the test cannot read, read <Meta> attributes in any order, and
point to the manifest regeneration commands.
…list

Keep skipping unit tests for most changes under storybook/, and run them
only for its tests and the top-level modules they import. Record the
NumberControl exception's reason in a code comment.
@mirka
mirka requested a review from a team November 13, 2026 14:46
@mirka
mirka marked this pull request as ready for review November 13, 2026 15:42
@mirka
mirka requested a review from desrosj as a code owner November 13, 2026 15:42
@github-actions
github-actions Bot requested review from aduth and ciampo November 13, 2026 15:43
Comment thread storybook/test/component-status.test.ts Outdated
( [ key, message ] ) =>
[
...message.matchAll(
/\?path=\/docs\/([\w-]+--migration-guide)/g

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we capture the entire docs ID here rather than stop at --migration-guide? Changing ProgressBar's link to components-progressbar--migration-guide-typo still passes all six tests because this matcher and the earlier includes() check both accept the valid prefix.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The -typo case now fails. I also tried appending .typo to ProgressBar's guide URL and changing --migration-guide to --migration-guie in TextControl's link. Both still pass. Could we identify guide links from the message and compare the full path query value with the known guide paths?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This part was only meant as a quick convenience check, and not a central part of the overall test. The more we try to add coverage for all the possible failure cases here, the more it gets harder to add a Storybook link that's not a migration guide. Since nobody prepares PRs by hand anymore and typos or wrong links are no longer a common failure mode, I'd be fine with removing this check altogether if it's adding a false sense of coverage.

A link with extra characters after --migration-guide passed both link
checks, because they matched the valid prefix.
@mirka
mirka requested a review from ciampo November 17, 2026 11:33
Comment thread storybook/test/component-status.test.ts Resolved
Comment thread storybook/test/component-status.test.ts Resolved
Comment thread storybook/test/component-status.test.ts Outdated
( [ key, message ] ) =>
[
...message.matchAll(
/\?path=\/docs\/([\w-]+--migration-guide)/g

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The -typo case now fails. I also tried appending .typo to ProgressBar's guide URL and changing --migration-guide to --migration-guie in TextControl's link. Both still pass. Could we identify guide links from the message and compare the full path query value with the known guide paths?

Treat every Storybook link in a denylist message as a migration guide link
and compare its full path query value, so typos after or inside the
--migration-guide suffix fail. Read the manifest tag from each story's
combined tags, since a story can opt in to the manifest on its own.
Allow links to other Storybook pages in denylist messages, and keep
comparing the whole path of each migration guide link.
const denylist = DENYLIST[ '@wordpress/components' ];
const denylistEntriesByComponent = new Map(
Object.entries( denylist ).map( ( [ key, message ] ) => [
key.replace( /^__experimental/, '' ),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Changing the denylist key from __experimentalInputControl to InputControl leaves all six tests green, but ESLint then allows imports of __experimentalInputControl. Could we check each original key against the package’s public exports and private API names before stripping the prefix to match the story?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't think that's worth the complexity here, especially since it's not a failure that has actually happened. The purpose of this PR is to prevent failure cases that have actually happened multiple times, not to cover all possible failures. If we decide at some point that we do want coverage for that, it should live with the lint rule though, not this Storybook component status test.

Count a denylist entry as covered when a story has it as its component or
lists it in subcomponents, so a removed or renamed story no longer drops
its denylist entry from the check. Remove the check that guide links point
to existing guides, which mostly repeated the link check for
not-recommended components.
const componentsWithStories = new Set(
componentStories.flatMap( ( { component, subcomponents } ) => [
component,
...subcomponents,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Adding PanelRow to the denylist leaves all six tests green, even though its only story marks Panel as recommended. When a denylisted component is documented under a parent, could we check that the parent story is marked not-recommended?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is probably better to leave as is. Not being able to mark just a single subcomponent with a status is a limitation of Storybook, not necessarily a sign of drift. There are valid cases where a subcomponent is unrecommended earlier than rest of the family, and it's very likely intentional if only a subcomponent is listed in the lint rule (i.e. not something that would/has happened by mistake).

A denylisted component documented only in a story's subcomponents now
needs that story to be not-recommended, like a component with its own
story.
A story's status covers the whole page, so a subcomponent it lists can be
denylisted while the parent stays recommended.
@mirka
mirka requested a review from ciampo November 20, 2026 16:37

@ciampo ciampo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM 🚀

@mirka
mirka enabled auto-merge (squash) November 23, 2026 09:55
@mirka
mirka disabled auto-merge November 23, 2026 13:15
@mirka
mirka merged commit 7cb7fae into trunk Nov 23, 2026
117 of 126 checks passed
@mirka
mirka deleted the test-component-status-denylist-consistency branch November 23, 2026 13:16
@github-actions github-actions Bot added this to the Gutenberg 24.6 milestone Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants