Skip to content

Use vitest#expect from the local context#12373

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

Use vitest#expect from the local context#12373
petebacondarwin merged 1 commit intomainfrom
vicb/expect-3

Conversation

@vicb
Copy link
Copy Markdown
Contributor

@vicb vicb commented Feb 2, 2026

Part of #12346
Part of a series (#12347, #12356) handling simple refactors, one package at a time to keep the review simpler.

The code changes are courtesy of OpenCode/Opus

Note that the tests inside the templates have not been updated

Summary

I've successfully migrated the create-cloudflare package to use context-based expect for vitest concurrency safety. Here's the breakdown:

Changes Made

  1. ESLint Configuration (eslint.config.mjs)
  • Enabled the workers-sdk/no-vitest-import-expect rule for test files
  1. Trivial Files Migrated (18 files)
    These files were converted to use { expect } from the test context:
File Tests
src/tests/deploy.test.ts 9
src/tests/dialog.test.ts 6
src/tests/git.test.ts 24
src/tests/metrics.test.ts 15
src/tests/pre-existing.test.ts 2
src/tests/templates.test.ts 28
src/tests/workers.test.ts 9
src/helpers/tests/cli.test.ts 4
src/helpers/tests/codemod.test.ts 3
src/helpers/tests/command.test.ts 6
src/helpers/tests/compatDate.test.ts 6
src/helpers/tests/json.test.ts 8
src/helpers/tests/retry.test.ts 5
src/wrangler/tests/accounts.test.ts 7
src/wrangler/tests/config.test.ts 8
  1. Complex Files (12 files with eslint-disable)
    These files use patterns incompatible with context-based expect:
File Reason
e2e/helpers/framework-helpers.ts Helper module with expect at module scope
e2e/helpers/to-exist.ts Extends vitest expect with custom matcher
e2e/helpers/workers-helpers.ts Helper module with expect at module scope
src/helpers/tests/mocks.ts Helper module with expect at module scope
src/helpers/tests/packages.test.ts Uses test.each
src/helpers/tests/packageManagers.test.ts Uses test.each
src/frameworks/tests/index.test.ts Uses test.each
src/helpers/tests/args.test.ts Uses test.each
src/tests/validators.test.ts Uses test.each
e2e/tests/cli/cli.test.ts E2E test with complex patterns
e2e/tests/frameworks/frameworks.test.ts E2E test with complex patterns
e2e/tests/workers/workers.test.ts E2E test with complex patterns

Verification

  • ✅ Lint passes: pnpm --filter create-cloudflare check:lint
  • ✅ Tests pass: 206 tests passed (1 skipped)

  • 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 user facing

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


Open with Devin

@vicb vicb requested a review from a team as a code owner February 2, 2026 21:11
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Feb 2, 2026

⚠️ No Changeset found

Latest commit: 0e3b8f1

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 5 additional flags.

Open in Devin Review

Copy link
Copy Markdown
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

I wonder if test.each is a great pattern if we can't access the expect on the test function callback? I wonder if going forward there is an alternative approach for these iterations?

@@ -1,3 +1,4 @@
// eslint-disable-next-line workers-sdk/no-vitest-import-expect -- test.each pattern
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There are other tests in this file that don't use test.each that perhaps should be getting their expect from the callback args?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We have a lint rule to prevent shadowing that wouldn't be very happy with that. But again we'll tackle those later.

@vicb
Copy link
Copy Markdown
Contributor Author

vicb commented Feb 2, 2026

I wonder if test.each is a great pattern if we can't access the expect on the test function callback? I wonder if going forward there is an alternative approach for these iterations?

We can but getting the typings to work is a little trickier. When Claude tried to convert everything in one go, it failed after 6h two times.

That's why the PRs are handling simpler cases first and then I'll teach Claude how to fix the more complex cases.

@vicb
Copy link
Copy Markdown
Contributor Author

vicb commented Feb 2, 2026

Thanks for the review Pete, added some details to your questions

@github-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk Feb 3, 2026
@github-project-automation github-project-automation Bot moved this from Untriaged to Approved in workers-sdk Feb 3, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Feb 3, 2026

create-cloudflare

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

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

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

wrangler

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

commit: 0e3b8f1

@petebacondarwin petebacondarwin merged commit 7971be7 into main Feb 3, 2026
54 of 89 checks passed
@petebacondarwin petebacondarwin deleted the vicb/expect-3 branch February 3, 2026 10:15
@github-project-automation github-project-automation Bot moved this from Approved to Done in workers-sdk Feb 3, 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