Repository navigation
Storybook: Test that component statuses match the use-recommended-components denylist - #86799
Conversation
…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.
🤖 PR meta 🤖🎉 PropsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the 📦 Bundle sizeSize Change: 0 B Total Size: 8.69 MB
|
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.
| ( [ key, message ] ) => | ||
| [ | ||
| ...message.matchAll( | ||
| /\?path=\/docs\/([\w-]+--migration-guide)/g |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
| ( [ key, message ] ) => | ||
| [ | ||
| ...message.matchAll( | ||
| /\?path=\/docs\/([\w-]+--migration-guide)/g |
There was a problem hiding this comment.
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/, '' ), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
What?
Follow-up to #85764.
Adds a unit test that keeps the Storybook statuses of
@wordpress/componentsstories consistent with theuse-recommended-componentsdenylist, themanifesttag, 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 theNumberControlexception recorded in the test, trunk already passes.Why?
#85764 documents that a legacy component's Storybook status,
manifesttag, and denylist entry must agree, and that "anot-recommendedstatus and a denylist entry always change together". Nothing enforced this, and these sources had drifted on trunk forSpinner,SelectControl,CustomGradientPicker,NumberControl, the privateMenu, and themanifesttag ofBaseControl. 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 thestatus-indexer.tsit 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
componentname, without the__experimentalexport prefix. A story whosecomponentis imported from another package is not matched, so the@wordpress/uiSelectControlin theCustomSelectControlmigration examples does not count as a story of the legacySelectControl.Testing Instructions
npm run test:unit -- storybook/test/component-status.test.ts, and confirm each one is reported with the file to change:Spinnerentry from the denylist inpackages/eslint-plugin/rules/use-recommended-components.js.Tipdenylist message.FlexItemfrom thesubcomponentsof theFlexstory.tags: [ 'manifest' ]to theTooltipstory meta.TextControlstory status touse-with-caution.NumberControlstory status touse-with-caution.With all six changes applied, five of the six tests failed with these messages: