Skip to content

Plugins: Convert the tests to TypeScript - #85088

Open
R1shabh-Gupta wants to merge 2 commits into
WordPress:trunkfrom
R1shabh-Gupta:update/plugins-tests-typescript
Open

R1shabh-Gupta wants to merge 2 commits into
WordPress:trunkfrom
R1shabh-Gupta:update/plugins-tests-typescript

Conversation

@R1shabh-Gupta

Copy link
Copy Markdown
Contributor

What?

Part of #67691.

Converts the two JavaScript tests in @wordpress/plugins, src/api/test/index.js and src/components/test/plugin-area.jsdom.test.jsx, to TypeScript.

Why?

The package source is already TypeScript, but its tests were still JavaScript and not type checked. This is the plugins item under Tests in the tracking issue.

How?

Splits the package's single tsconfig.json into a build project (tsconfig.build.json) and a dev project (tsconfig.json). Consumers and the root tsconfig.build.json now reference the build project, and the stale ESLint suppressions for the old paths are removed.

Test changes, all type-only:

  • The "fails to register" tests pass invalid input on purpose (no arguments, an object name, settings without render, an object scope), so each of those arguments gets a narrow @ts-expect-error.
  • TestComponent gets a { content: string } props type.
  • ComponentSpy is annotated as ComponentType< { content: string } >.

Testing Instructions

  1. npm run test:unit:vitest -- packages/plugins: all 16 tests pass.
  2. npm run typecheck, npm run lint:tsconfig, npm run lint:js and npm run build pass.

Use of AI Tools

This PR was developed with the assistance of Claude Code.

@coderabbitai review

@github-actions github-actions Bot added [Package] Plugins /packages/plugins [Package] Editor /packages/editor [Package] Interface /packages/interface [Package] Edit Site /packages/edit-site [Package] Boot /packages/boot labels Oct 19, 2026
@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground

🎉 Props

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: R1shabh-Gupta <rishabhwp@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.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

@R1shabh-Gupta
R1shabh-Gupta marked this pull request as ready for review October 19, 2026 13:48
@coderabbitai

coderabbitai Bot commented Oct 19, 2026

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: WordPress/gutenberg/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 709df5a1-198d-4a7b-a90d-edfadbfeff4b
📥 Commits

Reviewing files that changed from the base of the PR and between ab9bf10 and 35c7064.

📒 Files selected for processing: 13
  • packages/boot/tsconfig.json
  • packages/edit-site/tsconfig.json
  • packages/editor/tsconfig.build.json
  • packages/editor/tsconfig.json
  • packages/interface/tsconfig.build.json
  • packages/plugins/CHANGELOG.md
  • packages/plugins/src/api/test/index.ts
  • packages/plugins/src/components/test/plugin-area.jsdom.test.tsx
  • packages/plugins/tsconfig.build.json
  • packages/plugins/tsconfig.json
  • tools/eslint/suppressions.json
  • tsconfig.build.json
  • tsconfig.json
💤 Files with no reviewable changes: 1
  • tools/eslint/suppressions.json

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

📝 Summary

Summary by CodeRabbit

  • Chores
    • Updated build configuration across the editor and related packages to keep plugin builds aligned.
  • Tests
    • Converted plugin tests to TypeScript and added checks for invalid plugin registrations and component props.
    • Plugin tests are now type-checked without including their declarations in published builds.
  • Documentation
    • Recorded the plugin test and build-configuration updates in the package changelog.

The plugins package now has separate build and development TypeScript configurations. Project references target the build configuration. Plugin tests have TypeScript annotations, and related ESLint suppressions were removed.

Changes: Plugins TypeScript configuration

Layer / File(s) Summary
Separate build and development projects
packages/plugins/tsconfig.build.json, packages/plugins/tsconfig.json, tsconfig.json, tsconfig.build.json, packages/boot/tsconfig.json, packages/edit-site/tsconfig.json, packages/editor/tsconfig*.json, packages/interface/tsconfig.build.json
A build configuration was added for the plugins package. The development configuration now references it. Root and package project references target the plugins build configuration.
Type-check plugins tests
packages/plugins/src/api/test/index.ts, packages/plugins/src/components/test/plugin-area.jsdom.test.tsx, tools/eslint/suppressions.json, packages/plugins/CHANGELOG.md
Tests gained TypeScript type annotations and expected-error directives. The corresponding ESLint suppressions were removed. The changelog records the test conversion and configuration split.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other

Suggested reviewers: manzoorwanijk, ciampo

Merge Risk: ⚪ Minimal · up to 35c70

The configuration keeps tests in development type-checking without publishing their declarations. No actionable merge-blocking risk remains.

Pre-merge checks: Passed 5
Check name Status Explanation
Description check Passed The description clearly explains the TypeScript test conversion, TypeScript configuration split, project reference updates, ESLint suppression removal, and validation steps.
Title check Passed The title clearly identifies the primary change: converting the plugins tests to TypeScript.
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
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.
Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2 files. (10 skipped: 10 unsupported.)

✨ Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.

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.

{ "path": "../compose/tsconfig.build.json" },
{ "path": "../deprecated/tsconfig.build.json" },
{ "path": "../element/tsconfig.build.json" },
{ "path": "../hooks" },

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.

hooks was split in #85141, so after rebasing this must be ../hooks/tsconfig.build.json; ../hooks is now its noEmit dev project, which a project reference cannot point at. The rebase conflict lands in tsconfig.json, so this line is easy to miss.

const ComponentSpy = vi.fn( ( { content } ) => {
return `plugin: ${ content }.`;
} );
const ComponentSpy: ComponentType< { content: string } > = vi.fn(

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.

Typing the parameter, as TestComponent does above, is shorter and keeps the mock type. The ComponentType import can then go:

const ComponentSpy = vi.fn( ( { content }: { content: string } ) => {
	return `plugin: ${ content }.`;
} );

@manzoorwanijk manzoorwanijk added [Type] Code Quality Issues or PRs that relate to code quality props-bot Manually triggers Props Bot to ensure the list of props is up to date. labels Oct 20, 2026
@github-actions github-actions Bot removed the props-bot Manually triggers Props Bot to ensure the list of props is up to date. label Oct 20, 2026

This branch has not been deployed

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

Labels

[Package] Boot /packages/boot [Package] Edit Site /packages/edit-site [Package] Editor /packages/editor [Package] Interface /packages/interface [Package] Plugins /packages/plugins [Type] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants