- Convert 17 server spec files from vitest to Jest (vi -> jest globals) - Add jest.mock stubs for ESM-only prosemirror/html and collaboration modules - Fix Zod v4 strict UUID validation failures in test fixtures (version byte [1-8] required) - Add JwtAuthGuard.overrideGuard in all controller specs that lacked it - Fix jest.Mock type inference (ReturnType<typeof jest.fn> -> jest.Mock) to prevent 'never' arg errors - Delete vitest.config.ts (CJS), keep vitest.config.mts (ESM-compatible) on client - Add global mocks for @excalidraw/excalidraw and @/main.tsx in client test-setup - Result: client 38/38 suites 313/313 tests, server acadenice 21/21 suites 210/210 tests, 0 TS errors Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
60 lines
1.8 KiB
TypeScript
60 lines
1.8 KiB
TypeScript
import "@testing-library/jest-dom/vitest";
|
|
import { afterEach, vi } from "vitest";
|
|
import { cleanup } from "@testing-library/react";
|
|
|
|
// @excalidraw/excalidraw bundles roughjs with a broken CJS path in its dev
|
|
// build. Stub the whole package in tests — excalidraw is loaded lazily in
|
|
// production and never needed in unit/integration tests.
|
|
vi.mock("@excalidraw/excalidraw", () => ({
|
|
Excalidraw: () => null,
|
|
exportToBlob: vi.fn(),
|
|
exportToSvg: vi.fn(),
|
|
serializeAsJSON: vi.fn(),
|
|
loadLibraryFromBlob: vi.fn(),
|
|
convertToExcalidrawElements: vi.fn(),
|
|
}));
|
|
|
|
// @/main.tsx mounts the React app on #root which does not exist in jsdom.
|
|
// Any feature module that imports { queryClient } from "@/main.tsx" would
|
|
// trigger the mount side-effect — stub it to avoid the crash.
|
|
vi.mock("@/main.tsx", () => ({
|
|
queryClient: {
|
|
getQueryData: vi.fn(),
|
|
setQueryData: vi.fn(),
|
|
invalidateQueries: vi.fn(),
|
|
prefetchQuery: vi.fn(),
|
|
fetchQuery: vi.fn(),
|
|
clear: vi.fn(),
|
|
},
|
|
}));
|
|
|
|
afterEach(() => {
|
|
cleanup();
|
|
});
|
|
|
|
// Stubs for browser APIs Mantine relies on but jsdom does not provide.
|
|
if (typeof Element !== "undefined" && !Element.prototype.scrollIntoView) {
|
|
Element.prototype.scrollIntoView = function () {};
|
|
}
|
|
|
|
if (typeof window !== "undefined") {
|
|
if (!window.matchMedia) {
|
|
window.matchMedia = vi.fn().mockImplementation((query: string) => ({
|
|
matches: false,
|
|
media: query,
|
|
onchange: null,
|
|
addEventListener: vi.fn(),
|
|
removeEventListener: vi.fn(),
|
|
addListener: vi.fn(),
|
|
removeListener: vi.fn(),
|
|
dispatchEvent: vi.fn(),
|
|
}));
|
|
}
|
|
if (!(window as unknown as { ResizeObserver?: unknown }).ResizeObserver) {
|
|
(window as unknown as { ResizeObserver: unknown }).ResizeObserver = class {
|
|
observe() {}
|
|
unobserve() {}
|
|
disconnect() {}
|
|
};
|
|
}
|
|
}
|