Skip to content

Migrate Block Editor Package Tests to Vitest - #80981

Draft
ciampo wants to merge 1 commit into
codex/vitest-77-block-editor-jsxfrom
codex/vitest-78-block-editor
Draft

Migrate Block Editor Package Tests to Vitest#80981
ciampo wants to merge 1 commit into
codex/vitest-77-block-editor-jsxfrom
codex/vitest-78-block-editor

Conversation

@ciampo

@ciampo ciampo commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

What?

Follow up to #80855.

TL;DR: This migrates all 133 @wordpress/block-editor unit-test files from Jest to Vitest. The necessary change classes are explicit Vitest imports, ESM-aware module mocks and module lifecycle, public-package partial mocks in place of deep source mocks, modern fake timers, and Vitest snapshot metadata.

Why?

This is the next bounded package slice in the repository-wide Jest-to-Vitest migration. Keeping the package migration in one independently revertible PR preserves the exactly-one-runner invariant while making its module-mocking and snapshot differences reviewable in context.

How?

  • Routes packages/block-editor to the Vitest jsdom project and adds the package-local Vitest development dependency.
  • Converts Jest globals and mocks to explicit Vitest imports and ESM-compatible vi.mock( import( … ) ) factories.
  • Replaces deep @wordpress/data and @wordpress/blocks source mocks with public-package partial mocks.
  • Reworks the few module-reset/isolation cases around dynamic ESM imports.
  • Uses modern Vitest fake timers for the inserter media hooks.
  • Updates 17 snapshots only for the Vitest header and hierarchical test-name keys; an entry-by-entry audit found zero snapshot-body differences.
  • Keeps Testing Library unchanged. The five existing @ariakit/test consumers remain on jsdom intentionally and will move to Vitest Browser Mode in a separate browser-focused PR.

Testing Instructions

  1. Run the focused package suite:
    npm run test:unit:vitest -- --project jsdom packages/block-editor
  2. Validate routing and conventions:
    npm run --workspace @wordpress/unit-tests test:unit:routing
    npm run --workspace @wordpress/unit-tests test:unit:conventions
  3. Run package and lockfile checks:
    npm run lint:pkg-json -- packages/block-editor/package.json
    npm run lint:lockfile
  4. Run the complete Vitest suite:
    npm run test:unit:vitest

Verified locally:

  • Focused Block Editor suite: 133 files, 2,132 tests, 17 snapshots.
  • Complete suite: 998 passed and 2 skipped files; 34,719 passed and 8 skipped tests, including the Chromium browser project.
  • Residual Jest partition: 3 suites, 33 tests, 0 snapshots.
  • Routing: 996 baseline tests owned exactly once; 1,000 Vitest tests and 3 Jest tests, with 164 tracked renames and 7 additions.
  • Convention graph: 1,000 Vitest tests, 1,016 ESM graph files, 102 workspace dependencies, and 402 TypeScript tests.
  • All changed test files passed strict JavaScript lint; package metadata and lockfile checks passed.

Testing Instructions for Keyboard

Not applicable; this changes test infrastructure only.

Screenshots or screencast

Not applicable.

Use of AI Tools

Codex was used to inventory the package tests, apply the mechanical runner conversion, investigate Vitest-specific module differences, and run the verification commands. The resulting diff and snapshot entries were reviewed directly.

@github-actions

Copy link
Copy Markdown

Size Change: 0 B

Total Size: 7.76 MB

compressed-size-action

@github-actions

Copy link
Copy Markdown

Flaky tests detected in 8d974eb.
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/30556666583
📝 Reported issues:

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

Labels

[Package] Block editor /packages/block-editor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant