chore(worker): upgrade @cloudflare/vitest-pool-workers to v0.16 and vitest to v4 - #284
Merged
Merged
Conversation
…est to v4
Migrates the Cloudflare Worker test setup from vitest 3.x / pool-workers
0.8.x to vitest 4.x / pool-workers 0.16.x:
- package.json: bump @cloudflare/vitest-pool-workers ^0.8→^0.16, vitest
^3→^4.1; add "type":"module" (required for vitest 4/rolldown to load
the ESM config file)
- vitest.config.js: replace defineWorkersConfig({test:{poolOptions:{…}}})
with defineConfig({plugins:[cloudflareTest(…)]}) per the v3→v4 codemod
- proxy.test.js / beverage-types.test.js: replace fetchMock (removed from
cloudflare:test in 0.16) with vi.stubGlobal('fetch', vi.fn()) and
mockResolvedValueOnce/mockRejectedValueOnce; all 56 tests pass
Part of #242 (slices 2 and 3).
Contributor
There was a problem hiding this comment.
Pull request overview
Upgrades the Cloudflare Worker test tooling to the latest @cloudflare/vitest-pool-workers/Vitest versions and updates the worker Vitest configuration and tests to match the new APIs.
Changes:
- Upgraded
@cloudflare/vitest-pool-workersto^0.16.0andvitestto^4.1.0(lockfile updated accordingly). - Migrated
vitest.config.jsto the new plugin-based config (cloudflareTest) and set the worker package to ESM ("type": "module"). - Replaced
cloudflare:test’s removedfetchMockusage withvi.stubGlobal('fetch', ...)in worker tests.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| cloudflare-worker/vitest.config.js | Switches Vitest config to plugin-based Cloudflare worker integration. |
| cloudflare-worker/test/proxy.test.js | Updates proxy tests to stub fetch via Vitest instead of fetchMock. |
| cloudflare-worker/test/beverage-types.test.js | Updates beverage types tests to stub fetch via Vitest instead of fetchMock. |
| cloudflare-worker/package.json | Updates devDependencies and marks package as ESM for Vitest/Vite config loading. |
| cloudflare-worker/package-lock.json | Lockfile refresh reflecting the dependency upgrades and new transitive tree. |
Comment on lines
51
to
58
| it('proxies requests to upstream and returns response', async () => { | ||
| const upstreamBody = JSON.stringify([{ name: 'Test Brewery', products: [] }]); | ||
| fetchMock.get(UPSTREAM) | ||
| .intercept({ path: '/cbf2025/beer.json' }) | ||
| .reply(200, upstreamBody, { | ||
| headers: { 'Content-Type': 'application/json' }, | ||
| }); | ||
| mockFetch.mockResolvedValueOnce(new Response(upstreamBody, { | ||
| status: 200, | ||
| headers: { 'Content-Type': 'application/json' }, | ||
| })); | ||
|
|
||
| const response = await fetchWorker('/cbf2025/beer.json'); |
Comment on lines
40
to
47
| it('parses directory listing into beverage types', async () => { | ||
| fetchMock.get(UPSTREAM) | ||
| .intercept({ path: '/cbf2025/' }) | ||
| .reply(200, makeDirectoryHtml([ | ||
| 'beer.json', 'cider.json', 'perry.json', 'mead.json', | ||
| ])); | ||
| mockFetch.mockResolvedValueOnce(new Response( | ||
| makeDirectoryHtml(['beer.json', 'cider.json', 'perry.json', 'mead.json']), | ||
| { status: 200 }, | ||
| )); | ||
|
|
||
| const response = await fetchWorker('/cbf2025/available_beverage_types.json'); | ||
| expect(response.status).toBe(200); |
Each stubbed-fetch test now verifies the exact upstream URL the worker
constructs, restoring the URL-validation coverage that fetchMock's
intercept({ path }) provided implicitly.
Owner
Author
|
@copilot review |
Agent-Logs-Url: https://github.com/richardthe3rd/cambridge-beer-festival-app/sessions/0c00ccf3-adc6-477f-818c-0327541020c6 Co-authored-by: richardthe3rd <573334+richardthe3rd@users.noreply.github.com>
Contributor
Addressed in 31d8f01: worker tests now assert full upstream fetch arguments (URL + init options) across proxy and available beverage type paths, and the worker test suite passes (56/56). Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
@cloudflare/vitest-pool-workersfrom^0.8to^0.16vitestfrom^3to^4.1"type":"module"tocloudflare-worker/package.jsonso vitest 4/rolldown can load the ESM config filevitest.config.jsfromdefineWorkersConfig({test:{poolOptions:{workers:…}}})todefineConfig({plugins:[cloudflareTest(…)]})per the official v3→v4 codemodfetchMockwas removed fromcloudflare:testin 0.16; replaced withvi.stubGlobal('fetch', vi.fn())+mockResolvedValueOnce/mockRejectedValueOnceAll 56 worker tests pass locally.
Part of #242 (slices 2 and 3 — config migration and test rewrite).
Generated by Claude Code