Skip to content

Commit 331a83e

Browse files
committed
ci(design-system): add test coverage reporting with Istanbul
1 parent 393cf6d commit 331a83e

File tree

6 files changed

+153
-3
lines changed

6 files changed

+153
-3
lines changed

.github/workflows/pr.yml

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ jobs:
124124

125125
permissions:
126126
contents: read
127+
pull-requests: write
127128

128129
steps:
129130
- name: Checkout source code
@@ -155,8 +156,38 @@ jobs:
155156
restore-keys: |
156157
${{ runner.os }}-turbo-test-
157158
158-
- name: Run Tests
159-
run: pnpm test --affected
159+
- name: Run Tests with Coverage
160+
run: pnpm --filter @drivenets/design-system test:coverage
161+
162+
- name: Upload Coverage Report
163+
uses: actions/upload-artifact@ea05b972c4286d9363af3d338d0c4c61a0dc8f96 # v4.6.2
164+
if: always()
165+
with:
166+
name: coverage-report
167+
path: packages/design-system/coverage/
168+
retention-days: 30
169+
170+
- name: Coverage Summary
171+
if: always()
172+
run: |
173+
if [ -f packages/design-system/coverage/coverage-summary.json ]; then
174+
echo "## 📊 Coverage Summary" >> $GITHUB_STEP_SUMMARY
175+
echo "" >> $GITHUB_STEP_SUMMARY
176+
echo "| Metric | Coverage |" >> $GITHUB_STEP_SUMMARY
177+
echo "|--------|----------|" >> $GITHUB_STEP_SUMMARY
178+
echo "| Statements | $(jq -r '.total.statements.pct' packages/design-system/coverage/coverage-summary.json)% |" >> $GITHUB_STEP_SUMMARY
179+
echo "| Branches | $(jq -r '.total.branches.pct' packages/design-system/coverage/coverage-summary.json)% |" >> $GITHUB_STEP_SUMMARY
180+
echo "| Functions | $(jq -r '.total.functions.pct' packages/design-system/coverage/coverage-summary.json)% |" >> $GITHUB_STEP_SUMMARY
181+
echo "| Lines | $(jq -r '.total.lines.pct' packages/design-system/coverage/coverage-summary.json)% |" >> $GITHUB_STEP_SUMMARY
182+
fi
183+
184+
- name: Coverage PR Comment
185+
uses: davelosert/vitest-coverage-report-action@3bb15bf7db10acbe97dbd47ceeaeb7f59b964a68 # v2.8.0
186+
if: github.event_name == 'pull_request'
187+
with:
188+
working-directory: packages/design-system
189+
json-summary-path: coverage/coverage-summary.json
190+
json-final-path: coverage/coverage-final.json
160191

161192
build:
162193
name: Build

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
node_modules
22
dist
3+
coverage
34

45
*.log
56

packages/design-system/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"generate-scss-dts": "typed-scss-modules ./src -o ./.scss-dts --nameFormat all --exportType default > /dev/null 2>&1",
4242
"storybook": "storybook dev -p 6006",
4343
"test": "vitest",
44+
"test:coverage": "vitest --coverage --run",
4445
"build": "tsdown",
4546
"build:storybook": "storybook build",
4647
"build:lint": "publint && attw --pack"
@@ -90,6 +91,7 @@
9091
"@types/react-dom": "^19.2.3",
9192
"@vitest/browser": "^4.0.16",
9293
"@vitest/browser-playwright": "^4.0.15",
94+
"@vitest/coverage-istanbul": "^4.0.17",
9395
"babel-plugin-react-compiler": "^1.0.0",
9496
"eslint": "^9.39.2",
9597
"eslint-plugin-jsx-a11y": "^6.10.2",

packages/design-system/vite.config.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,27 @@ const dirname = typeof __dirname !== 'undefined' ? __dirname : path.dirname(file
99

1010
export default defineConfig({
1111
test: {
12+
coverage: {
13+
provider: 'istanbul',
14+
reporter: ['text', 'html', 'lcov', 'json-summary'],
15+
reportsDirectory: './coverage',
16+
include: ['src/components/**/*.{ts,tsx}'],
17+
exclude: [
18+
'**/*.stories.tsx',
19+
'**/*.stories.ts',
20+
'**/*.test.ts',
21+
'**/*.test.tsx',
22+
'**/stories/**',
23+
'**/*.types.ts',
24+
'**/index.ts',
25+
],
26+
thresholds: {
27+
statements: 70,
28+
branches: 70,
29+
functions: 70,
30+
lines: 70,
31+
},
32+
},
1233
projects: [
1334
{
1435
extends: true,

pnpm-lock.yaml

Lines changed: 92 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

turbo.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
"test": {
2020
"dependsOn": []
2121
},
22+
"test:coverage": {
23+
"dependsOn": [],
24+
"outputs": ["coverage/**"]
25+
},
2226
"build": {
2327
"outputs": ["dist/**"],
2428
"dependsOn": ["^build"]

0 commit comments

Comments
 (0)