Skip to content

Enforce canonical Vitest test conventions - #80880

Closed
ciampo wants to merge 4 commits into
codex/vitest-14-block-directory-snapshotsfrom
codex/vitest-15-test-graph-guardrails
Closed

ciampo wants to merge 4 commits into
codex/vitest-14-block-directory-snapshotsfrom
codex/vitest-15-test-graph-guardrails

Conversation

@ciampo

@ciampo ciampo commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

What?

Part of #80855. Stacked on #80878; review commit 1daffed73db.

TL;DR — canonical authoring and type-graph guardrails: adds a CI validator for ESM-only Vitest tests, explicit runner imports, dynamic-import TypeScript mocks, workspace-owned Vitest dependencies, version consistency, and complete migrated TS/TSX test type-checking.

Why?

Passing tests alone does not prove the intended native-Vitest end state. Normal package builds also exclude some test directories, so migrated TypeScript tests could execute while retaining type errors or untyped mocks. This PR makes the canonical conventions in #80855 executable gates before larger package migrations.

How?

The validator:

  • discovers the active Vitest partition from the migration manifest;
  • rejects CommonJS exports and unbound require() in the authored Vitest graph;
  • rejects unbound Vitest APIs and vitest/globals;
  • requires TypeScript vi.mock() calls to use vi.mock(import(...));
  • requires each owning workspace to declare the same devDependencies.vitest version;
  • generates isolated no-emit TypeScript projects covering every migrated TS/TSX test;
  • runs in the existing JavaScript routing CI job.

The clean CI job first runs the repository's standard custom workspace builds (including generated Icons exports), then generates the official Vips/video-conversion worker placeholders and package declarations before validating the test-only TypeScript graph. This preserves real workspace types without pulling unrelated package source into the isolated test project or relying on local build artifacts.

Enabling the type graph exposed and fixed type-only gaps in existing migrated tests: complete Abilities reducer fixtures, explicit invalid-input boundaries, an ambiguous empty array, two useResizeObserver mocks, and the narrow selector contract used from untyped @wordpress/commands.

@wordpress/commands remains an explicit compatibility declaration because that JavaScript package does not publish types. No production code, runner ownership, or snapshots change.

Testing Instructions

  1. From a checkout without generated build outputs, declarations, or worker placeholders, run:
    • npx lerna run build
    • npm run --workspace @wordpress/build-scripts generate-worker-placeholders
    • npx tsc --build
    • npm run test:unit:conventions
    • Expected: 67 Vitest tests, 83 ESM graph files, 25 workspaces, and 41 TypeScript tests validated.
  2. npm run test:unit:routing
    • Expected: 933 Jest, 67 Vitest, no overlap, and no missing baseline tests.
  3. npm run test:unit:vitest
    • Expected: 67 files and 902 tests.
  4. Run all four Vitest shards.
  5. Run focused JS lint, npm run lint:pkg-json, npm run lint:lockfile, and npm run lint:tsconfig.

npm run lint:deps continues to report only the repository's pre-existing @babel/core and yargs version drift.

Testing Instructions for Keyboard

Not applicable; production behavior is unchanged.

Screenshots or screencast

Not applicable.

Use of AI Tools

AI tools helped implement and adversarially exercise the validator, reproduce clean-CI failures, add the official generated prerequisites, and run deterministic verification.

@github-actions

Copy link
Copy Markdown

Size Change: 0 B

Total Size: 7.76 MB

compressed-size-action

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

Labels

[Package] is-shallow-equal /packages/is-shallow-equal

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant