Skip to content

Commit 0f090a7

Browse files
committed
test: coverage report
1 parent 005031d commit 0f090a7

File tree

5 files changed

+45
-8
lines changed

5 files changed

+45
-8
lines changed

.github/workflows/e2e.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
env:
1010
NODE_VERSION: 18
1111
PNPM_VERSION: 8.5.0
12+
COVERAGE: "true"
1213

1314
jobs:
1415
test:
@@ -36,8 +37,9 @@ jobs:
3637
build: pnpm run build
3738
start: pnpm run start
3839
browser: chrome
39-
env:
40-
COVERAGE: "true"
40+
41+
- name: Run Component Tests with Coverage
42+
run: pnpm test:components:coverage
4143

4244
- name: Upload coverage to Codecov
4345
uses: codecov/codecov-action@v3

.nycrc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
],
88
"exclude": [
99
"cypress/**/*.*",
10-
"**/*.d.ts",
11-
"**/*.cy.tsx",
12-
"**/*.cy.ts"
10+
"**/*.d.ts"
1311
],
1412
"reporter": [
1513
"text",

cypress.config.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,52 @@
11
import { defineConfig } from 'cypress';
2+
import codeCoverageTask from '@cypress/code-coverage/task.js';
3+
import { execSync } from 'child_process';
24

35
export default defineConfig({
46
env: {
57
codeCoverage: {
68
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',
714
},
815
},
916
watchForFileChanges: false,
1017
component: {
18+
specPattern: '**/DatabaseWithFilter.cy.tsx',
1119
devServer: {
1220
framework: 'react',
1321
bundler: 'vite',
1422
},
1523
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+
});
1650
return config;
1751
},
1852
supportFile: 'cypress/support/component.ts',

cypress/support/component.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
// You can read more here:
1313
// https://on.cypress.io/configuration
1414
// ***********************************************************
15-
import { addMatchImageSnapshotCommand } from 'cypress-image-snapshot/command';
16-
import 'cypress-real-events';
1715

18-
// Import commands.js using ES2015 syntax:
16+
// Import code coverage support first
1917
import '@cypress/code-coverage/support';
18+
19+
import { addMatchImageSnapshotCommand } from 'cypress-image-snapshot/command';
20+
import 'cypress-real-events';
2021
import 'cypress-real-events/support';
2122
import './commands';
2223
import './document';

vite.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ export default defineConfig({
8181
'cypress/**/*',
8282
'node_modules/**/*',
8383
],
84+
extension: ['.js', '.jsx', '.ts', '.tsx'],
85+
checkProd: false,
8486
}) : undefined,
8587
process.env.ANALYZE_MODE
8688
? visualizer({

0 commit comments

Comments
 (0)