Skip to content

Commit e1aae85

Browse files
authored
Merge pull request #26 from bartstc/chore/basic-coverage-report
chore: publish coverage report (basic)
2 parents e091004 + 2596a1e commit e1aae85

6 files changed

Lines changed: 307 additions & 29 deletions

File tree

.github/workflows/ci.yml

Lines changed: 127 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
name: CI
2+
23
on:
34
push:
45
branches:
6+
- core
57
- basic
68
pull_request:
79
branches:
10+
- core
811
- basic
912

13+
env:
14+
NODE_VERSION: "22.x"
15+
1016
jobs:
1117
lint-tests:
1218
uses: ./.github/workflows/run-tests.yml
@@ -15,26 +21,81 @@ jobs:
1521
test-command: pnpm lint
1622

1723
unit-tests:
18-
uses: ./.github/workflows/run-tests.yml
19-
with:
20-
test-type: unit
21-
test-command: pnpm test:ci
24+
runs-on: ubuntu-latest
25+
26+
# For every direct push to target branches or when it's active PR
27+
if: ${{ github.event_name == 'push' || !github.event.pull_request.draft }}
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v4
31+
32+
- name: Enable corepack
33+
run: corepack enable
34+
35+
- name: Setup Node.js
36+
uses: actions/setup-node@v4
37+
with:
38+
node-version: ${{ env.NODE_VERSION }}
39+
cache: "pnpm"
40+
41+
- name: Get pnpm store directory
42+
id: pnpm-cache
43+
shell: bash
44+
run: |
45+
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
46+
47+
- name: Setup pnpm cache
48+
uses: actions/cache@v4
49+
with:
50+
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
51+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
52+
restore-keys: |
53+
${{ runner.os }}-pnpm-store-
54+
55+
- name: Install dependencies
56+
run: pnpm install --no-frozen-lockfile --ignore-scripts
57+
58+
- name: Run coverage
59+
run: pnpm test:coverage
60+
61+
- name: Run unit tests
62+
run: pnpm test:ci
63+
64+
- name: Upload test results
65+
if: success() || failure()
66+
uses: actions/upload-artifact@v4
67+
with:
68+
name: unit-test-results
69+
path: reports/**/*
70+
71+
- name: Upload coverage report
72+
if: success() || failure()
73+
uses: actions/upload-artifact@v4
74+
with:
75+
name: unit-coverage-report
76+
path: coverage/**/*
2277

2378
storybook-tests:
2479
runs-on: ubuntu-latest
80+
env:
81+
STORYBOOK_DISABLE_TELEMETRY: 1
82+
STORYBOOK: "true"
83+
CI: true
84+
85+
# For every direct push to target branches or when it's active PR
86+
if: ${{ github.event_name == 'push' || !github.event.pull_request.draft }}
2587
steps:
2688
- name: Checkout
2789
uses: actions/checkout@v4
2890

2991
- name: Enable corepack
3092
run: corepack enable
3193

32-
# https://github.com/storybookjs/test-runner/issues/301
33-
# - name: Install Node.js
34-
# uses: actions/setup-node@v3
35-
# with:
36-
# node-version: "16.x"
37-
# cache: "pnpm"
94+
- name: Setup Node.js
95+
uses: actions/setup-node@v4
96+
with:
97+
node-version: ${{ env.NODE_VERSION }}
98+
cache: "pnpm"
3899

39100
- name: Get pnpm store directory
40101
id: pnpm-cache
@@ -53,8 +114,8 @@ jobs:
53114
- name: Install dependencies
54115
run: pnpm install --no-frozen-lockfile --ignore-scripts
55116

56-
- name: Install Playwright
57-
run: pnpm exec playwright install --with-deps
117+
- name: Install Playwright browsers
118+
run: pnpm exec playwright install chromium --with-deps --only-shell
58119

59120
- name: Build Storybook
60121
run: pnpm build-storybook --quiet
@@ -63,13 +124,21 @@ jobs:
63124
run: |
64125
pnpm exec concurrently -k -s first -n "SB,TEST" -c "magenta,blue" \
65126
"pnpm exec http-server storybook-static --port 6006 --silent" \
66-
"pnpm exec wait-on tcp:127.0.0.1:6006 && pnpm exec test-storybook --json --outputFile storybook-report.json a"
127+
"pnpm exec wait-on tcp:6006 && pnpm exec test-storybook --coverage --coverageDirectory=coverage --excludeTags=\"!test\" --junit --outputFile reports/storybook-report.json"
67128
68-
- name: Upload json report artifacts
129+
- name: Upload test results
130+
if: success() || failure()
69131
uses: actions/upload-artifact@v4
70132
with:
71-
name: storybook-report
72-
path: storybook-report.json
133+
name: storybook-test-results
134+
path: reports/**/*
135+
136+
- name: Upload coverage report
137+
if: success() || failure()
138+
uses: actions/upload-artifact@v4
139+
with:
140+
name: storybook-coverage-report
141+
path: coverage/**/*
73142

74143
build:
75144
needs: [lint-tests, unit-tests, storybook-tests]
@@ -117,8 +186,49 @@ jobs:
117186
name: build
118187
path: dist
119188

189+
test-reports:
190+
needs: [unit-tests, storybook-tests]
191+
runs-on: ubuntu-latest
192+
steps:
193+
- uses: actions/checkout@v4
194+
195+
- name: Download Artifacts
196+
uses: actions/download-artifact@v4
197+
198+
- name: Generate Full Coverage Report
199+
uses: danielpalme/ReportGenerator-GitHub-Action@v5
200+
with:
201+
reports: "unit-coverage-report/lcov.info;storybook-coverage-report/lcov.info"
202+
reporttypes: "MarkdownSummaryGithub;JsonSummary;Html"
203+
targetdir: coverage-report
204+
205+
- name: Add Coverage Report Comment to PR
206+
if: github.event_name == 'pull_request'
207+
run: gh pr comment $PR_NUMBER --body-file coverage-report/SummaryGithub.md
208+
env:
209+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
210+
PR_NUMBER: ${{ github.event.number }}
211+
212+
- name: Publish Coverage Report in Build Summary
213+
run: cat coverage-report/SummaryGithub.md >> $GITHUB_STEP_SUMMARY
214+
215+
- name: Upload Full Coverage Report
216+
uses: actions/upload-artifact@v4
217+
with:
218+
name: full-coverage-report
219+
path: coverage-report/**/*
220+
221+
- name: Publish Test Results
222+
uses: dorny/test-reporter@v2
223+
id: test-reporter
224+
with:
225+
name: Test Results
226+
path: unit-test-results/**/*.xml,storybook-test-results/**/*.xml
227+
reporter: jest-junit
228+
fail-on-error: false
229+
120230
deploy:
121-
needs: build
231+
needs: [build, test-reports]
122232
runs-on: ubuntu-latest
123233
steps:
124234
- name: Get build artifacts

.storybook/main.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { AddonOptionsVite } from "@storybook/addon-coverage";
12
import type { StorybookConfig } from "@storybook/react-vite";
23
import * as tsconfigPaths from "vite-tsconfig-paths";
34

@@ -7,6 +8,15 @@ const config: StorybookConfig = {
78
addons: [
89
"@storybook/addon-links",
910
"@storybook/addon-a11y",
11+
{
12+
name: "@storybook/addon-coverage",
13+
options: {
14+
istanbul: {
15+
include: ["src/**/*.tsx"],
16+
exclude: ["src/**/*.ts", "src/test-lib/*.tsx"],
17+
},
18+
} satisfies AddonOptionsVite,
19+
},
1020
"@storybook/addon-docs",
1121
],
1222

@@ -28,6 +38,12 @@ const config: StorybookConfig = {
2838
typescript: {
2939
reactDocgen: "react-docgen-typescript",
3040
},
41+
42+
build: {
43+
test: {
44+
disabledAddons: ["@storybook/addon-docs"],
45+
},
46+
},
3147
};
3248

3349
export default config;

README.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ This version is free of any libraries. If the `core` version doesn't match your
2424
- TypeScript support.
2525
- [Devcontainer](https://code.visualstudio.com/docs/devcontainers/containers) config for VS Code.
2626
- [PNPM](https://pnpm.io/) as a package manager.
27-
- CI setup (automate tests, build, deploy draft) with [GitHub Actions](https://docs.github.com/en/actions).
27+
- CI setup (tests, build, tests coverage report, deploy draft) with [GitHub Actions](https://docs.github.com/en/actions).
2828
- [Github Copilot](https://github.com/features/copilot) instructions configured for efficient chat and agent usage.
2929

3030
## Extended version - `core`
@@ -91,14 +91,17 @@ Learn more about using this template in practice below.
9191

9292
## Basic commands
9393

94-
| Command | Description |
95-
| ---------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
96-
| `pnpm dev` | Runs dev server with the HMR locally on port `5173` |
97-
| `pnpm build` | Builds optimized app package |
98-
| `pnpm test` | Runs unit tests |
99-
| `pnpm storybook` | Runs a Storybook locally on port `6006` |
100-
| `pnpm test-storybook` | Runs integration tests (requires a running Storybook on port `6006` - more info [here](https://storybook.js.org/blog/interaction-testing-with-storybook/)) |
101-
| `pnpm build-storybook` | Builds static app with [a Storybook's content](https://storybook.js.org/docs/react/sharing/publish-storybook) |
94+
| Command | Description |
95+
| ------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
96+
| `pnpm dev` | Runs dev server with the HMR locally on port `5173` |
97+
| `pnpm lint` | Checks for lint errors |
98+
| `pnpm build` | Builds optimized app package |
99+
| `pnpm test` | Runs unit tests |
100+
| `pnpm test:coverage` | Runs unit tests with coverage |
101+
| `pnpm storybook` | Runs a Storybook locally on port `6006` |
102+
| `pnpm test-storybook` | Runs integration tests (requires a running Storybook on port `6006` - more info [here](https://storybook.js.org/blog/interaction-testing-with-storybook/)) |
103+
| `pnpm test-storybook:coverage` | Runs integration tests with coverage |
104+
| `pnpm build-storybook` | Builds static app with [a Storybook's content](https://storybook.js.org/docs/react/sharing/publish-storybook) |
102105

103106
# Contributing
104107

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
"dev": "vite",
88
"build": "tsc && vite build",
99
"test": "vitest",
10-
"test:ci": "vitest run --reporter verbose --reporter=junit --outputFile=./unit-report.xml",
10+
"test:ci": "vitest run --reporter verbose --reporter=junit --outputFile=./reports/unit-report.xml --coverage --coverage.reporter=lcov --coverage.reportsDirectory=./coverage",
11+
"test:coverage": "vitest run --coverage",
1112
"preview": "vite preview",
1213
"lint": "CI=true eslint . --ext ts,tsx --ignore-pattern '*.d.ts' --report-unused-disable-directives --max-warnings 0",
1314
"prepare": "husky install",
1415
"storybook": "storybook dev -p 6006",
1516
"test-storybook": "test-storybook --watch",
17+
"test-storybook:coverage": "test-storybook --coverage",
1618
"build-storybook": "storybook build"
1719
},
1820
"dependencies": {
@@ -23,6 +25,7 @@
2325
"devDependencies": {
2426
"@eslint/js": "9.24.0",
2527
"@storybook/addon-a11y": "9.0.15",
28+
"@storybook/addon-coverage": "2.0.0",
2629
"@storybook/addon-docs": "9.0.15",
2730
"@storybook/addon-links": "9.0.15",
2831
"@storybook/react-vite": "9.0.15",

0 commit comments

Comments
 (0)