// Resolve via the @nx/jest exports map. A plain Node require (no --conditions) // skips the @nx/nx-source condition, so this lands on the built dist/preset.js // rather than the local TypeScript source. const nxPreset = require('@nx/jest/preset').default; const path = require('path'); // SWC resolves bare plugin names by walking node_modules upward from cwd. // Tests that chdir into temp dirs would fail resolution since the temp dir // has no node_modules. Pre-resolving to an absolute path bypasses this. const mutCjsExportsPlugin = path.dirname( require.resolve('@swc-contrib/mut-cjs-exports/package.json') ); module.exports = { ...nxPreset, testTimeout: 35000, testMatch: ['**/+(*.)+(spec|test).+(ts|js)?(x)'], transform: { '^.+\\.(html)$': 'ts-jest', '^.+\\.[tj]sx?$': [ '@swc/jest', { jsc: { parser: { syntax: 'typescript', dynamicImport: true }, transform: { useDefineForClassFields: false, }, experimental: { plugins: [[mutCjsExportsPlugin, {}]], }, }, module: { type: 'commonjs' }, }, ], }, resolver: '../../scripts/patched-jest-resolver.js', moduleFileExtensions: ['ts', 'js', 'html'], coverageReporters: ['html'], maxWorkers: 1, testEnvironment: 'node', setupFiles: ['../../scripts/unit-test-setup.js'], moduleNameMapper: { // Mock ora to avoid ESM issues - ora@9+ is ESM-only and breaks Jest '^ora$': '/../../scripts/jest-mocks/ora.js', // Handle both `import * as x` and `import x from` styles for CommonJS modules '^chalk$': '/../../scripts/jest-mocks/chalk.js', '^yargs-parser$': '/../../scripts/jest-mocks/yargs-parser.js', '^prettier$': '/../../scripts/jest-mocks/prettier.js', }, };