Skip to content

Use vitest#expect from the local context#12356

Merged
vicb merged 1 commit intomainfrom
vicb/expect-2
Feb 2, 2026
Merged

Use vitest#expect from the local context#12356
vicb merged 1 commit intomainfrom
vicb/expect-2

Conversation

@vicb
Copy link
Copy Markdown
Contributor

@vicb vicb commented Feb 2, 2026

Part of #12346
Follow up of #12347

The code changes are courtesy of OpenCode/Opus

Summary

This PR migrates test files to use expect from the local test context instead of importing it from vitest. This change improves concurrency safety when running tests with .concurrent.

Background

When running tests concurrently with Vitest, the global expect imported from vitest can cause issues because it cannot reliably detect which test is running. The Vitest documentation recommends using expect from the local test context instead.

Changes

Before:

import { expect, test } from "vitest";
test("name", () => {
  expect(value).toBe(1);
});

After:

import { test } from "vitest";
test("name", ({ expect }) => {
  expect(value).toBe(1);
});

ESLint Rule

A new ESLint rule workers-sdk/no-vitest-import-expect was added to enforce this pattern. The rule is enabled per-package as they are migrated.
For files with complex patterns (e.g., test.each, helper functions using expect at module scope), an eslint-disable comment is added:

// eslint-disable-next-line workers-sdk/no-vitest-import-expect -- see #12346
import { expect, test } from "vitest";

Migrated Packages

Package Test Files Trivial Complex (disabled)
pages-shared 3 2 1
vitest-pool-workers 1 1 0
edge-preview-authenticated-proxy 1 0 1
playground-preview-worker 1 0 1
containers-shared 3 3 0
workflows-shared 3 2 1
workers-utils 9 3 6
workers-shared 12 0 12

Remaining Packages (future PRs)

  • create-cloudflare (31 files)
  • vite-plugin-cloudflare (102 files)
  • wrangler (216 files)
  • fixtures/ (115 files)

  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: not a user facing change

A picture of a cute animal (not mandatory, but encouraged)


Open with Devin

@vicb vicb requested review from a team as code owners February 2, 2026 08:10
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Feb 2, 2026

⚠️ No Changeset found

Latest commit: 2488e6d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 4 additional flags.

Open in Devin Review

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Feb 2, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@12356

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@12356

miniflare

npm i https://pkg.pr.new/miniflare@12356

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@12356

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@12356

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@12356

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@12356

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@12356

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@12356

wrangler

npm i https://pkg.pr.new/wrangler@12356

commit: 2488e6d

@github-project-automation github-project-automation Bot moved this from Untriaged to Approved in workers-sdk Feb 2, 2026
@vicb
Copy link
Copy Markdown
Contributor Author

vicb commented Feb 2, 2026

Thanks for the review Matt!

@vicb vicb merged commit a4db914 into main Feb 2, 2026
39 of 41 checks passed
@vicb vicb deleted the vicb/expect-2 branch February 2, 2026 09:22
@github-project-automation github-project-automation Bot moved this from Approved to Done in workers-sdk Feb 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants