Repository navigation
Jest: load components and block-editor as ESM, drop the pnpm patches - #54534
Conversation
Drops the pnpm patches for @wordpress/components 44 and @wordpress/block-editor 20: their rolldown CommonJS builds snapshot circular imports before the exports exist, which only jest consumed. A resolver takes the import entry for those two packages instead, and babel-jest's interop reads the bindings at use time. The transform allowlist moves to one helper so project configs extend it rather than replace it.
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Jetpack plugin: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. Boost plugin: No scheduled milestone found for this plugin. If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
Code Coverage SummaryThis PR did not change code coverage! That could be good or bad, depending on the situation. Everything covered before, and still is? Great! Nothing was covered before? Not so great. 🤷 |
config.base.js was shadowing jest-resolver.js, which swaps the browser condition for node on parsel-js; that is why parsel-js needed transforming. One resolver now does both, and the allowlist drops parsel-js.
Nikschavan
left a comment
There was a problem hiding this comment.
Thank you, the changes look good. I left one question inline about the Boost jest mapping, which still loads the CommonJS build of @wordpress/components.
Co-authored-by: Brad Jorsch <anomiex@users.noreply.github.com>
louwie17
left a comment
There was a problem hiding this comment.
Thanks @retrofox, nice to get rid of the patches! The Jest runs I did went well: the Premium Analytics DataViews, backup, charts, forms and Jetpack GUI suites all pass, and InnerBlocks and ToggleGroupControl render fine in both the forms (ESM) and Jetpack extensions setups.
The main thing to fix is the Boost mapping @Nikschavan mentioned, I left a reply on that thread. The other one is a quick lint fix in jest.config.gui.js, which is currently failing the ESLint check.
Co-reviewed and tested with Claude and Codex.
its components mapping skips the shared resolver
Proposed changes
Drop the two pnpm patches
#54512 added patches for
@wordpress/components44.0.0 and@wordpress/block-editor20.0.0.Their rolldown CommonJS builds evaluate a circular import before the exporting module has set its exports, so
BaseControlreachesuseBaseControlPropsasundefined("Invalid value used as weak map key") andInnerBlocksmemoizes an undefined block list ("Element type is invalid").Only Jest consumed those CommonJS builds. Webpack and
wp-buildtake the ESM builds, so nothing that ships was ever patched.This removes both patches from
pnpm-workspace.yaml,.pnpm-patches/, and the lockfile.Load them as ESM in Jest
jest-resolver.jsswapsrequireforimporton these two packages. The transform allowlist moves totransform-ignore.jsso they get transpiled, and charts extends it instead of keeping its own.Boost and Premium Analytics map
@wordpress/componentsto an absolute path, which skips the resolver, so their mappers take theimportentry throughresolveMapperTarget().It can all go once WordPress/gutenberg#86322 and WordPress/gutenberg#86323 ship.
Does this pull request change what data or activity we track or use?
No.
Testing instructions
Jest
Without the resolver entry this fails with 24 "Invalid value used as weak map key" errors.
cd projects/plugins/jetpack pnpm run test-extensions extensions/blocks/subscriptions