refactor: migrate tests/unit to npm workspace @wordpress/unit-tests#77063
Conversation
Read IS_GUTENBERG_PLUGIN directly from root package.json instead of relying on npm_package_config_* env vars, which are unreliable in npm workspaces. Set globals early in Jest config to ensure correct module-level guards.
|
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
left a comment
There was a problem hiding this comment.
Thank you for working on this. Let us clean things up a bit.
Claude Code reviewMigration changes look correct
Unused unit-test deps still in root devDependenciesThese exist only in root
Safe to drop from root. Ones to leave in root
Loose ends in this branch
|
There was a problem hiding this comment.
Pull request overview
This PR migrates the existing test/unit Jest setup into a dedicated npm workspace package (@wordpress/unit-tests) so unit-test tooling and dependencies can be isolated from the monorepo root, in line with the broader workspace conversion effort.
Changes:
- Added
test/unit/package.jsonto define the new private workspace@wordpress/unit-testsand its test scripts/dependencies. - Updated
test/unit/jest.config.jsto resolve repo-root paths correctly when running from the workspace context. - Updated root
package.jsonscripts and workspaces to run unit tests via the new workspace and adjusted related dependency placements/lockfile.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
test/unit/package.json |
Introduces the @wordpress/unit-tests workspace package definition and unit test scripts/dependencies. |
test/unit/jest.config.js |
Adjusts root path handling for workspace execution (repo-root resolution and globbing). |
package.json |
Routes unit-test scripts through the @wordpress/unit-tests workspace and updates workspaces/deps accordingly. |
package-lock.json |
Reflects workspace addition and dependency graph changes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
manzoorwanijk
left a comment
There was a problem hiding this comment.
Thank you for working on this.
Next, we have test/native and test/performance, which would help us further clean up the root package.json.
|
It looks like some of the unit tests are failing on trunk after this got merged https://github.com/WordPress/gutenberg/actions/runs/24705229142/job/72256949732. |
Looking into it. It's strange that PR is green but trunk fails 😄 |
|
OK, they are failing on Node 24, which we don't run for PRs. I think it's better to run that for PRs as well. CC: @aduth |
|
Yeah, happens from time to time. We run a limited unit test matrix on PRs to save some time. |
|
#77512 fixes it. I verified it by temporarily running the CI checks on v24 on that PR. |
Co-authored-by: USERSATOSHI <tusharbharti@git.wordpress.org> Co-authored-by: manzoorwanijk <manzoorwanijk@git.wordpress.org>
|
Note here: because # Ignores --testPathPattern, runs all tests:
npm run test:unit -- --testPathPattern='test/crdt.ts'Instead, you either need to pass npm run test:unit -- -- --testPathPattern='test/crdt.ts'
# or
npm run --workspace @wordpress/unit-tests test:unit -- --testPathPattern='test/crdt.ts'It seems like this was already noticed in this PR and a similar workaround was added to the |
|
I think a similar fix needs to be applied here - #77083. That said, we need to test this workflow migration PRs more thoroughly. |
|
Thank you for the catch. I have created #77541 to fix it. |
Follow-up to #77063. After the test/unit workspace conversion, flags passed via `npm run test:unit -- ...` were swallowed by the nested `npm run --workspace` call. For example: npm run test:unit -- --testPathPattern='test/crdt.ts' …ran the entire suite instead of filtering. Append a trailing `--` to each workspace-delegating script so npm forwards all subsequent user args (both flags and positionals) to the workspace command untouched. Also drop the `-- --` workaround in `fixtures:generate` since a single `--` now works end-to-end.
What?
Part of #75041
Why?
The issue provides more context, but in short, this PR ensures the workspace package does not rely on root dependencies once dependency isolation is enforced.
How?
This PR converts tests/unit into a new workspace
@wordpress/unit-testswhile still relating the functionality.Testing Instructions
Testing Instructions for Keyboard
run all
npm run unit:*scripts.