- e2e:修死选择器与蜜罐误命中、补断言、GA4/security-headers 用例诚实标注 skip 边界;新增 assert-helpers/fixtures/hydrated/primary-nav/touch-targets 等复用桩。 - 集成层:config/test/jest.integration.config.js + tests-integration/ 真库 一次性 SQLite 用例,teardown 守卫开发库指纹。 - 门禁工具链:jest.setup 归位到根、scripts/accessibility 全站 axe 节点计数、 check-brand-text-token/check-motion-constraints 机械守卫、stryker/lighthouse 配置收敛。
132 lines
4.3 KiB
JavaScript
132 lines
4.3 KiB
JavaScript
// @ts-nocheck
|
||
const path = require('path');
|
||
|
||
module.exports = {
|
||
preset: 'ts-jest',
|
||
testEnvironment: 'jsdom',
|
||
rootDir: path.resolve(__dirname, '../..'),
|
||
roots: ['<rootDir>/src'],
|
||
testMatch: ['**/__tests__/**/*.test.{ts,tsx}', '**/*.test.{ts,tsx}'],
|
||
// 仅收集实际可单元测试的目录的覆盖率,排除 pages/API routes/admin 等需集成/E2E 测试的代码
|
||
collectCoverageFrom: [
|
||
'src/components/ui/**/*.{ts,tsx}',
|
||
'src/components/layout/**/*.{ts,tsx}',
|
||
'src/components/seo/**/*.{ts,tsx}',
|
||
'src/components/detail/**/*.{ts,tsx}',
|
||
'src/components/sections/**/*.{ts,tsx}',
|
||
'src/components/content/**/*.{ts,tsx}',
|
||
'src/components/analytics/**/*.{ts,tsx}',
|
||
'src/hooks/**/*.{ts,tsx}',
|
||
'src/lib/**/*.ts',
|
||
'!src/**/*.d.ts',
|
||
'!src/**/*.stories.{ts,tsx}',
|
||
'!src/**/__tests__/**',
|
||
],
|
||
// 覆盖率棘轮(验收 A-7):阈值取自实测值下调 3–5 个点,只允许上升。
|
||
// 本文件是阈值的单一真源;根 jest.config.js 仅转发(旧注释曾把路径写成 config/test/ 之外的地方,已纠)。
|
||
// 复测命令:npm run test:coverage(最近一次 2026-09-23,134 suites / 1697 tests,EXIT=0)
|
||
// 实测 global: stmts 85.56 / branch 86.86 / funcs 80.59 / lines 85.56
|
||
// 目录级最近实测:components/content 100/100/100/100 · components/sections 72.77/87.06/73.8/72.77 · lib/cms 91.9/92.63/92.5/91.9
|
||
// ⚠ 口径提示:global 四项实测已比门限高 5.6–10.6 个点,即棘轮当前偏松(低于「实测 −5pp」的本文件自订策略)。
|
||
// 上调是独立动作,须与「哪些目录仍可约束」一起评估,不与功能变更混提。
|
||
coverageThreshold: {
|
||
global: {
|
||
branches: 82,
|
||
functions: 75,
|
||
lines: 75,
|
||
statements: 75,
|
||
},
|
||
'./src/hooks/': {
|
||
branches: 88,
|
||
functions: 85,
|
||
lines: 88,
|
||
statements: 88,
|
||
},
|
||
'./src/lib/': {
|
||
branches: 86,
|
||
functions: 85,
|
||
lines: 92,
|
||
statements: 92,
|
||
},
|
||
'./src/lib/cms/': {
|
||
branches: 86,
|
||
functions: 86,
|
||
lines: 88,
|
||
statements: 88,
|
||
},
|
||
'./src/lib/constants/': {
|
||
branches: 88,
|
||
functions: 55,
|
||
lines: 92,
|
||
statements: 92,
|
||
},
|
||
'./src/components/ui/': {
|
||
branches: 74,
|
||
functions: 76,
|
||
lines: 62,
|
||
statements: 62,
|
||
},
|
||
'./src/components/layout/': {
|
||
branches: 66,
|
||
functions: 46,
|
||
lines: 82,
|
||
statements: 82,
|
||
},
|
||
'./src/components/detail/': {
|
||
branches: 80,
|
||
functions: 42,
|
||
lines: 80,
|
||
statements: 80,
|
||
},
|
||
'./src/components/sections/': {
|
||
branches: 72,
|
||
functions: 50,
|
||
lines: 44,
|
||
statements: 44,
|
||
},
|
||
'./src/components/content/': {
|
||
branches: 95,
|
||
functions: 46,
|
||
lines: 52,
|
||
statements: 52,
|
||
},
|
||
'./src/components/analytics/': {
|
||
branches: 82,
|
||
functions: 86,
|
||
lines: 94,
|
||
statements: 94,
|
||
},
|
||
'./src/components/seo/': {
|
||
branches: 95,
|
||
functions: 95,
|
||
lines: 95,
|
||
statements: 95,
|
||
},
|
||
},
|
||
coverageProvider: 'v8',
|
||
coverageReporters: ['text', 'lcov', 'html', 'json'],
|
||
coverageDirectory: '<rootDir>/coverage',
|
||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
|
||
moduleNameMapper: {
|
||
'^@/(.*)$': '<rootDir>/src/$1',
|
||
},
|
||
transform: {
|
||
// ts-jest 需要明确指定 jsx: 'react-jsx',因为项目 tsconfig 使用 'preserve'
|
||
// 由后续 SWC/Babel 处理,但 Jest 环境下没有这些工具链
|
||
'^.+\\.(ts|tsx)$': ['ts-jest', { tsconfig: { jsx: 'react-jsx' } }],
|
||
// sanitize-html 的解析器链(htmlparser2 v12 起)为 ESM-only,Node 可靠 require(esm) 加载,
|
||
// Jest 的 CJS 运行时不行,须显式转译(作用域限定在这几个包,不影响其余 node_modules)
|
||
'node_modules/(?:htmlparser2|domhandler|domutils|dom-serializer|domelementtype|entities)/.+\\.js$': [
|
||
'ts-jest',
|
||
{ tsconfig: { allowJs: true, checkJs: false, module: 'commonjs', esModuleInterop: true, target: 'es2020' } },
|
||
],
|
||
},
|
||
transformIgnorePatterns: [
|
||
'node_modules/(?!(nanoid|next-auth|@auth|@aws-sdk|htmlparser2|domhandler|domutils|dom-serializer|domelementtype|entities)/)',
|
||
],
|
||
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
|
||
testTimeout: 10000,
|
||
verbose: true,
|
||
maxWorkers: '50%',
|
||
};
|