Skip to content

chore(worker): upgrade @cloudflare/vitest-pool-workers to v0.16 and vitest to v4 - #284

Merged
richardthe3rd merged 3 commits into
mainfrom
claude/vitest-pool-workers-upgrade
May 17, 2026
Merged

chore(worker): upgrade @cloudflare/vitest-pool-workers to v0.16 and vitest to v4#284
richardthe3rd merged 3 commits into
mainfrom
claude/vitest-pool-workers-upgrade

Conversation

@richardthe3rd

Copy link
Copy Markdown
Owner

Summary

  • Bumps @cloudflare/vitest-pool-workers from ^0.8 to ^0.16
  • Bumps vitest from ^3 to ^4.1
  • Adds "type":"module" to cloudflare-worker/package.json so vitest 4/rolldown can load the ESM config file
  • Migrates vitest.config.js from defineWorkersConfig({test:{poolOptions:{workers:…}}}) to defineConfig({plugins:[cloudflareTest(…)]}) per the official v3→v4 codemod
  • Rewrites fetch mocking in both test files: fetchMock was removed from cloudflare:test in 0.16; replaced with vi.stubGlobal('fetch', vi.fn()) + mockResolvedValueOnce/mockRejectedValueOnce

All 56 worker tests pass locally.

Part of #242 (slices 2 and 3 — config migration and test rewrite).


Generated by Claude Code

…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).
Copilot AI review requested due to automatic review settings May 17, 2026 14:24

Copilot AI left a comment

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.

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-workers to ^0.16.0 and vitest to ^4.1.0 (lockfile updated accordingly).
  • Migrated vitest.config.js to the new plugin-based config (cloudflareTest) and set the worker package to ESM ("type": "module").
  • Replaced cloudflare:test’s removed fetchMock usage with vi.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.
@richardthe3rd

Copy link
Copy Markdown
Owner Author

@copilot review

Copilot AI commented May 17, 2026

Copy link
Copy Markdown
Contributor

@copilot review

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:

  • unofficial-builds.nodejs.org
    • Triggering command: /home/REDACTED/work/cambridge-beer-festival-app/cambridge-beer-festival-app/.mise/mise-2026.5.8 ./bin/mise run test:worker (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@richardthe3rd
richardthe3rd merged commit cdfb384 into main May 17, 2026
14 checks passed
@richardthe3rd
richardthe3rd deleted the claude/vitest-pool-workers-upgrade branch May 17, 2026 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants