Skip to content

Test: Migrate Node unit tests to Vitest - #82211

Merged
ciampo merged 13 commits into
trunkfrom
codex/vitest-consolidated-04b-node-migration
Sep 1, 2026
Merged

ciampo merged 13 commits into
trunkfrom
codex/vitest-consolidated-04b-node-migration

Conversation

@ciampo

@ciampo ciampo commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

What?

Part of #80855.

Follows #82210.

Migrate deterministic Node unit tests from Jest to Vitest. This also adds the direct workspace dependencies and shared runner configuration used by the following jsdom migration.

jsdom tests and their Jest-only dependencies stay on Jest until the next PR in this stack.

Why?

Separating Node and jsdom tests keeps the migration reviewable and leaves DOM-specific setup out of this layer.

How?

Note

This is a large PR, but 99% of the changes are mechanical.
If reviewers feel strongly about the PR size being too large, I could split it into 3/4 PRs (or more).

Route the migrated Node tests through Vitest, convert Jest imports and mocks, preserve the remaining Jest test route and its package dependencies, and declare project matchers through Vitest's Matchers interface.

Follow-up cleanup

Testing Instructions

  1. Run npm run --workspace @wordpress/unit-tests test:unit:routing.
  2. Run npm run --workspace @wordpress/unit-tests test:unit:conventions.
  3. Run npm run test:unit:vitest -- --project=node.
  4. Run npm run test:unit -- --runInBand --shard=1/4 through --shard=4/4.
  5. Run npm run typecheck.

Testing Instructions for Keyboard

Not applicable; this PR does not change the UI.

Use of AI Tools

Codex helped split, verify, and document the changes. I reviewed the result.

@ciampo ciampo added the [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. label Aug 29, 2026
@ciampo ciampo self-assigned this Aug 29, 2026
@github-actions github-actions Bot added [Package] Element /packages/element [Package] Date /packages/date [Package] Data /packages/data [Package] Server Side Render /packages/server-side-render [Package] A11y /packages/a11y [Package] Autop /packages/autop [Tool] Babel preset /packages/babel-preset-default [Tool] Browserslist config /packages/browserslist-config [Package] DOM ready /packages/dom-ready [Package] Hooks /packages/hooks [Package] i18n /packages/i18n [Package] is-shallow-equal /packages/is-shallow-equal [Tool] npm-package-json-lint config /packages/npm-package-json-lint-config [Tool] WP Scripts /packages/scripts [Package] Url /packages/url [Package] Word count /packages/wordcount [Package] Deprecated packages/deprecated [Tool] Babel plugin makepot /packages/babel-plugin-makepot [Tool] Babel plugin import JSX pragma /packages/babel-plugin-import-jsx-pragma [Package] Blob /packages/blob [Package] Compose /packages/compose [Package] Core data /packages/core-data [Package] API fetch /packages/api-fetch [Package] Viewport /packages/viewport [Package] DOM /packages/dom [Package] Keycodes /packages/keycodes [Package] Plugins /packages/plugins [Package] Components /packages/components labels Aug 29, 2026
@github-actions

github-actions Bot commented Aug 29, 2026 •

Copy link
Copy Markdown

Size Change: 0 B

Total Size: 7.91 MB

compressed-size-action

@github-actions

github-actions Bot commented Aug 29, 2026 •

Copy link
Copy Markdown

Flaky tests detected in 0c78ff1.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/33405341092
📝 Reported tests:

two users concurrently move list items (RTC WebSocket) in /test/e2e/specs/editor/collaboration/collaboration-stress.spec.ts, passed after 1 failed attempt.
TimeoutError: locator.click: Timeout 10000ms exceeded.
Call log:
  - waiting for locator('role=toolbar[name="Block tools"i]').locator('role=button[name="Move up"i]')
    - locator resolved to <button id=":rq:" type="button" tabindex="-1" aria-label="Move up" data-toolbar-item="true" aria-describedby="block-editor-block-mover-button__description-0" class="components-button block-editor-block-mover-button is-up-button is-next-40px-default-size has-icon">…</button>
  - attempting click action
    - waiting for element to be visible, enabled and stable
    - element is visible, enabled and stable
    - scrolling into view if needed
  - element was detached from the DOM, retrying

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/collaboration/collaboration-stress.spec.ts:623:7
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/collaboration/collaboration-stress.spec.ts:602:3

@github-actions

github-actions Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: manzoorwanijk <manzoorwanijk@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@manzoorwanijk manzoorwanijk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the size of the PR, I relied fully on the AI review for this.

Comment thread tools/eslint/config.mjs
Comment thread packages/upload-media/src/store/test/actions.ts Outdated
Comment thread packages/block-editor/src/store/test/reducer.js Outdated
Comment thread test/unit/scripts/test/babel-transformer.js
Comment thread packages/upload-media/src/store/test/private-actions.js Outdated
Comment thread packages/env/lib/test/resolve-available-ports.js Outdated
Comment thread tools/release/commands/test/changelog.js Outdated
Comment thread packages/jest-console/src/index.ts

Copilot AI 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.

Pull request overview

Migrates deterministic Node unit tests from Jest to Vitest while retaining Jest for jsdom tests.

Changes:

  • Adds explicit Vitest imports, mocks, matcher types, and snapshots.
  • Routes Node tests through shared Vitest configuration and CI.
  • Adds direct Vitest workspace dependencies while preserving jsdom’s Jest dependencies.

Reviewed changes

Copilot reviewed 298 out of 639 changed files in this pull request and generated no comments.

Show a summary per file
File Description
Node test files and snapshots Migrates test APIs and expected snapshots to Vitest.
Workspace manifests and lockfile Declares consistent direct Vitest dependencies.
test/unit/* Configures routing, setup, conventions, and matcher types.
test/integration/* Supports both transitional Jest and Vitest timers.
tools/eslint/config.mjs Applies test linting to migrated Node tests.
packages/jest-console/* Preserves console spies and supports Vitest-driven tests.
.github/workflows/*, bin/unit-test-date.sh Runs migrated tests through Vitest in CI.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions

github-actions Bot commented Sep 1, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

📦 Bundle size

Size Change: 0 B

Total Size: 7.91 MB

96d135f Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric b426d73 trunk % Change
timeToFirstByte 63.7 ms +8.56% -11.07% 64.6 ms +3.87% -12.62% -1.39%
largestContentfulPaint 98 ms +10.2% -10.2% 96 ms +6.25% -4.17% 2.08%
lcpMinusTtfb 33.3 ms +24.62% -6.16% 31.45 ms +12.56% -5.72% 5.88%
wpBeforeTemplate 33.22 ms +4.52% -17.94% 33.27 ms +2.68% -19.3% -0.15%
wpTemplate 25.82 ms +4.92% -1.55% 26.06 ms +6.18% -1.84% -0.92%
wpTotal 59.14 ms +7.1% -10.99% 59.65 ms +4.06% -11.77% -0.85%
wpMemoryUsage 7.54 MB +0% -0% 7.50 MB +0% -0% 0.46%
wpDbQueries 17 +0% -0% 17 +0% -0% 0%

front-end-classic-theme

Metric b426d73 trunk % Change
timeToFirstByte 50.55 ms +11.47% -9.2% 51.5 ms +7.96% -8.54% -1.84%
largestContentfulPaint 98 ms +4.08% -6.12% 100 ms +0% -8% -2%
lcpMinusTtfb 45.75 ms +1.75% -3.39% 45.15 ms +4.43% -1.66% 1.33%
wpBeforeTemplate 25.77 ms +23.55% -8.07% 27.33 ms +14.23% -12.04% -5.71%
wpTemplate 19.77 ms +4.96% -2.88% 20.08 ms +3.44% -1.99% -1.54%
wpTotal 47.14 ms +10.78% -9.06% 47.93 ms +7.89% -8.49% -1.65%
wpMemoryUsage 6.16 MB +0% -0% 6.12 MB +0% -0% 0.58%
wpDbQueries 14 +0% -0% 14 +0% -0% 0%

media-processing

Metric b426d73 trunk % Change
mediaProcessingJpeg 410.77 ms +0.08% -0.42% 410 ms +0.56% -0.7% 0.19%
mediaProcessingAvif 6385.85 ms +0.76% -0.14% 6385.81 ms +0.21% -0.1% 0%
mediaProcessingJpegToAvif 4569.78 ms +0.26% -0.13% 4558.41 ms +0.26% -0.03% 0.25%

media-upload

Metric b426d73 trunk % Change
jpegUploadProcessing 1439.78 ms +34.65% -1.27% 1431.65 ms +1% -1.3% 0.57%
pngUploadProcessing 202.86 ms +2.26% -3.25% 204.36 ms +5.27% -3.12% -0.73%
largeJpegUploadProcessing 1405.01 ms +1.42% -0.6% 1413.09 ms +1.26% -1.02% -0.57%
multipleImageUploadProcessing 1547.14 ms +0.78% -1.13% 1551.02 ms +0.71% -1.58% -0.25%

post-editor

Metric b426d73 trunk % Change
serverResponse 519.55 ms +4.74% -5.18% 558.37 ms +2.36% -9.15% -6.95%
firstPaint 239.65 ms +17.61% -9.81% 228.42 ms +5.24% -7.21% 4.92%
domContentLoaded 1281.5 ms +0.66% -0.97% 1285.52 ms +0.28% -0.24% -0.31%
loaded 1282.8 ms +0.66% -0.98% 1286.79 ms +0.27% -0.26% -0.31%
firstContentfulPaint 433.46 ms +2.32% -2.42% 432.46 ms +1.33% -2.04% 0.23%
firstBlock 3500.71 ms +1.65% -1.28% 3550.88 ms +0.2% -0.49% -1.41%
type 19.36 ms +7.39% -20.2% 19.21 ms +14.63% -25.46% 0.78%
typeWithoutInspector 18.91 ms +14.17% -15.02% 18.91 ms +8.51% -15.86% 0%
typeWithTopToolbar 23.41 ms +11.19% -12.09% 23.4 ms +11.79% -18.03% 0.04%
typeContainer 8.71 ms +11.48% -7.35% 8.97 ms +9.03% -5.35% -2.9%
focus 76.37 ms +22.98% -7.02% 76.89 ms +18.47% -5.29% -0.68%
firstFocus 167.5 ms +0% -0% 160.59 ms +0% -0% 4.3%
selectAll 590.03 ms +1.58% -0.12% 587.98 ms +2.52% -1.04% 0.35%
listViewOpen 64.95 ms +19.45% -8.38% 67.1 ms +8.29% -8.88% -3.2%
inserterOpen 21.4 ms +13.64% -12.29% 20.56 ms +15.42% -9.58% 4.09%
inserterHover 3.44 ms +11.05% -9.01% 3.46 ms +11.85% -14.16% -0.58%
inserterSearch 7.21 ms +14.56% -4.85% 7.6 ms +17.11% -14.61% -5.13%
loadPatterns 613.05 ms +5.84% -5% 636.04 ms +1.66% -1.96% -3.61%
wpTotal 508.58 ms +5.04% -5.06% 548.27 ms +2.34% -9.27% -7.24%
wpMemoryUsage 13.13 MB +0% -0% 13.10 MB +0% -0% 0.22%
wpDbQueries 54 +0% -1.85% 54 +0% -1.85% 0%

site-editor

Metric b426d73 trunk % Change
serverResponse 298.84 ms +10.74% -1.22% 298.96 ms +6.45% -4.24% -0.04%
firstPaint 197.97 ms +36.91% -15.39% 204.1 ms +46.06% -13.56% -3%
domContentLoaded 1004.7 ms +4.02% -0.94% 956.52 ms +3.32% -1.99% 5.04%
loaded 1005.76 ms +3.99% -0.94% 957.35 ms +3.31% -1.99% 5.06%
firstContentfulPaint 312.37 ms +3.19% -1.34% 316.49 ms +3.45% -4.19% -1.3%
firstBlock 3119.07 ms +1.41% -0.13% 2946.52 ms +0.87% -3.63% 5.86%
type 19.18 ms +13.56% -22.42% 15.93 ms +4.9% -17.26% 20.4%
navigate 80.52 ms +12.58% -11.14% 89.28 ms +5.81% -17.06% -9.81%
loadPatterns 1062.9 ms +7.56% -1.99% 1057.07 ms +22.75% -9.69% 0.55%
loadPages 1055.75 ms +5.22% -0.94% 1122.71 ms +4.71% -7.65% -5.96%
wpTotal 291.64 ms +10.9% -1.28% 291.91 ms +6.16% -4.39% -0.09%
wpMemoryUsage 12.02 MB +0% -0% 11.99 MB +0% -0% 0.3%
wpDbQueries 44 +0% -2.27% 44 +0% -2.27% 0%

96d135f Run

Copilot AI 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.

Pull request overview

Copilot reviewed 298 out of 644 changed files in this pull request and generated 1 comment.

Comment thread packages/wp-build/lib/test/browserslist.js Outdated

Copilot AI 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.

Pull request overview

Copilot reviewed 298 out of 644 changed files in this pull request and generated 1 comment.

@@ -1,17 +1,36 @@
import { spyOn } from 'jest-mock';

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aduth looks like copilot is picking up repo skills while reviewing 🎉

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an isolated real-Jest subprocess test for jest.restoreAllMocks() in 7f81705, then made it load the source entry through the repository transformer in c192bc3

Copilot AI 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.

Pull request overview

Copilot reviewed 298 out of 646 changed files in this pull request and generated 2 comments.

Copilot AI 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.

Pull request overview

Copilot reviewed 298 out of 646 changed files in this pull request and generated 1 comment.

Comment thread packages/jest-console/src/test/index.test.ts Outdated

@manzoorwanijk manzoorwanijk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me now. Thank you for this effort.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] A11y /packages/a11y [Package] Abilities /packages/abilities [Package] Admin UI /packages/admin-ui [Package] API fetch /packages/api-fetch [Package] Autop /packages/autop [Package] Blob /packages/blob [Package] Block editor /packages/block-editor [Package] Block library /packages/block-library [Package] Blocks /packages/blocks [Package] Components /packages/components [Package] Compose /packages/compose [Package] Core commands /packages/core-commands [Package] Core data /packages/core-data [Package] Data Controls /packages/data-controls [Package] Data /packages/data [Package] DataViews /packages/dataviews [Package] Date /packages/date [Package] Deprecated packages/deprecated [Package] Design System MCP /packages/design-system-mcp [Package] DOM ready /packages/dom-ready [Package] DOM /packages/dom [Package] Edit Post /packages/edit-post [Package] Edit Site /packages/edit-site [Package] Edit Widgets /packages/edit-widgets [Package] Editor /packages/editor [Package] Element /packages/element [Package] Escape HTML /packages/escape-html [Package] Fields /packages/fields [Package] Format library /packages/format-library [Package] Grid /packages/grid [Package] Hooks /packages/hooks [Package] i18n /packages/i18n [Package] Icons /packages/icons [Package] Interactivity Router /packages/interactivity-router [Package] Interactivity /packages/interactivity [Package] Interface /packages/interface [Package] is-shallow-equal /packages/is-shallow-equal [Package] Keycodes /packages/keycodes [Package] Media Utils /packages/media-utils [Package] Notices /packages/notices [Package] Plugins /packages/plugins [Package] Preferences /packages/preferences [Package] Priority Queue /packages/priority-queue [Package] Private APIs /packages/private-apis [Package] Project management automation /packages/project-management-automation [Package] Redux Routine /packages/redux-routine [Package] Rich text /packages/rich-text [Package] Server Side Render /packages/server-side-render [Package] Style Engine /packages/style-engine [Package] Sync /packages/sync [Package] Theme /packages/theme [Package] Token List /packages/token-list [Package] UI /packages/ui [Package] Url /packages/url [Package] Viewport /packages/viewport [Package] Views /packages/views [Package] Warning /packages/warning [Package] Widget Dashboard /packages/widget-dashboard [Package] Widget primitives /packages/widget-primitives [Package] Word count /packages/wordcount [Package] wp-build /packages/wp-build [Tool] Babel plugin import JSX pragma /packages/babel-plugin-import-jsx-pragma [Tool] Babel plugin makepot /packages/babel-plugin-makepot [Tool] Babel preset /packages/babel-preset-default [Tool] Browserslist config /packages/browserslist-config [Tool] Dependency Extraction Webpack Plugin /packages/dependency-extraction-webpack-plugin [Tool] Docgen /packages/docgen [Tool] Env /packages/env [Tool] ESLint plugin /packages/eslint-plugin [Tool] Jest console /packages/jest-console [Tool] Jest preset /packages/jest-preset-default [Tool] npm-package-json-lint config /packages/npm-package-json-lint-config [Tool] Prettier config /packages/prettier-config [Tool] Readable JS Assets Webpack Plugin /packages/readable-js-assets-webpack-plugin [Tool] stylelint config /packages/stylelint-config [Tool] WP Scripts /packages/scripts [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants