Skip to content

Test: Classify and enforce unit test environments by filename - #80991

Merged
ciampo merged 6 commits into
trunkfrom
codex/vitest-consolidated-03-projects-browser
Aug 28, 2026
Merged

ciampo merged 6 commits into
trunkfrom
codex/vitest-consolidated-03-projects-browser

Conversation

@ciampo

@ciampo ciampo commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Part of #80855.

What?

Classify every unit test by the environment in its filename, and make that filename select the environment:

  • *.test.* runs in Node.js.
  • *.jsdom.test.* runs in jsdom.
  • *.browser.test.* runs in a real browser.

This PR does not move tests from Jest to Vitest. The migration manifest still decides which runner owns a test; the filename now decides which environment that runner uses.

Why?

Vitest uses Node.js by default, while Jest previously ran every test in jsdom. Explicit filenames prevent tests from silently running in the wrong environment during the migration.

The convention is also enforced for future changes. The routing check verifies that every discovered test belongs to exactly one runner and the correct filename-selected project. Per-file @jest-environment and @vitest-environment overrides are rejected.

How?

  • Rename tests that need the DOM to *.jsdom.test.*, while keeping Node-compatible tests unsuffixed and existing Browser Mode tests as *.browser.test.*.
  • Split Jest into Node.js and jsdom projects selected by filename.
  • Make the routing check compare each Jest and Vitest project's actual inventory with the filename-derived inventory.
  • Rename matching snapshots and update documentation and exact-path tooling references.

Files that mix DOM-only and browser-dependent assertions are intentionally not split here. A later Browser Mode PR will split them after Browser Mode is enabled for those tests, so the new *.browser.test.* files run in Chromium instead of Jest's jsdom environment.

Testing Instructions

  • Confirm the unit tests, npm run test:unit:routing, and npm run test:unit:conventions pass. The routing check must report every discovered test in exactly one runner and the correct filename-selected project; the four Jest shards must cover the complete inventory once.
  • Review the classifications: use Browser Mode where real browser behavior is necessary, jsdom for deterministic DOM-only behavior, and Node.js otherwise. Confirm that matching snapshots and exact-path tooling references moved with each renamed test.

Testing Instructions for Keyboard

Not applicable. This PR changes test infrastructure and filenames, with no user-facing or keyboard behavior changes.

Use of AI Tools

Codex assisted with the environment audit, mechanical renames, enforcement, reference updates, verification, and adversarial self-review. The author reviewed the resulting changes and test output.

@github-actions github-actions Bot added the [Package] Components /packages/components label Jul 30, 2026
@github-actions

github-actions Bot commented Jul 30, 2026 •

Copy link
Copy Markdown

Size Change: 0 B

Total Size: 7.92 MB

compressed-size-action

@ciampo
ciampo force-pushed the codex/vitest-consolidated-02-jsx-extensions branch from 6c16f00 to 57a0bf5 Compare July 30, 2026 23:46
@ciampo
ciampo force-pushed the codex/vitest-consolidated-03-projects-browser branch from d81f25e to f9682b1 Compare July 30, 2026 23:46
@github-actions

github-actions Bot commented Jul 31, 2026 •

Copy link
Copy Markdown

Flaky tests detected in 29de986.
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/33212055973
📝 Reported tests:

Should save the changes in /test/e2e/specs/editor/plugins/wp-editor-meta-box.spec.js, passed after 2 failed attempts.
TimeoutError: page.waitForFunction: Timeout 10000ms exceeded.
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/plugins/wp-editor-meta-box.spec.js:34:14
TimeoutError: locator.click: Timeout 10000ms exceeded.
Call log:
  - waiting for locator('role=button[name="Visual"i]')

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/plugins/wp-editor-meta-box.spec.js:33:55
awareness cursor tracks all positions through a bolded word without sticking at formatting boundaries in /test/e2e/specs/editor/collaboration/collaboration-awareness-cursor-position.spec.ts, passed after 1 failed attempt.
Error: Awareness cursor should be visible at offset 0

expect(received).not.toBe(expected) // Object.is equality

Expected: not -1
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/collaboration/collaboration-awareness-cursor-position.spec.ts:124:10
shows pattern summary fields in the post editor in /test/e2e/specs/editor/various/post-summary-dataform/post-summary.spec.js, passed after 1 failed attempt.
Error: apiRequestContext.fetch: socket hang up
Call log:
  - → GET http://localhost:8889/wp-json/wp/v2/blocks?per_page=100&status=publish%2Cfuture%2Cdraft%2Cpending%2Cprivate%2Ctrash
    - user-agent: Playwright/1.62.1 (x64; ubuntu 24.04) node/20.20 CI/1
    - accept: */*
    - accept-encoding: gzip,deflate,br
    - X-WP-Nonce: cd764cce96
    - cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_23778236db82f19306f247e20a353a99=admin%7C1788125105%7CoaVhnmzWAl3JAmglT7TAr1R5PA7AodiWkg6vp4WbX5N%7C57fe1f9a3845ef25d0d5e8284a6cfe12c72c902c5a268de962dbc43bfb2bada2; wp-settings-time-1=1787952689

    at RequestUtils.rest (/home/runner/work/gutenberg/gutenberg/packages/e2e-test-utils-playwright/src/request-utils/rest.ts:112:39)
    at RequestUtils.deleteAllBlocks (/home/runner/work/gutenberg/gutenberg/packages/e2e-test-utils-playwright/src/request-utils/blocks.ts:23:28)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/post-summary-dataform/post-summary.spec.js:25:23

@ciampo
ciampo force-pushed the codex/vitest-consolidated-02-jsx-extensions branch from 57a0bf5 to 83736a6 Compare July 31, 2026 00:38
@ciampo
ciampo force-pushed the codex/vitest-consolidated-03-projects-browser branch from f9682b1 to 45dbb01 Compare July 31, 2026 00:38
@ciampo
ciampo force-pushed the codex/vitest-consolidated-02-jsx-extensions branch from 83736a6 to 2216a5f Compare July 31, 2026 01:12
@ciampo
ciampo force-pushed the codex/vitest-consolidated-03-projects-browser branch 2 times, most recently from 3a61746 to 9878da6 Compare July 31, 2026 02:57
@ciampo
ciampo force-pushed the codex/vitest-consolidated-02-jsx-extensions branch 2 times, most recently from 6f0d9f5 to 59d27ae Compare July 31, 2026 19:21
@ciampo
ciampo force-pushed the codex/vitest-consolidated-03-projects-browser branch from 9878da6 to d542198 Compare July 31, 2026 19:21
@ciampo
ciampo force-pushed the codex/vitest-consolidated-02-jsx-extensions branch from 59d27ae to 842e177 Compare July 31, 2026 20:00
@ciampo
ciampo force-pushed the codex/vitest-consolidated-03-projects-browser branch from 5d74e5a to aa8d0ba Compare July 31, 2026 20:00
@ciampo
ciampo force-pushed the codex/vitest-consolidated-02-jsx-extensions branch from 842e177 to 5fadb3d Compare August 11, 2026 15:07
@ciampo
ciampo force-pushed the codex/vitest-consolidated-03-projects-browser branch from aa8d0ba to 9097318 Compare August 11, 2026 15:26
@github-actions github-actions Bot added [Package] Element /packages/element [Package] Data /packages/data [Package] A11y /packages/a11y [Package] DOM ready /packages/dom-ready [Package] Hooks /packages/hooks [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 labels Aug 11, 2026
@ciampo
ciampo force-pushed the codex/vitest-consolidated-03-projects-browser branch from bd5eee3 to 49cabc0 Compare August 12, 2026 11:49
@ciampo
ciampo force-pushed the codex/vitest-consolidated-02-jsx-extensions branch from b17afc1 to 46b3c70 Compare August 12, 2026 13:32
@ciampo
ciampo force-pushed the codex/vitest-consolidated-03-projects-browser branch from 49cabc0 to c103b50 Compare August 12, 2026 13:33
@ciampo
ciampo force-pushed the codex/vitest-consolidated-02-jsx-extensions branch from 46b3c70 to 7667c4b Compare August 12, 2026 17:57
@ciampo
ciampo force-pushed the codex/vitest-consolidated-03-projects-browser branch from c103b50 to 2cf71e5 Compare August 12, 2026 17:57
@ciampo
ciampo force-pushed the codex/vitest-consolidated-02-jsx-extensions branch 5 times, most recently from 0b00df6 to 7ce5a3f Compare August 27, 2026 14:46
Base automatically changed from codex/vitest-consolidated-02-jsx-extensions to trunk August 27, 2026 15:25
@ciampo
ciampo force-pushed the codex/vitest-consolidated-03-projects-browser branch from 2cf71e5 to c493a8c Compare August 27, 2026 16:35
@github-actions github-actions Bot added [Package] Admin UI /packages/admin-ui [Package] Grid /packages/grid [Package] Widget primitives /packages/widget-primitives [Package] Widget Dashboard /packages/widget-dashboard [Package] Views /packages/views labels Aug 27, 2026
@ciampo
ciampo force-pushed the codex/vitest-consolidated-03-projects-browser branch from c493a8c to 8d127a2 Compare August 27, 2026 18:35
@ciampo ciampo changed the title Test: Classify unit test environments by filename Test: Classify and enforce unit test environments by filename Aug 27, 2026
@ciampo
ciampo marked this pull request as ready for review August 27, 2026 20:24
@github-actions

github-actions Bot commented Aug 27, 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: mirka <0mirka00@git.wordpress.org>

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

Comment thread docs/contributors/code/testing-overview.md Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] A11y /packages/a11y [Package] Admin UI /packages/admin-ui [Package] API fetch /packages/api-fetch [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 data /packages/core-data [Package] Data /packages/data [Package] DataViews /packages/dataviews [Package] DOM ready /packages/dom-ready [Package] DOM /packages/dom [Package] Edit Post /packages/edit-post [Package] Edit Widgets /packages/edit-widgets [Package] Editor /packages/editor [Package] Element /packages/element [Package] Fields /packages/fields [Package] Format library /packages/format-library [Package] Grid /packages/grid [Package] Hooks /packages/hooks [Package] Icons /packages/icons [Package] Interactivity Router /packages/interactivity-router [Package] Interactivity /packages/interactivity [Package] Interface /packages/interface [Package] Keycodes /packages/keycodes [Package] Media Utils /packages/media-utils [Package] Notices /packages/notices [Package] Plugins /packages/plugins [Package] Rich text /packages/rich-text [Package] Sync /packages/sync [Package] Theme /packages/theme [Package] UI /packages/ui [Package] Viewport /packages/viewport [Package] Views /packages/views [Package] Widget Dashboard /packages/widget-dashboard [Package] Widget primitives /packages/widget-primitives [Type] Build Tooling Issues or PRs related to build tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants