Files
outline/server/test/setup.ts
T
Tom Moor 2a2774a6d0 chore: Update modelcontextprotocol (#12052)
* chore: Update modelcontextprotocol

* fix: Restore native Web API classes after jest-fetch-mock setup

jest-fetch-mock replaces globalThis.Response with a cross-fetch polyfill
that doesn't support Web Streams (ReadableStream bodies become Buffers).
The MCP SDK's @hono/node-server adapter calls response.body.getReader()
which fails with the polyfilled Response. Since dontMock() is already
called, preserving the native classes is the correct behavior.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-15 08:15:43 -04:00

67 lines
1.8 KiB
TypeScript

import "reflect-metadata";
import sharedEnv from "@shared/env";
import env from "@server/env";
import { EventEmitter } from "node:events";
// Increase the default max listeners for EventEmitter to prevent warnings in tests
// This needs to be done before any modules that use EventEmitter are loaded
EventEmitter.defaultMaxListeners = 100;
// Save native Response/Request before jest-fetch-mock replaces them with
// cross-fetch polyfills that don't support Web Streams (e.g. ReadableStream
// bodies lose their getReader method). The MCP SDK's @hono/node-server adapter
// depends on proper Web Streams support.
const NativeResponse = globalThis.Response;
const NativeRequest = globalThis.Request;
const NativeHeaders = globalThis.Headers;
// Enable fetch mocks for testing
require("jest-fetch-mock").enableMocks();
fetchMock.dontMock();
// Restore native Web API classes
globalThis.Response = NativeResponse;
globalThis.Request = NativeRequest;
globalThis.Headers = NativeHeaders;
// Mock AWS SDK S3 client and related commands
jest.mock("@aws-sdk/client-s3", () => ({
S3Client: jest.fn(() => ({
send: jest.fn(),
})),
DeleteObjectCommand: jest.fn(),
GetObjectCommand: jest.fn(),
ObjectCannedACL: {},
}));
jest.mock("@aws-sdk/lib-storage", () => ({
Upload: jest.fn(() => ({
done: jest.fn(),
})),
}));
jest.mock("@aws-sdk/s3-presigned-post", () => ({
createPresignedPost: jest.fn(),
}));
jest.mock("@aws-sdk/s3-request-presigner", () => ({
getSignedUrl: jest.fn(),
}));
// Initialize the database models
require("@server/storage/database");
// Import Redis after mocking
const Redis = require("ioredis");
beforeEach(() => {
env.URL = sharedEnv.URL = "https://app.outline.dev";
});
afterEach(async () => {
// Create a new Redis instance for cleanup
const redis = new Redis();
await redis.flushall();
redis.disconnect();
});