2
0

vitest.config.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import { defineConfig } from 'vitest/config'
  2. import { resolve } from 'path'
  3. export default defineConfig({
  4. test: {
  5. projects: [
  6. // Node.js 环境项目 - 后端测试
  7. {
  8. test: {
  9. // 共享配置
  10. globals: true,
  11. name: 'node',
  12. environment: 'node',
  13. include: [
  14. 'tests/unit/server/**/*.test.{ts,js}',
  15. 'tests/integration/server/**/*.test.{ts,js}'
  16. ],
  17. exclude: [
  18. '**/node_modules/**',
  19. '**/dist/**',
  20. '**/build/**',
  21. '**/coverage/**',
  22. 'tests/e2e/**'
  23. ],
  24. alias: {
  25. '~': resolve(__dirname, './tests'),
  26. '@': resolve(__dirname, './src'),
  27. }
  28. }
  29. },
  30. // Happy DOM 环境项目 - 前端组件测试
  31. {
  32. test: {
  33. // 全局设置
  34. globals: true,
  35. name: 'happy-dom',
  36. environment: 'happy-dom',
  37. include: [
  38. 'tests/unit/client/**/*.test.{ts,js,tsx,jsx}',
  39. 'tests/integration/client/**/*.test.{ts,js,tsx,jsx}'
  40. ],
  41. exclude: [
  42. '**/node_modules/**',
  43. '**/dist/**',
  44. '**/build/**',
  45. '**/coverage/**',
  46. 'tests/e2e/**',
  47. 'src/client/home/**',
  48. 'src/client/components/ui/**',
  49. 'src/client/__test_utils__/**',
  50. ],
  51. alias: {
  52. '~': resolve(__dirname, './tests'),
  53. '@': resolve(__dirname, './src'),
  54. },
  55. },
  56. }
  57. ],
  58. testTimeout: 10000,
  59. setupFiles: ['./tests/utils/setup.ts'],
  60. // 覆盖率配置 - 放在根级别
  61. coverage: {
  62. provider: 'v8',
  63. reporter: ['text', 'lcov', 'html'],
  64. reportsDirectory: './coverage',
  65. exclude: [
  66. '**/node_modules/**',
  67. '**/dist/**',
  68. '**/build/**',
  69. '**/coverage/**',
  70. '**/*.d.ts',
  71. 'tests/e2e/**',
  72. 'scripts/**',
  73. 'src/test/**',
  74. '**/__tests__/**',
  75. '**/__mocks__/**',
  76. '**/index.ts',
  77. '**/types.ts',
  78. 'vitest.config.ts',
  79. 'vitest.config.components.ts',
  80. 'vite.config.ts',
  81. 'server.js',
  82. 'eslint.config.js',
  83. 'debug-page.js',
  84. 'src/server/__test_utils__/**',
  85. 'src/client/__test_utils__/**',
  86. ],
  87. thresholds: {
  88. branches: 65,
  89. functions: 65,
  90. lines: 65,
  91. statements: 65
  92. }
  93. },
  94. // api测试关闭并行测试
  95. fileParallelism: false
  96. },
  97. })