|
1 | 1 | import { defineConfig } from 'cypress'; |
| 2 | +import codeCoverageTask from '@cypress/code-coverage/task.js'; |
| 3 | +import { execSync } from 'child_process'; |
2 | 4 |
|
3 | 5 | export default defineConfig({ |
4 | 6 | env: { |
5 | 7 | codeCoverage: { |
6 | 8 | exclude: ['cypress/**/*.*', '**/__tests__/**/*.*', '**/*.test.*'], |
| 9 | + reportDir: 'coverage/cypress', |
| 10 | + all: true, |
| 11 | + include: ['src/**/*.ts', 'src/**/*.tsx'], |
| 12 | + reporter: ['text', 'html', 'text-summary', 'json', 'lcov'], |
| 13 | + tempDir: 'coverage/.nyc_output', |
7 | 14 | }, |
8 | 15 | }, |
9 | 16 | watchForFileChanges: false, |
10 | 17 | component: { |
| 18 | + specPattern: '**/DatabaseWithFilter.cy.tsx', |
11 | 19 | devServer: { |
12 | 20 | framework: 'react', |
13 | 21 | bundler: 'vite', |
14 | 22 | }, |
15 | 23 | setupNodeEvents(on, config) { |
| 24 | + codeCoverageTask(on, config); |
| 25 | + |
| 26 | + // 在测试完成后生成报告 |
| 27 | + on('after:run', async () => { |
| 28 | + try { |
| 29 | + // 确保目录存在 |
| 30 | + execSync('mkdir -p coverage/cypress'); |
| 31 | + // 运行 nyc 报告 |
| 32 | + execSync('nyc report --reporter=lcov --reporter=text --reporter=html --report-dir=coverage/cypress', { |
| 33 | + stdio: 'inherit' |
| 34 | + }); |
| 35 | + } catch (error) { |
| 36 | + console.error('Error generating coverage report:', error); |
| 37 | + } |
| 38 | + }); |
| 39 | + |
| 40 | + on('task', { |
| 41 | + log(message) { |
| 42 | + console.log(message); |
| 43 | + return null; |
| 44 | + }, |
| 45 | + table(message) { |
| 46 | + console.table(message); |
| 47 | + return null; |
| 48 | + } |
| 49 | + }); |
16 | 50 | return config; |
17 | 51 | }, |
18 | 52 | supportFile: 'cypress/support/component.ts', |
|
0 commit comments