Skip to content

test: Set up Vitest #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
May 16, 2025
Merged

test: Set up Vitest #131

merged 12 commits into from
May 16, 2025

Conversation

dcalhoun
Copy link
Member

What?

Set up an automated JavaScript testing environment.

Why?

Improve project stability. Close CMM-285.

How?

Leverage several dependencies already used by the Gutenberg project, with one divergence—use Vitest rather than Jest.

Attempts to set up an environment with vitest-jest and Gutenberg's jest-preset-default were unsuccessful, as I encountered numerous build errors related to Babel configuration. Using Jest, Vite, and jest-preset-default together may not straightforward. Also, vitest-jest appears to be an abandoned project. Vitest does have differences from Jest, but remains largely compatible.

In the future, we could reengage explorations for how we might further align with Gutenberg and use jest-preset-default.

Testing Instructions

N/A, no user-facing changes.

Accessibility Testing Instructions

N/A, no user-facing changes.

Screenshots or screencast

N/A, no user-facing changes.

@dcalhoun dcalhoun requested a review from Copilot May 14, 2025 18:52
@dcalhoun dcalhoun added the [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. label May 14, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR sets up an automated JavaScript testing environment using Vitest instead of Jest for the Gutenberg project. The key changes include adding Vitest configuration files (vitest.setup.js and vitest.config.js), updating test files (editor-load-notice.test.jsx) to work with Vitest, and modifying build scripts (package.json, Makefile, and Buildkite pipeline) and documentation to support JavaScript tests.

Reviewed Changes

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

Show a summary per file
File Description
vitest.setup.js Configures auto-cleanup for tests using Testing Library with Vitest.
vitest.config.js Defines the Vitest configuration including plugins and setup files.
src/components/editor-load-notice.test.jsx Adds tests for EditorLoadNotice covering multiple user interactions.
package.json Updates scripts and dependencies to include Vitest and Testing Library.
mocks/@wordpress/i18n/index.js Provides a simple mock for i18n functions using Vitest’s vi.fn().
mocks/@wordpress/components/index.jsx Mocks a Notice component for testing purposes.
README.md Enhances documentation with instructions for running JavaScript and other tests.
Makefile Adds a target to run JavaScript tests via npm and Vitest.
.buildkite/pipeline.yml Introduces a step to run JavaScript tests on the CI pipeline.

Avoid cryptic errors from lingering global stubs.
@dcalhoun dcalhoun enabled auto-merge (squash) May 14, 2025 19:00
@dcalhoun dcalhoun requested a review from kean May 14, 2025 19:04
@dcalhoun dcalhoun merged commit 167d87d into trunk May 16, 2025
11 checks passed
@dcalhoun dcalhoun deleted the test/vitest-setup branch May 16, 2025 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[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.

2 participants