Skip to content

Fix Blocks Jest private API singleton resolution#65341

Merged
gigitux merged 3 commits into
trunkfrom
fix/blocks-jest-patterns-singleton
May 28, 2026
Merged

Fix Blocks Jest private API singleton resolution#65341
gigitux merged 3 commits into
trunkfrom
fix/blocks-jest-patterns-singleton

Conversation

@gigitux

@gigitux gigitux commented May 27, 2026

Copy link
Copy Markdown
Contributor

Submission Review Guidelines:

Changes proposed in this Pull Request:

While working on #65308, I noticed a couple of places where the Blocks unit test setup could be made more reliable.

The current approach relies on importing from an internal dependency path. If that file is moved or removed upstream, unit tests can fail unexpectedly, as happened in #65308.

unlock import

Instead of importing unlock from an internal package path, this PR defines a small test utility that opts into the private API explicitly and exports the unlock function from there.

@wordpress/patterns mock

The test setup previously mocked @wordpress/patterns because it was not installed as a direct dependency. This PR adds the package properly, so the mock is no longer needed.

How to test the changes in this Pull Request:

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

  1. Ensure that CI jobs don't fail.

Testing that has already taken place:

Milestone

Note: Check the box above to have the milestone automatically assigned when merged.
Alternatively (e.g. for point releases), manually assign the appropriate milestone.

Changelog entry

  • Automatically create a changelog entry from the details below.
  • This Pull Request does not require a changelog entry. (Comment required below)
Changelog Entry Details

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Changelog Entry Comment

Comment

Improve block library unit test env.

@github-actions github-actions Bot added focus: monorepo infrastructure Issues and PRs related to monorepo tooling. plugin: woocommerce Issues related to the WooCommerce Core plugin. labels May 27, 2026
@gigitux gigitux self-assigned this May 27, 2026
@gigitux gigitux marked this pull request as ready for review May 27, 2026 13:09
@gigitux gigitux requested a review from a team as a code owner May 27, 2026 13:09
@gigitux gigitux requested review from Konamiman and ObliviousHarmony and removed request for a team May 27, 2026 13:09
@woocommercebot woocommercebot requested review from a team and Aljullu and removed request for a team May 27, 2026 13:10
@github-actions

Copy link
Copy Markdown
Contributor

Testing Guidelines

Hi @Konamiman @Aljullu @ObliviousHarmony ,

Apart from reviewing the code changes, please make sure to review the testing instructions (Guide) and verify that relevant tests (E2E, Unit, Integration, etc.) have been added or updated as needed.

Reminder: PR reviewers are required to document testing performed. This includes:

  • 🖼️ Screenshots or screen recordings.
  • 📝 List of functionality tested / steps followed.
  • 🌐 Site details (environment attributes such as hosting type, plugins, theme, store size, store age, and relevant settings).
  • 🔍 Any analysis performed, such as assessing potential impacts on environment attributes and other plugins, conducting performance profiling, or using LLM/AI-based analysis.

⚠️ Within the testing details you provide, please ensure that no sensitive information (such as API keys, passwords, user data, etc.) is included in this public issue.

@coderabbitai

coderabbitai Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 2294f9d7-8b75-4059-9545-cebfba415580

📥 Commits

Reviewing files that changed from the base of the PR and between db4f863 and 278790e.

📒 Files selected for processing (1)
  • plugins/woocommerce/changelog/fix-blocks-jest-patterns-singleton
✅ Files skipped from review due to trivial changes (1)
  • plugins/woocommerce/changelog/fix-blocks-jest-patterns-singleton

📝 Walkthrough

Walkthrough

This PR adds @wordpress/patterns to the workspace and package devDependencies, creates a test utility to re-export the private unlock API, adjusts TypeScript and Jest configs to include test utilities and treat patterns as a singleton, and updates integration test helpers and mocks to use the new utilities.

Changes

WordPress Patterns Test Infrastructure Integration

Layer / File(s) Summary
Workspace and package dependencies
pnpm-workspace.yaml, plugins/woocommerce/client/blocks/package.json, plugins/woocommerce/changelog/fix-blocks-jest-patterns-singleton
@wordpress/patterns (v2.19.6) is added to the workspace catalog and as a devDependency; changelog entry added.
Test utility for WordPress private APIs
plugins/woocommerce/client/blocks/tests/utils/lock-unlock.ts
New utility that imports unlock from WordPress private APIs (opt-in) and re-exports it for tests.
TypeScript and Jest configuration
plugins/woocommerce/client/blocks/tsconfig.base.json, plugins/woocommerce/client/blocks/tsconfig.json, plugins/woocommerce/client/blocks/tests/js/jest.config.js
Adds @woocommerce/blocks-test-utils path aliases, includes tests/utils in tsconfig, and registers @wordpress/patterns as a Jest singleton module.
Integration test updates and mock refactoring
plugins/woocommerce/client/blocks/tests/integration/helpers/integration-test-editor.tsx, plugins/woocommerce/client/blocks/tests/js/config/global-mocks.js
Integration test helper now returns Promise<RenderResult>, imports unlock from the new local utility and waitForStoreResolvers, and global mocks now stub is-editor to return false.

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: fixing Jest private API singleton resolution for the Blocks module by properly configuring @wordpress/patterns as a singleton dependency.
Description check ✅ Passed The description clearly explains the changes: replacing an unsafe unlock import with a test utility and adding @wordpress/patterns as a proper dependency instead of mocking it.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/blocks-jest-patterns-singleton

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor

Test using WordPress Playground

The changes in this pull request can be previewed and tested using a WordPress Playground instance.
WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Test this pull request with WordPress Playground.

Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a commit that changes plugin code.

@github-actions

github-actions Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor

Size Change: -3.39 kB (-0.06%)

Total Size: 5.67 MB

Filename Size Change
./plugins/woocommerce/client/admin/build/wp-admin-scripts/settings-embed.js 375 kB -3.39 kB (-0.9%)

compressed-size-action

@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor

Actionable comments posted: 0

@Aljullu Aljullu 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.

Code changes make sense. Tests are also green, so LGTM.

@gigitux gigitux enabled auto-merge (squash) May 28, 2026 14:09
@gigitux gigitux merged commit eda35c5 into trunk May 28, 2026
290 of 291 checks passed
@gigitux gigitux deleted the fix/blocks-jest-patterns-singleton branch May 28, 2026 14:25
@github-actions github-actions Bot added this to the 10.9.0 milestone May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

focus: monorepo infrastructure Issues and PRs related to monorepo tooling. plugin: woocommerce Issues related to the WooCommerce Core plugin.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants