mirror of
https://github.com/outline/outline.git
synced 2026-06-13 03:14:59 +03:00
091346dfe8
* wip * Remove obsolete snapshots * simplify * chore(test): Convert mocks to TypeScript and tighten fetch mock types Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * Remove unneccessary patches * Migrate to msw instead of custom fetch mock * Address PR review comments - Split chained vi.useFakeTimers().setSystemTime() into separate calls. - Switch test setup to dynamic imports so EventEmitter.defaultMaxListeners assignment runs before module init (static imports were hoisted above it). - Drop redundant NODE_ENV guard in monkeyPatchSequelizeErrorsForJest; its sole caller already gates on env.isTest. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
57 lines
2.0 KiB
TypeScript
57 lines
2.0 KiB
TypeScript
// This file runs before the test environment is set up to ensure mocks are registered early.
|
|
// It prevents real Redis clients from being initialized during module imports.
|
|
|
|
import { vi } from "vitest";
|
|
import type * as IORedisMock from "ioredis-mock";
|
|
import { __setRequireDirectoryCache } from "@server/utils/fs";
|
|
|
|
// Pre-populate the requireDirectory cache used by @server/utils/fs so that
|
|
// tasks/processors/email-templates can be looked up via their pre-loaded
|
|
// modules instead of via Node's require(), which cannot resolve TypeScript
|
|
// files with aliased imports under Vitest. The eager globs intentionally
|
|
// exclude index.ts files (which call requireDirectory themselves and would
|
|
// recurse) and any files whose imports would themselves load the directory
|
|
// they live in.
|
|
__setRequireDirectoryCache(
|
|
"emails/templates",
|
|
import.meta.glob("../emails/templates/!(index|*.test).{js,ts}", {
|
|
eager: true,
|
|
})
|
|
);
|
|
__setRequireDirectoryCache(
|
|
"queues/processors",
|
|
import.meta.glob("../queues/processors/!(index|*.test).{js,ts}", {
|
|
eager: true,
|
|
})
|
|
);
|
|
__setRequireDirectoryCache(
|
|
"queues/tasks",
|
|
import.meta.glob("../queues/tasks/!(index|*.test).{js,ts}", {
|
|
eager: true,
|
|
})
|
|
);
|
|
|
|
vi.mock("ioredis", async () => {
|
|
const mod = await vi.importActual<typeof IORedisMock>("ioredis-mock");
|
|
return mod;
|
|
});
|
|
|
|
vi.mock("@server/utils/MutexLock");
|
|
|
|
vi.mock("@aws-sdk/signature-v4-crt", () => ({}));
|
|
|
|
// Auto-mock these modules using the corresponding files under server/__mocks__/.
|
|
// In Jest, __mocks__ next to a `roots` directory is auto-applied; vitest
|
|
// requires an explicit vi.mock() call to wire them up.
|
|
vi.mock("bull", () => import("../__mocks__/bull"));
|
|
vi.mock("dd-trace", async () => {
|
|
const mod = await import("../__mocks__/dd-trace");
|
|
return { default: mod.mockTracer, ...mod };
|
|
});
|
|
vi.mock("franc", () => import("../__mocks__/franc"));
|
|
vi.mock("iso-639-3", () => import("../__mocks__/iso-639-3"));
|
|
vi.mock(
|
|
"request-filtering-agent",
|
|
() => import("../__mocks__/request-filtering-agent")
|
|
);
|