Files
novalon-website/config/test/jest.config.js
T
zhangxiang a022a612c5 test(seo): expand structured data tests to cover all 7 schema components
- Add 24 new tests for ServiceSchema, ProductSchema, FAQSchema,
  BreadcrumbSchema, and LocalBusinessSchema (previously uncovered)
- Raise SEO component coverage from 40.89% → 100% (all metrics)
- Update jest.config.js coverage thresholds to reflect Phase 7实测 values
- Sync test-strategy-plan.md to v1.8 with latest coverage data
- Update README.md progress with 1509 tests / 73.59% stmts / 82.38% branches
2026-08-02 13:36:28 +08:00

124 lines
3.4 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__/**',
],
// 覆盖率阈值采用渐进提升策略:基于 Phase 7 实测值设定目录级阈值,避免全局平均掩盖核心模块缺口
// 实测基准 (Phase 7 — 2026-08-02): global(72.65% stmts/82.20% branches/73.56% funcs),
// ui(63.91%/76.52%), layout(71.02%/76.92%), detail(74.20%/75.96%), sections(43.24%/78.09%),
// seo(100%/100%), content(56.15%/100%), analytics(已覆盖全部 7 组件),
// lib(95.96%/89.60%), lib/cms(91.22%/90.90%), lib/constants(98.78%/91.89%)
coverageThreshold: {
global: {
branches: 70,
functions: 55,
lines: 55,
statements: 55,
},
'./src/hooks/': {
branches: 38,
functions: 60,
lines: 60,
statements: 60,
},
'./src/lib/': {
branches: 40,
functions: 45,
lines: 42,
statements: 42,
},
'./src/components/ui/': {
branches: 45,
functions: 55,
lines: 35,
statements: 35,
},
'./src/components/layout/': {
branches: 60,
functions: 35,
lines: 60,
statements: 60,
},
'./src/components/detail/': {
branches: 60,
functions: 45,
lines: 60,
statements: 60,
},
'./src/components/sections/': {
branches: 60,
functions: 30,
lines: 35,
statements: 35,
},
'./src/components/content/': {
branches: 80,
functions: 40,
lines: 45,
statements: 45,
},
'./src/components/analytics/': {
branches: 30,
functions: 40,
lines: 35,
statements: 35,
},
'./src/components/seo/': {
branches: 80,
functions: 80,
lines: 80,
statements: 80,
},
'./src/lib/cms/': {
branches: 80,
functions: 75,
lines: 60,
statements: 65,
},
'./src/lib/constants/': {
branches: 88,
functions: 45,
lines: 85,
statements: 85,
},
},
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' } }],
},
transformIgnorePatterns: [
'node_modules/(?!(nanoid|next-auth|@auth|@aws-sdk)/)',
],
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
testTimeout: 10000,
verbose: true,
maxWorkers: '50%',
};