Skip to content

Use vitest#expect from the local context#12403

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

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

Conversation

@vicb
Copy link
Copy Markdown
Contributor

@vicb vicb commented Feb 4, 2026

Part of #12346

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

This PR handles bucket 1 out of 4 of the wrangler package.

Code was created by OpenNext/Opus:

Wrangler Bucket 1 Migration Summary

Overview

Migrated 39 test files in packages/wrangler/src/__tests__/ from directories pages/, d1/, kv/, and queues/ to use expect from the test context instead of importing it from vitest.

ESLint Configuration

Added to packages/wrangler/eslint.config.mjs:

// Bucket 1: pages, d1, kv, queues
{
  files: ["src/__tests__/{pages,d1,kv,queues}/**/*.test.ts"],
  rules: {
    "workers-sdk/no-vitest-import-expect": "error",
  },
},

Files Changed

Trivial Files Migrated (27)

These files were fully converted to use expect from the test context:

d1/ (13 files):

  • convert-timestamp-to-iso.test.ts
  • create.test.ts
  • d1.test.ts
  • execute.test.ts
  • export.test.ts
  • info.test.ts
  • insights.test.ts
  • list.test.ts
  • migrate.test.ts
  • splitter.test.ts
  • timeTravel.test.ts
  • trimmer.test.ts
  • utils.test.ts

kv/ (2 files):

  • help.test.ts
  • local.test.ts

pages/ (11 files):

  • dev.test.ts
  • filepath-routing.test.ts
  • functions-build.test.ts
  • pages-build-env.test.ts
  • pages-deployment-tail.test.ts
  • pages.test.ts
  • project-delete.test.ts
  • project-validate.test.ts
  • routes-consolidation.test.ts
  • routes-transformation.test.ts
  • routes-validation.test.ts

queues/ (1 file):

  • queues-subscription.test.ts

Complex Files Disabled (12)

These files have the lint rule disabled with /* eslint-disable workers-sdk/no-vitest-import-expect */:

File Reason
d1/delete.test.ts expect used in mockDatabaseDelete helper function
kv/bulk.test.ts expect used in MSW request handlers
kv/key.test.ts expect used in MSW request handlers
kv/namespace.test.ts Uses test.each patterns
pages/deploy.test.ts Uses test.each patterns
pages/deployment-list.test.ts expect used in MSW handlers
pages/pages-download-config.test.ts expect used in MSW handlers
pages/project-create.test.ts expect used in MSW handlers
pages/project-list.test.ts expect used in MSW handlers
pages/project-upload.test.ts expect used in MSW handlers
pages/secret.test.ts expect used in MSW handlers
queues/queues.test.ts Uses test.each patterns

Conversion Pattern

Before:

import { describe, expect, it } from "vitest";

it("should work", async () => {
  expect(value).toBe(1);
});

After:

import { describe, it } from "vitest";

it("should work", async ({ expect }) => {
  expect(value).toBe(1);
});

Verification

  • Lint: pnpm --filter wrangler check:lint passes with 0 errors
  • Tests: All 2841 tests pass (2829 passed, 3 skipped, 9 todo)

Remaining Buckets

Bucket Directories Files Status
1 pages/, d1/, kv/, queues/ 39 Completed
2 r2/, cloudchamber/, containers/, vectorize/ 31 Pending
3 versions/, autoconfig/, api/, deploy/, dev/, config/, utils/, core/, metrics/ 40 Pending
4 Root-level files 66 Pending

  • 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: no user facing changes

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


Open with Devin

@vicb vicb requested review from a team as code owners February 4, 2026 06:15
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Feb 4, 2026

⚠️ No Changeset found

Latest commit: deb89c4

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 bugs or issues to report.

Open in Devin Review

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Feb 4, 2026

create-cloudflare

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

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

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

wrangler

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

commit: deb89c4

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.

As a follow up we should refactor all the expect usage in MSW handlers to just return 500 responses instead. It is considered an anti-pattern to do expectation checks inside these handlers.

@github-project-automation github-project-automation Bot moved this from Untriaged to Approved in workers-sdk Feb 4, 2026
@petebacondarwin petebacondarwin merged commit 4edbcd8 into main Feb 4, 2026
46 of 49 checks passed
@petebacondarwin petebacondarwin deleted the vicb/expect-wrangler-1 branch February 4, 2026 10:05
@github-project-automation github-project-automation Bot moved this from Approved to Done in workers-sdk Feb 4, 2026
@vicb
Copy link
Copy Markdown
Contributor Author

vicb commented Feb 4, 2026

As a follow up we should refactor all the expect usage in MSW handlers to just return 500 responses instead. It is considered an anti-pattern to do expectation checks inside these handlers.

I'm adding that to the parent issue to make sure to do that at the end.

Thanks for the review!

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