test: consolidate MCP client/fetch-stub setup into useTestClient helper (#333)

This commit is contained in:
Sampson authored and GitHub committed 2026-08-11 15:13:10 -05:00
1 parent ad288a4ef9
commit 937e85a61f
9 files changed
+211 -351

No files matched your search

+7 -21
View File
@@ -1,31 +1,17 @@
import assert from 'node:assert/strict';
import { after, before, describe, it } from 'node:test';
import type { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { connectTestClient, stubFetch } from '../../testUtils/mcpTestHarness.js';
import { describe, it } from 'node:test';
import { useTestClient } from '../../testUtils/mcpTestHarness.js';
import { name } from './index.js';
describe(name, () => {
let client: Client;
let close: () => Promise<void>;
let restoreFetch: () => void;
before(async () => {
restoreFetch = stubFetch((url) => {
if (url.pathname === '/res/v1/local/place_search') {
return { type: 'locations' };
}
});
({ client, close } = await connectTestClient());
});
after(async () => {
restoreFetch();
await close();
const getClient = useTestClient((url) => {
if (url.pathname === '/res/v1/local/place_search') {
return { type: 'locations' };
}
});
it('returns a locations response for a simple location query', async () => {
const result = await client.callTool({
const result = await getClient().callTool({
name,
arguments: { location: 'san francisco ca united states' },
});