// @ts-check // eslint-disable-next-line import/no-commonjs const esmPackages = require("./jest.esm-packages.js"); const swcJestTransform = [ "@swc/jest", { jsc: { // Jest runs on Node so we can target a modern engine and skip a bunch // of polyfills/transforms that `env.targets: ["defaults"]` would emit. target: "es2022", loose: true, parser: { syntax: "typescript", tsx: true, }, transform: { react: { runtime: "automatic", }, }, experimental: { plugins: [ ["@swc-contrib/mut-cjs-exports", {}], ["@swc/plugin-emotion", { sourceMap: false }], ], }, }, module: { type: "commonjs", // A test file loads only the modules its tests touch, not its full import // graph. Modules that must run before the tests start are listed in // frontend/test/jest-setup-eager.js. lazy: true, }, sourceMaps: "inline", minify: false, }, ]; const baseConfig = { transform: { "^.+\\.m?[jt]sx?$": swcJestTransform, }, moduleNameMapper: { // Force jose to use Node.js runtime instead of browser runtime in jsdom environment. // The browser runtime expects CryptoKey to be globally available, which jsdom doesn't provide. "^jose$": "/node_modules/jose/dist/node/cjs/index.js", // remend only declares an `import` export condition, so jest's CJS resolver can't find it. "^remend$": "/node_modules/remend/dist/index.js", "^build-configs/(.*)$": "/frontend/build/$1", "\\.(css|less)$": "/frontend/test/__mocks__/styleMock.js", "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)(\\?url)?$": "/frontend/test/__mocks__/fileMock.js", "^cljs/(.*)$": "/target/cljs_dev/$1", // The real catalogues are a build artifact, so tests resolve a small fixture // per locale instead. "^locales/(.*)\\.json$": "/frontend/test/__mocks__/locales/$1.json", "\\.svg\\?(component|source)": "/frontend/test/__mocks__/svgMock.tsx", "csv-parse/browser/esm/sync": "/node_modules/csv-parse/dist/cjs/sync", "csv-stringify/browser/esm/sync": "/node_modules/csv-stringify/dist/cjs/sync", /** * SDK components import root SDK folder (`embedding-sdk`) that contains the ee plugins. * This isn't a problem in the core app because we seem to not import to entry file directly * for any component under tests. */ "sdk-ee-plugins": "/frontend/src/metabase/plugins/noop.ts", /** * SDK iframe embedding imports the embedding sdk and its components. * We want to exclude the SDK from the main app's bundle to reduce the bundle size. */ "sdk-iframe-embedding-ee-plugins": "/frontend/src/metabase/utils/noop.ts", "ee-plugins": "/frontend/src/metabase/utils/noop.ts", "ee-overrides": "/frontend/src/metabase/utils/noop.ts", /** * Docs snippets are loaded as raw text (asset/source) in rspack. * In Jest, mock them as plain strings. */ "^docs/embedding/sdk/snippets/(.*)$": "/frontend/test/__mocks__/fileMock.js", "docs/(.*)$": "/docs/$1", }, transformIgnorePatterns: [ // Combined pattern for both flat and bun isolated node_modules structures // - Flat: node_modules// where is NOT in esmPackages // - Bun: node_modules/.bun/@/ where is NOT in esmPackages `/node_modules/(?:\\.bun/(?!(${esmPackages.join("|")})@)|(?!\\.bun)(?!(${esmPackages.join("|")})/))`, // CLJS files are already compiled CJS — skip transform entirely "/target/cljs_dev/", ], testPathIgnorePatterns: [ "/frontend/.*/.*.tz.unit.spec.{js,jsx,ts,tsx}", "/release/.*", ], testMatch: ["/**/*.unit.spec.{js,jsx,ts,tsx}"], modulePaths: [ "/frontend/test", "/frontend/src", "/enterprise/frontend/src", ], modulePathIgnorePatterns: [ "/target/cljs_release/.*", "/target/classes/.*", "/resources/frontend_client", "/.*/__mocks__", "/enterprise/frontend/src/custom-viz", ], setupFiles: [ "/frontend/test/jest-setup.js", "/frontend/test/metabase-bootstrap.js", "/frontend/test/register-visualizations.js", ], setupFilesAfterEnv: [ "/frontend/test/jest-setup-eager.js", "/frontend/test/jest-setup-env.js", ], globals: { ga: {}, }, coverageDirectory: "./coverage", collectCoverageFrom: [ "frontend/src/**/*.{js,jsx,ts,tsx}", "enterprise/frontend/src/**/*.{js,jsx,ts,tsx}", "!/**/*.styled.{js,jsx,ts,tsx}", "!/**/*.story.{js,jsx,ts,tsx}", "!/**/*.info.{js,jsx,ts,tsx}", "!/**/*.unit.spec.{js,jsx,ts,tsx}", ], coveragePathIgnorePatterns: [ "/node_modules/", "/target/cljs_dev/", "/target/cljs_release/", "/frontend/test/", ], testEnvironment: "jest-environment-jsdom", testRunner: "/frontend/test/jest-test-runner.js", }; // eslint-disable-next-line import/no-commonjs module.exports = baseConfig;