Jest Preset Default: Support self-referencing via exports - #80837
Merged
Conversation
manzoorwanijk
marked this pull request as draft
July 29, 2026 10:27
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If 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. |
manzoorwanijk
marked this pull request as ready for review
July 29, 2026 10:29
manzoorwanijk
force-pushed
the
fix/jest-preset-default-self-referencing
branch
from
July 29, 2026 10:29
0efb3d0 to
88a1bfc
Compare
manzoorwanijk
marked this pull request as draft
July 29, 2026 10:29
manzoorwanijk
marked this pull request as ready for review
July 29, 2026 10:30
|
Size Change: -82 B (0%) Total Size: 7.76 MB 📦 View Changed
|
`packages/jest-preset-default/test/index.js` requires the package by its own name, which only resolves while npm hoists every workspace into the root `node_modules`. Add an `exports` field so Node's self-referencing applies. The `./jest-preset` entry is required: `jest-config` resolves a bare preset name through the extensionless `<pkg>/jest-preset` subpath, and extensions are not appended to `exports` subpaths. With the package root resolving to `jest-preset.js`, `test/unit/jest.config.js` can pass the resolved path straight to `preset`.
manzoorwanijk
force-pushed
the
fix/jest-preset-default-self-referencing
branch
from
July 30, 2026 07:25
88a1bfc to
90fc37d
Compare
Mamaduka
approved these changes
Jul 30, 2026
Mamaduka
left a comment
Member
There was a problem hiding this comment.
Followed testing instructions and everything looks to be in order ✅
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Follow up to #80767.
Adds an
exportsfield to@wordpress/jest-preset-defaultso the package can be resolved by its own name from within itself, and simplifies howtest/unit/jest.config.jspoints at the preset.Why?
The test added in #80767 does
require( '@wordpress/jest-preset-default' )from inside the package. That only resolves because npm hoists every workspace into the rootnode_modules. Under an isolated/linked install strategy there is no root link, and the test fails withCannot find module '@wordpress/jest-preset-default'— see the failing run on #75814.Node's self-referencing is the supported way to import a package from within itself, and it requires an
exportsfield.How?
Adds a minimal
exportsmap exposing only the package root,jest-preset, andpackage.json.The
./jest-presetentry is load-bearing.jest-configresolves a preset given as a bare package name by looking up the extensionless<pkg>/jest-presetsubpath, and extensions are not appended toexportssubpaths. A map without that entry breaks every consumer usingpreset: "@wordpress/jest-preset-default", and./jest-preset.jsdoes not work as a substitute.Since the package root resolves to
jest-preset.js(main, as of #80767),test/unit/jest.config.jscan now pass the resolved path straight topresetinstead of deriving the containing directory from a subpath import.This narrows the published surface:
scripts/andindex.jsstill ship viafilesbut are no longer resolvable as deep imports. Nothing in the repo relies on them —jest-preset.jsreachesscripts/through relativerequire.resolve— but it is a breaking change for anyone deep-importing them, so it is noted in the changelog.Testing Instructions
npm run test:unit -- packages/jest-preset-default/test/index.jspasses.npm run test:unitpasses.@wordpress/jest-preset-defaultlinked and a config of{ preset: "@wordpress/jest-preset-default" }, Jest resolves the preset and runs. Use a fresh--cacheDirectory; a warm Jest cache will mask preset resolution changes.Use of AI Tools
Investigated and drafted with Claude Code (Opus). The
exportsshapes were verified empirically againstjest-resolveand Node, and end to end with a standalone consumer package. Please adjust this disclosure to match your own review.