|
| 1 | +const compileModules = [ |
| 2 | + '@rc-component', |
| 3 | + 'react-sticky-box', |
| 4 | + 'rc-tween-one', |
| 5 | + '@babel', |
| 6 | + '@ant-design', |
| 7 | + 'countup.js', |
| 8 | + '.pnpm', |
| 9 | +]; |
| 10 | + |
| 11 | +const resolve = (p) => require.resolve(`@ant-design/tools/lib/jest/${p}`); |
| 12 | + |
| 13 | +const ignoreList = []; |
| 14 | + |
| 15 | +// cnpm use `_` as prefix |
| 16 | +['', '_'].forEach((prefix) => { |
| 17 | + compileModules.forEach((module) => { |
| 18 | + ignoreList.push(`${prefix}${module}`); |
| 19 | + }); |
| 20 | +}); |
| 21 | + |
| 22 | +const transformIgnorePatterns = [ |
| 23 | + // Ignore modules without es dir. |
| 24 | + // Update: @babel/runtime should also be transformed |
| 25 | + `[/\\\\]node_modules[/\\\\](?!${ignoreList.join('|')})[^/\\\\]+?[/\\\\](?!(es)[/\\\\])`, |
| 26 | +]; |
| 27 | + |
| 28 | +function getTestRegex(libDir) { |
| 29 | + if (['dist', 'lib', 'es', 'dist-min'].includes(libDir)) { |
| 30 | + return 'demo\\.test\\.(j|t)sx?$'; |
| 31 | + } |
| 32 | + return '.*\\.test\\.(j|t)sx?$'; |
| 33 | +} |
| 34 | + |
| 35 | +module.exports = { |
| 36 | + verbose: true, |
| 37 | + testEnvironment: '@happy-dom/jest-environment', |
| 38 | + setupFiles: ['./tests/setup.ts'], |
| 39 | + setupFilesAfterEnv: ['@testing-library/jest-dom'], |
| 40 | + moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'md'], |
| 41 | + modulePathIgnorePatterns: [], |
| 42 | + moduleNameMapper: { |
| 43 | + '\\.(css|less)$': 'identity-obj-proxy', |
| 44 | + }, |
| 45 | + testPathIgnorePatterns: ['/node_modules/', 'dekko', 'node', 'image.test.js', 'image.test.ts'], |
| 46 | + transform: { |
| 47 | + '\\.tsx?$': resolve('codePreprocessor'), |
| 48 | + '\\.(m?)js$': resolve('codePreprocessor'), |
| 49 | + '\\.md$': resolve('demoPreprocessor'), |
| 50 | + '\\.(jpg|png|gif|svg)$': resolve('imagePreprocessor'), |
| 51 | + }, |
| 52 | + testRegex: getTestRegex(process.env.LIB_DIR), |
| 53 | + collectCoverageFrom: [ |
| 54 | + 'src/**/*.{ts,tsx}', |
| 55 | + '!src/**/*.d.ts', |
| 56 | + '!src/**/demo/**', |
| 57 | + '!src/**/__tests__/**', |
| 58 | + '!src/version.ts', |
| 59 | + '!src/index.ts', // 纯重导出文件 |
| 60 | + '!src/A2UI/types/**', // 纯类型文件 |
| 61 | + ], |
| 62 | + transformIgnorePatterns, |
| 63 | + globals: { |
| 64 | + 'ts-jest': { |
| 65 | + tsConfig: './tsconfig.json', |
| 66 | + }, |
| 67 | + }, |
| 68 | + testEnvironmentOptions: { |
| 69 | + url: 'http://localhost/x-card', |
| 70 | + }, |
| 71 | + bail: true, |
| 72 | + maxWorkers: '50%', |
| 73 | +}; |
0 commit comments