2023-04-12 10:47:27 +01:00
|
|
|
/*
|
2024-09-06 15:44:31 +01:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2023-04-12 10:47:27 +01:00
|
|
|
Copyright 2023 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
2025-01-06 11:18:54 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
2024-09-06 15:44:31 +01:00
|
|
|
Please see LICENSE files in the repository root for full details.
|
2023-04-12 10:47:27 +01:00
|
|
|
*/
|
|
|
|
|
|
2026-05-29 08:26:59 +00:00
|
|
|
import { env } from "node:process";
|
|
|
|
|
import path, { dirname } from "node:path";
|
|
|
|
|
import { fileURLToPath } from "node:url";
|
2023-04-12 10:47:27 +01:00
|
|
|
|
|
|
|
|
import type { Config } from "jest";
|
|
|
|
|
|
2026-05-29 08:26:59 +00:00
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
|
|
|
|
2023-04-12 10:47:27 +01:00
|
|
|
const config: Config = {
|
2026-01-15 09:21:25 +00:00
|
|
|
testEnvironment: "jest-fixed-jsdom",
|
2023-04-12 10:47:27 +01:00
|
|
|
testEnvironmentOptions: {
|
|
|
|
|
url: "http://localhost/",
|
2024-12-23 18:06:52 +00:00
|
|
|
// This is needed to be able to load dual CJS/ESM WASM packages e.g. rust crypto & matrix-wywiwyg
|
|
|
|
|
customExportConditions: ["browser", "node"],
|
2023-04-12 10:47:27 +01:00
|
|
|
},
|
2026-03-05 21:42:08 +00:00
|
|
|
transform: {
|
|
|
|
|
"\\.[jt]sx?$": "babel-jest",
|
|
|
|
|
},
|
2025-11-03 16:26:47 +00:00
|
|
|
testMatch: ["<rootDir>/test/**/*-test.[tj]s?(x)"],
|
2023-08-09 09:39:48 +01:00
|
|
|
globalSetup: "<rootDir>/test/globalSetup.ts",
|
2024-07-05 02:08:06 +08:00
|
|
|
setupFiles: ["jest-canvas-mock", "web-streams-polyfill/polyfill"],
|
2023-08-09 09:39:48 +01:00
|
|
|
setupFilesAfterEnv: ["<rootDir>/test/setupTests.ts"],
|
2023-04-12 10:47:27 +01:00
|
|
|
moduleNameMapper: {
|
2025-07-22 18:25:45 +02:00
|
|
|
// Support CSS module
|
|
|
|
|
"\\.(module.css)$": "identity-obj-proxy",
|
2026-06-18 10:36:07 +01:00
|
|
|
"\\.(css|scss|pcss)(\\?raw)?$": "<rootDir>/__mocks__/cssMock.js",
|
2023-04-12 10:47:39 +01:00
|
|
|
"\\.(gif|png|ttf|woff2)$": "<rootDir>/__mocks__/imageMock.js",
|
|
|
|
|
"\\.svg$": "<rootDir>/__mocks__/svg.js",
|
2026-06-04 12:55:25 +01:00
|
|
|
"^matrix-js-sdk(.*)$": "<rootDir>/node_modules/matrix-js-sdk$1",
|
2026-05-29 08:26:59 +00:00
|
|
|
"^react$": "<rootDir>/node_modules/react",
|
|
|
|
|
"^react-dom$": "<rootDir>/node_modules/react-dom",
|
2023-04-12 10:47:39 +01:00
|
|
|
"decoderWorker\\.min\\.js": "<rootDir>/__mocks__/empty.js",
|
|
|
|
|
"decoderWorker\\.min\\.wasm": "<rootDir>/__mocks__/empty.js",
|
|
|
|
|
"waveWorker\\.min\\.js": "<rootDir>/__mocks__/empty.js",
|
2024-10-15 14:57:26 +01:00
|
|
|
"context-filter-polyfill": "<rootDir>/__mocks__/empty.js",
|
2026-06-19 16:34:18 +01:00
|
|
|
"workers/(.+)Factory": "<rootDir>/__mocks__/workerFactoryMock-jest.js",
|
2026-06-18 10:36:07 +01:00
|
|
|
".*\\?raw": "jest-raw-loader",
|
2023-11-13 19:52:15 +01:00
|
|
|
"recorderWorkletFactory": "<rootDir>/__mocks__/empty.js",
|
2026-05-29 08:26:59 +00:00
|
|
|
"@vector-im/compound-web": "<rootDir>/node_modules/@vector-im/compound-web",
|
2026-06-19 16:34:18 +01:00
|
|
|
"^vitest$": "<rootDir>/__mocks__/empty.js",
|
|
|
|
|
"jest-mock-vitest-adapter": "<rootDir>/test/setup/adapter.ts",
|
|
|
|
|
"test-utils-rtl": "<rootDir>/test/test-utils/jest-matrix-react.tsx",
|
2023-04-12 10:47:27 +01:00
|
|
|
},
|
2025-10-01 11:03:43 +02:00
|
|
|
transformIgnorePatterns: [
|
2026-07-15 09:41:41 +01:00
|
|
|
`${path.join(__dirname, "../..")}/node_modules/.pnpm/(?!(matrix-js-sdk|htmlparser2|mime|uuid|p-retry|is-network-error|react-merge-refs|is-ip|ip-regex|super-regex|function-timeout|time-span|convert-hrtime|clone-regexp|is-regexp|matrix-web-i18n|await-lock|@element-hq/web-shared-components|react-virtuoso|lodash|domutils|domhandler|domelementtype|dom-serializer|entities)).+$`,
|
2025-10-01 11:03:43 +02:00
|
|
|
],
|
2023-08-22 15:10:47 +01:00
|
|
|
collectCoverageFrom: [
|
|
|
|
|
"<rootDir>/src/**/*.{js,ts,tsx}",
|
|
|
|
|
// getSessionLock is piped into a different JS context via stringification, and the coverage functionality is
|
|
|
|
|
// not available in that contest. So, turn off coverage instrumentation for it.
|
|
|
|
|
"!<rootDir>/src/utils/SessionLock.ts",
|
2024-10-21 14:40:49 +01:00
|
|
|
// Coverage chokes on type definition files
|
|
|
|
|
"!<rootDir>/src/**/*.d.ts",
|
2026-06-15 14:24:33 +01:00
|
|
|
// Ignore vitest tests
|
|
|
|
|
"!<rootDir>/src/**/*.test.{ts,tsx}",
|
|
|
|
|
"!<rootDir>/src/test/**",
|
2026-07-07 21:57:26 +05:30
|
|
|
// Exclude mocks
|
|
|
|
|
"!<rootDir>/src/**/*-{mock,mocks}.{ts,tsx}",
|
2023-08-22 15:10:47 +01:00
|
|
|
],
|
2026-06-11 15:01:32 +02:00
|
|
|
coverageReporters: ["text-summary", ["lcov", { projectRoot: "../../" }]],
|
2024-02-07 12:26:05 -05:00
|
|
|
prettierPath: null,
|
2024-10-14 21:41:58 +05:30
|
|
|
moduleDirectories: ["node_modules", "test/test-utils"],
|
2026-06-15 14:24:33 +01:00
|
|
|
workerIdleMemoryLimit: "512MB",
|
2023-04-12 10:47:27 +01:00
|
|
|
};
|
|
|
|
|
|
2026-02-27 15:05:47 +01:00
|
|
|
// if we're running under GHA, enable relevant reporters
|
2023-04-12 10:47:27 +01:00
|
|
|
if (env["GITHUB_ACTIONS"] !== undefined) {
|
2026-02-27 15:05:47 +01:00
|
|
|
config.reporters ??= [];
|
|
|
|
|
config.reporters.push(["github-actions", { silent: false }]);
|
|
|
|
|
config.reporters.push("summary");
|
2023-04-12 10:47:39 +01:00
|
|
|
|
|
|
|
|
// if we're running against the develop branch, also enable the slow test reporter
|
|
|
|
|
if (env["GITHUB_REF"] == "refs/heads/develop") {
|
2026-02-27 15:05:47 +01:00
|
|
|
config.reporters.push("<rootDir>/test/slowReporter.cjs");
|
2023-04-12 10:47:39 +01:00
|
|
|
}
|
2023-04-12 10:47:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default config;
|