Fix tests

This commit is contained in:
Justin Spahr-Summers 2025-02-11 22:02:20 +00:00
commit 3e2dd35dca
No known key found for this signature in database
6 changed files with 26 additions and 16 deletions

View file

@ -7,6 +7,10 @@ export default {
...defaultEsmPreset,
moduleNameMapper: {
"^(\\.{1,2}/.*)\\.js$": "$1",
"^pkce-challenge$": "<rootDir>/src/__mocks__/pkce-challenge.ts"
},
transformIgnorePatterns: [
"/node_modules/(?!eventsource)/"
],
testPathIgnorePatterns: ["/node_modules/", "/dist/"],
};

View file

@ -0,0 +1,6 @@
export default function pkceChallenge() {
return {
code_verifier: "test_verifier",
code_challenge: "test_challenge",
};
}

View file

@ -6,14 +6,6 @@ import {
registerClient,
} from "./auth.js";
// Mock pkce-challenge
jest.mock("pkce-challenge", () => ({
__esModule: true,
default: () => ({
code_verifier: "test_verifier",
code_challenge: "test_challenge",
}),
}));
// Mock fetch globally
const mockFetch = jest.fn();
@ -43,11 +35,13 @@ describe("OAuth Authorization", () => {
const metadata = await discoverOAuthMetadata("https://auth.example.com");
expect(metadata).toEqual(validMetadata);
expect(mockFetch).toHaveBeenCalledWith(
expect.objectContaining({
href: "https://auth.example.com/.well-known/oauth-authorization-server",
})
);
const calls = mockFetch.mock.calls;
expect(calls.length).toBe(1);
const [url, options] = calls[0];
expect(url.toString()).toBe("https://auth.example.com/.well-known/oauth-authorization-server");
expect(options.headers).toEqual({
"MCP-Protocol-Version": "2024-11-05"
});
});
it("returns undefined when discovery endpoint returns 404", async () => {

View file

@ -105,7 +105,13 @@ export class SSEClientTransport implements Transport {
this._eventSource = new EventSource(
this._url.href,
this._eventSourceInit ?? {
fetch: (url, init) => this._commonHeaders().then((headers) => fetch(url, { ...init, headers })),
fetch: (url, init) => this._commonHeaders().then((headers) => fetch(url, {
...init,
headers: {
...headers,
Accept: "text/event-stream"
}
})),
},
);
this._abortController = new AbortController();

View file

@ -5,5 +5,5 @@
"moduleResolution": "node",
"outDir": "./dist/cjs"
},
"exclude": ["**/*.test.ts"]
"exclude": ["**/*.test.ts", "src/__mocks__/**/*"]
}

View file

@ -3,5 +3,5 @@
"compilerOptions": {
"outDir": "./dist/esm"
},
"exclude": ["**/*.test.ts"]
"exclude": ["**/*.test.ts", "src/__mocks__/**/*"]
}