Skip to content

Use vitest#expect from the local context#12385

Merged
petebacondarwin merged 2 commits intomainfrom
vicb/expect-4
Feb 3, 2026
Merged

Use vitest#expect from the local context#12385
petebacondarwin merged 2 commits intomainfrom
vicb/expect-4

Conversation

@vicb
Copy link
Copy Markdown
Contributor

@vicb vicb commented Feb 3, 2026

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

This PR updates the fixtures folder.
Bceause it was not linted before, eslint configs have been added and @cloudflare/eslint-config-shared added to package.json.

The code changes are courtesy of OpenCode/Opus

Summary of Changes to fixtures/

Migrated fixture test files to use context-based expect from vitest for concurrency safety, and enabled the workers-sdk/no-vitest-import-expect ESLint rule.

Test File Migrations (~108 files)

Converted test files from:

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

To:

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

ESLint Configuration Added (57 projects)

Added eslint.config.mjs and @cloudflare/eslint-config-shared dependency to:

Project
fixtures/additional-modules
fixtures/browser-rendering
fixtures/d1-read-replication-app
fixtures/d1-worker-app
fixtures/dev-registry
fixtures/durable-objects-app
fixtures/dynamic-worker-loading
fixtures/entrypoints-rpc-tests
fixtures/get-platform-proxy
fixtures/get-platform-proxy-remote-bindings
fixtures/import-wasm-example
fixtures/interactive-dev-tests
fixtures/local-mode-tests
fixtures/no-bundle-import
fixtures/node-app-pages
fixtures/node-env
fixtures/nodejs-als-app
fixtures/nodejs-hybrid-app
fixtures/pages-d1-shim
fixtures/pages-dev-proxy-with-script
fixtures/pages-functions-app
fixtures/pages-functions-unenv-alias
fixtures/pages-functions-wasm-app
fixtures/pages-functions-with-config-file-app
fixtures/pages-functions-with-routes-app
fixtures/pages-nodejs-v2-compat
fixtures/pages-plugin-mounted-on-root-app
fixtures/pages-proxy-app
fixtures/pages-redirected-config
fixtures/pages-simple-assets
fixtures/pages-workerjs-and-functions-app
fixtures/pages-workerjs-app
fixtures/pages-workerjs-directory
fixtures/pages-workerjs-wasm-app
fixtures/pages-workerjs-with-config-file-app
fixtures/pages-workerjs-with-routes-app
fixtures/pages-ws-app
fixtures/ratelimit-app
fixtures/redirected-config-worker
fixtures/redirected-config-worker-with-environments
fixtures/unbound-durable-object
fixtures/vitest-pool-workers-examples
fixtures/vitest-pool-workers-remote-bindings
fixtures/wildcard-modules
fixtures/worker-app
fixtures/worker-logs
fixtures/worker-with-resources
fixtures/worker-with-unsafe-external-plugin
fixtures/workers-shared-asset-config
fixtures/workers-with-assets
fixtures/workers-with-assets-and-service-bindings
fixtures/workers-with-assets-only
fixtures/workers-with-assets-run-worker-first
fixtures/workers-with-assets-spa
fixtures/workers-with-assets-static-routing
fixtures/workflow
fixtures/workflow-multiple

Complex Files with eslint-disable (5 files)

These files use patterns incompatible with context-based expect (e.g., .each, helper functions):

File Reason
fixtures/interactive-dev-tests/tests/index.test.ts describe.each / it.each patterns
fixtures/workers-shared-asset-config/html-handling.test.ts describe.each / it.each patterns
fixtures/dev-registry/tests/dev-registry.test.ts expect in module-scope helper functions
fixtures/get-platform-proxy-remote-bindings/tests/index.test.ts expect in helper functions and beforeAll
fixtures/get-platform-proxy/tests/get-platform-proxy.env.test.ts expect used throughout tests
Excluded Projects
Project Reason
--------- --------
fixtures/import-npm/packages/import-example Uses npm (not pnpm), doesn't support workspace:*

Other Changes

  • Added export for rules/no-vitest-import-expect in packages/eslint-config-shared/package.json

  • 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 a review from a team as a code owner February 3, 2026 13:37
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Feb 3, 2026

⚠️ No Changeset found

Latest commit: c78cb52

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

@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@12385

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

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

wrangler

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

commit: c78cb52

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 found 1 potential issue.

Open in Devin Review

Comment on lines +192 to 197
test("should not retry a step if a NonRetryableError (with a generic error message) is thrown", async ({
expect,
}) => {
const name = randomUUID();
await fetchJson(
`http://${ip}:${port}/createDemo3?workflowName=${name}&doRetry=false&errorMessage=generic_error_message"`
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.

🔴 Stray double-quote in fetchJson URL breaks NonRetryableError retry test

The createDemo3 URL used in the NonRetryableError test includes an extra " at the end of the query string.

Actual behavior: the request is made to a different URL than intended (with an extra " character in the errorMessage parameter), so the fixture may not exercise the intended code path and can cause flaky/failed assertions about retry behavior.

Expected behavior: the URL should end after errorMessage=generic_error_message with no trailing quote.

Code reference
await fetchJson(
  `http://${ip}:${port}/createDemo3?workflowName=${name}&doRetry=false&errorMessage=generic_error_message"`
);

(Refers to lines 192-198)

Recommendation: Remove the trailing " from the template literal so the query string is ...&errorMessage=generic_error_message.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

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.

That's a good point... about existing code untouched in this PR.
I'll follow up after the PR gets merged.

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 found 1 new potential issue.

View issue and 5 additional flags in Devin Review.

Open in Devin Review

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.

🔴 Using expect(() => promise).rejects prevents rejection assertion from working

The test attempts to assert that a fetch() Promise rejects, but wraps the promise in a function and then uses .rejects.

Actual: .rejects expects a Promise/thenable. Passing a function means Vitest will not treat it as a promise rejection assertion, so this either fails immediately (type mismatch at runtime) or asserts the wrong thing.

Expected: pass the Promise directly: await expect(SELF.fetch(...)).rejects....

Click to expand

Code:

await expect(() =>
  SELF.fetch("http://example.com/container/hello")
).rejects.toThrow();

Correct pattern:

await expect(SELF.fetch("http://example.com/container/hello")).rejects.toThrow();

(Refers to lines 12-15)

Recommendation: Pass the SELF.fetch(...) promise directly to expect(...) when using .rejects.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Contributor Author

@vicb vicb Feb 3, 2026

Choose a reason for hiding this comment

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

Again a good finding in an existing and untouched test, I'll follow up after this PR.

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.

Nice

) {
let match = await cache.match("http://0.0.0.0/test");
expect(match).toBeUndefined();
// Note: we cannot use expect here since it's not in the test context
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.

Alternatively we could have passed the expect as a param to the testNoOpCache function...

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.

Good point!
I'll handle as part of the follow up with the 2 Devin findings.

@github-project-automation github-project-automation Bot moved this from Untriaged to Approved in workers-sdk Feb 3, 2026
@petebacondarwin petebacondarwin merged commit ead6246 into main Feb 3, 2026
40 checks passed
@github-project-automation github-project-automation Bot moved this from Approved to Done in workers-sdk Feb 3, 2026
@petebacondarwin petebacondarwin deleted the vicb/expect-4 branch February 3, 2026 16:31
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