Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/mcp-cloudflare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"devDependencies": {
"@cloudflare/vite-plugin": "^1.13.15",
"@cloudflare/vitest-pool-workers": "catalog:",
"@cloudflare/vitest-plugin": "catalog:",
"@cloudflare/workers-types": "catalog:",
"@sentry/mcp-core": "workspace:*",
"@sentry/mcp-server-mocks": "workspace:*",
Expand All @@ -45,6 +45,7 @@
"@vitejs/plugin-react": "catalog:",
"tailwindcss": "catalog:",
"urlpattern-polyfill": "^10.1.0",
"undici": "^7.24.4",
"vite": "catalog:",
"vitest": "catalog:",
"miniflare": "catalog:",
Expand Down
14 changes: 9 additions & 5 deletions packages/mcp-cloudflare/src/test-utils/configure-fetch-mock.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { createFetchMock } from "miniflare";
import { Response, type V4FetchHandler } from "miniflare";
import { fetch, MockAgent } from "undici";
import {
registerFetchMockInterceptors,
type FetchMockLike,
} from "./fetch-mock-setup";

export function createConfiguredFetchMock(): FetchMockLike {
const fetchMock = createFetchMock() as FetchMockLike;
export function createMockOutboundService(): V4FetchHandler {
const fetchMock = new MockAgent();
fetchMock.disableNetConnect();
registerFetchMockInterceptors(fetchMock);
return fetchMock;
registerFetchMockInterceptors(fetchMock as FetchMockLike);
return async (request) => {
const response = await fetch(request, { dispatcher: fetchMock });
return new Response(response.body, response);
};
}
2 changes: 1 addition & 1 deletion packages/mcp-cloudflare/src/test-utils/fetch-mock-setup.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Shared outbound mock registrations for Cloudflare Workers tests.
*
* The current vitest-pool-workers stack configures Miniflare's `fetchMock`
* The Cloudflare Vitest plugin configures Miniflare's `outboundService`
* centrally from vitest.config.ts so test files do not need per-file setup.
*/
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/mcp-cloudflare/tsconfig.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compilerOptions": {
"types": [
"@cloudflare/workers-types",
"@cloudflare/vitest-pool-workers"
"@cloudflare/vitest-plugin"
]
},
"include": [
Expand Down
10 changes: 5 additions & 5 deletions packages/mcp-cloudflare/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import path from "node:path";
import { cloudflareTest } from "@cloudflare/vitest-pool-workers";
import { cloudflareTest } from "@cloudflare/vitest-plugin";
import { defineConfig } from "vitest/config";
import { createConfiguredFetchMock } from "./src/test-utils/configure-fetch-mock";
import { createMockOutboundService } from "./src/test-utils/configure-fetch-mock";

/**
* Unified vitest config using vitest-pool-workers.
* Unified vitest config using the Cloudflare Vitest plugin.
*
* All tests run in the Cloudflare Workers runtime (workerd) which enables:
* - Testing with cloudflare:test bindings (KV, AI, etc.)
* - Using fetchMock from cloudflare:test for HTTP mocking
* - Using centrally registered outbound HTTP fixtures
*
* Bindings (KV, vars, compatibility flags) are defined in wrangler.test.jsonc
* to keep test config aligned with production wrangler.jsonc.
Expand All @@ -18,7 +18,7 @@ export default defineConfig({
cloudflareTest({
main: "./src/server/index.ts",
miniflare: {
fetchMock: createConfiguredFetchMock(),
outboundService: createMockOutboundService(),
},
wrangler: { configPath: "./wrangler.test.jsonc" },
}),
Expand Down
Loading
Loading