Skip to content

Conversation

@penalosa
Copy link
Contributor

@penalosa penalosa commented Jan 22, 2026

Summary

This PR migrates tests away from the deprecated unstable_dev() API to use either unstable_startWorker() or vitest-pool-workers.

  • Migrate fixtures/ integration tests to unstable_startWorker()
  • Migrate edge-preview-authenticated-proxy to vitest-pool-workers
  • Migrate middleware.test.ts and middleware.scheduled.test.ts to unstable_startWorker()
  • Delete unused templates/init-tests/ directory (dead code using old API)

  • 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: Internal API migration only

Open with Devin

- Migrate fixtures/local-mode-tests (5 test files) to use unstable_startWorker
- Migrate fixtures/no-bundle-import to use unstable_startWorker
- Delete fixtures/unstable_dev/ (only existed to test the deprecated API)
- Delete packages/wrangler/src/__tests__/api-dev.test.ts (deprecated API tests)
- Remove unstable_dev() test block from e2e/dev-registry.test.ts
- Remove unused Unstable_DevWorker imports from get-platform-proxy tests
- Remove unstable_dev label from auto-assign-issues.ts

Key API changes in migrated tests:
- unstable_dev(path, opts) → unstable_startWorker({ entrypoint: path, ...opts })
- vars: { KEY: val } → bindings: { KEY: { type: 'plain_text', value: val } }
- worker.stop() → worker.dispose()
- worker.fetch('/path') → worker.fetch('http://example.com/path')
…t-pool-workers

- Replace unstable_dev() with @cloudflare/vitest-pool-workers
- Use SELF.fetch() for testing the worker
- Use vi.spyOn(globalThis, 'fetch') to mock outbound requests to remote worker
- Configure isolatedStorage: false to preserve KV state between tests
- Add resolve.alias to fix promjs broken package.json (main points to lib/index.js but files are at root)
- Update tests/tsconfig.json with vitest-pool-workers types

All 25 tests pass.
- Migrate middleware.test.ts (26 tests)
- Migrate middleware.scheduled.test.ts (10 tests)
- Delete unused templates/init-tests/ directory (dead code)
@changeset-bot
Copy link

changeset-bot bot commented Jan 22, 2026

⚠️ No Changeset found

Latest commit: 3c79436

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

Comment on lines 23 to 24
// Let other requests pass through (e.g., prometheus logging)
// In tests, we don't want these to fail
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
// Let other requests pass through (e.g., prometheus logging)
// In tests, we don't want these to fail

Comment on lines 84 to 86
vi.spyOn(globalThis, "fetch").mockImplementation(
createMockFetchImplementation()
);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should be in a beforeEach()

Comment on lines 75 to 79
beforeAll(() => {
vi.spyOn(globalThis, "fetch").mockImplementation(
createMockFetchImplementation()
);
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Get rid of this and use beforeEach()

Comment on lines 310 to 312
vi.spyOn(globalThis, "fetch").mockImplementation(
createMockFetchImplementation()
);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As above, use a beforeEach

Comment on lines 301 to 303
beforeAll(() => {
vi.spyOn(globalThis, "fetch").mockImplementation(
createMockFetchImplementation()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you really need this again? The remote is the same as the one above

origin: "https://cloudflare.dev",
"X-CF-Token": token,
"X-CF-Remote": `http://127.0.0.1:${remote.port}`,
"X-CF-Remote": `${MOCK_REMOTE_URL}`,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This template stirng is overkill

origin: "https://cloudflare.dev",
"X-CF-Token": token,
"X-CF-Remote": `http://127.0.0.1:${remote.port}`,
"X-CF-Remote": `${MOCK_REMOTE_URL}`,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This template string is overkill

origin: "https://cloudflare.dev",
"X-CF-Token": token,
"X-CF-Remote": `http://127.0.0.1:${remote.port}`,
"X-CF-Remote": `${MOCK_REMOTE_URL}`,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This template string is overkill

origin: "https://cloudflare.dev",
"X-CF-Token": token,
"X-CF-Remote": `http://127.0.0.1:${remote.port}`,
"X-CF-Remote": `${MOCK_REMOTE_URL}`,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, get rid of any and all redudant template strings

Comment on lines 19 to 25
// promjs has broken package.json (main points to lib/index.js but files are at root)
resolve: {
alias: {
promjs: path.resolve(__dirname, "node_modules/promjs/index.js"),
},
},
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this needed? Did you have a look at the recommended SSR optimisations for vitest-pool-workers from the docs? Can you apply that to promjs?

import * as fs from "node:fs";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { unstable_dev } from "../api";
import { startWorker as unstable_startWorker } from "../api/startDevWorker";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just import it as startWorker

import dedent from "ts-dedent";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { unstable_dev } from "../api";
import { startWorker as unstable_startWorker } from "../api/startDevWorker";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just import it as startWorker

Comment on lines 1080 to 1084
// Note: worker.fetch() doesn't work correctly with paths when
// EXPERIMENTAL_MIDDLEWARE=true is set. The request URL pathname gets
// lost, causing the worker to not match routes like "/setup".
// We use native fetch() with the worker URL as a workaround.
// See: https://github.com/cloudflare/workers-sdk/issues/XXXX
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Change this to a TODO comment. We should get to the bottom of it

- Use beforeEach instead of beforeAll + afterEach re-mock pattern
- Remove redundant template strings for MOCK_REMOTE_URL
- Remove unnecessary comment about prometheus logging
- Use @cloudflare/vitest-pool-workers/latest in tsconfig
- Import startWorker directly instead of aliasing
- Change worker.fetch() workaround comment to TODO
@penalosa penalosa changed the title [wrangler] Migrate tests from unstable_dev() to unstable_startWorker() Migrate tests from unstable_dev() to unstable_startWorker() Jan 22, 2026
@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 22, 2026

create-cloudflare

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

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

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

wrangler

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

commit: 3c79436

- Fix unused imports in dev-registry.test.ts
- Fix RequestInfo type to Request | string | URL
- Exclude vitest.config.mts from tsconfig type checking
@penalosa penalosa marked this pull request as ready for review January 22, 2026 21:25
@penalosa penalosa requested a review from a team as a code owner January 22, 2026 21:25
Copy link
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

1 participant