mirror of
https://github.com/outline/outline.git
synced 2026-06-13 11:25:03 +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>
113 lines
3.1 KiB
TypeScript
113 lines
3.1 KiB
TypeScript
import path from "node:path";
|
|
import babel from "vite-plugin-babel";
|
|
import { defineConfig } from "vitest/config";
|
|
|
|
const aliases = {
|
|
"@server": path.resolve(__dirname, "./server"),
|
|
"@shared": path.resolve(__dirname, "./shared"),
|
|
"~": path.resolve(__dirname, "./app"),
|
|
plugins: path.resolve(__dirname, "./plugins"),
|
|
};
|
|
|
|
const fileMock = path.resolve(__dirname, "./__mocks__/fileMock.js");
|
|
|
|
const babelPlugin = () =>
|
|
babel({
|
|
filter: /\.(t|j)sx?$/,
|
|
babelConfig: {
|
|
babelrc: false,
|
|
configFile: false,
|
|
sourceMaps: "inline",
|
|
presets: [
|
|
["@babel/preset-react", { runtime: "automatic" }],
|
|
["@babel/preset-typescript", { allowDeclareFields: true }],
|
|
],
|
|
plugins: [
|
|
"babel-plugin-transform-typescript-metadata",
|
|
["@babel/plugin-proposal-decorators", { legacy: true }],
|
|
"@babel/plugin-transform-class-properties",
|
|
],
|
|
},
|
|
});
|
|
|
|
const sharedConfig = {
|
|
resolve: { alias: aliases },
|
|
plugins: [babelPlugin()],
|
|
esbuild: false as const,
|
|
oxc: false as const,
|
|
};
|
|
|
|
const aliasesAsArray = Object.entries(aliases).map(([find, replacement]) => ({
|
|
find,
|
|
replacement,
|
|
}));
|
|
|
|
const fileMockAlias = { find: /\.(gif|ttf|eot|svg)$/, replacement: fileMock };
|
|
|
|
export default defineConfig({
|
|
...sharedConfig,
|
|
test: {
|
|
globals: true,
|
|
pool: "threads",
|
|
// Match Jest's default behavior — unhandled promise rejections are
|
|
// logged but don't fail tests on their own.
|
|
dangerouslyIgnoreUnhandledErrors: true,
|
|
projects: [
|
|
{
|
|
...sharedConfig,
|
|
test: {
|
|
name: "server",
|
|
globals: true,
|
|
environment: "node",
|
|
include: ["server/**/*.test.{ts,tsx}", "plugins/**/*.test.{ts,tsx}"],
|
|
setupFiles: [
|
|
"./__mocks__/console.js",
|
|
"./server/test/setupMocks.ts",
|
|
"./server/test/setup.ts",
|
|
],
|
|
globalSetup: ["./server/test/globalTeardown.ts"],
|
|
fileParallelism: true,
|
|
},
|
|
},
|
|
{
|
|
...sharedConfig,
|
|
resolve: { alias: [fileMockAlias, ...aliasesAsArray] },
|
|
test: {
|
|
name: "app",
|
|
globals: true,
|
|
environment: "jsdom",
|
|
environmentOptions: {
|
|
jsdom: { url: "http://localhost" },
|
|
},
|
|
include: ["app/**/*.test.{ts,tsx}"],
|
|
setupFiles: ["./__mocks__/window.js", "./app/test/setup.ts"],
|
|
},
|
|
},
|
|
{
|
|
...sharedConfig,
|
|
test: {
|
|
name: "shared-node",
|
|
globals: true,
|
|
environment: "node",
|
|
include: ["shared/**/*.test.{ts,tsx}"],
|
|
setupFiles: ["./__mocks__/console.js", "./shared/test/setup.ts"],
|
|
},
|
|
},
|
|
{
|
|
...sharedConfig,
|
|
resolve: { alias: [fileMockAlias, ...aliasesAsArray] },
|
|
test: {
|
|
name: "shared-jsdom",
|
|
globals: true,
|
|
environment: "jsdom",
|
|
environmentOptions: {
|
|
jsdom: { url: "http://localhost" },
|
|
},
|
|
include: ["shared/**/*.test.{ts,tsx}"],
|
|
setupFiles: ["./__mocks__/window.js"],
|
|
},
|
|
},
|
|
],
|
|
},
|
|
});
|