Fix tests
This commit is contained in:
parent
92621516f8
commit
3e2dd35dca
6 changed files with 26 additions and 16 deletions
|
|
@ -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/"],
|
||||
};
|
||||
|
|
|
|||
6
src/__mocks__/pkce-challenge.ts
Normal file
6
src/__mocks__/pkce-challenge.ts
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
export default function pkceChallenge() {
|
||||
return {
|
||||
code_verifier: "test_verifier",
|
||||
code_challenge: "test_challenge",
|
||||
};
|
||||
}
|
||||
|
|
@ -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 () => {
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -5,5 +5,5 @@
|
|||
"moduleResolution": "node",
|
||||
"outDir": "./dist/cjs"
|
||||
},
|
||||
"exclude": ["**/*.test.ts"]
|
||||
"exclude": ["**/*.test.ts", "src/__mocks__/**/*"]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,5 +3,5 @@
|
|||
"compilerOptions": {
|
||||
"outDir": "./dist/esm"
|
||||
},
|
||||
"exclude": ["**/*.test.ts"]
|
||||
"exclude": ["**/*.test.ts", "src/__mocks__/**/*"]
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue