Skip to content

Commit 89583ba

Browse files
authored
Merge pull request #16 from arnabnandy7/hotfix/testCoverage
Adding test coverage workflow for sonar
2 parents 878424f + ad2e906 commit 89583ba

6 files changed

Lines changed: 186 additions & 3 deletions

File tree

.github/workflows/test.yml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@ on:
1010

1111
permissions:
1212
contents: read
13+
pull-requests: read
1314

1415
jobs:
1516
test:
1617
runs-on: ubuntu-latest
18+
env:
19+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN || secrets.SONARCLOUD_TOKEN }}
1720
steps:
1821
- name: Checkout repository
1922
uses: actions/checkout@v6
23+
with:
24+
fetch-depth: 0
2025

2126
- name: Use Node.js
2227
uses: actions/setup-node@v5
@@ -26,5 +31,17 @@ jobs:
2631
- name: Install dependencies
2732
run: npm ci
2833

29-
- name: Run tests
30-
run: npm test
34+
- name: Run tests with coverage
35+
run: npm run test:coverage
36+
37+
- name: SonarCloud scan
38+
uses: SonarSource/sonarqube-scan-action@v7
39+
if: ${{ env.SONAR_TOKEN != '' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) }}
40+
41+
- name: Upload coverage report
42+
uses: actions/upload-artifact@v4
43+
if: always()
44+
with:
45+
name: coverage-report
46+
path: coverage
47+
if-no-files-found: error

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const eslintConfig = defineConfig([
99
globalIgnores([
1010
// Default ignores of eslint-config-next:
1111
".next/**",
12+
"coverage/**",
1213
"out/**",
1314
"build/**",
1415
"next-env.d.ts",

package-lock.json

Lines changed: 148 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"build": "next build",
88
"start": "next start",
99
"lint": "eslint",
10-
"test": "vitest run"
10+
"test": "vitest run",
11+
"test:coverage": "vitest run --coverage"
1112
},
1213
"dependencies": {
1314
"exceljs": "^4.4.0",
@@ -25,6 +26,7 @@
2526
"@types/node": "^20",
2627
"@types/react": "^19",
2728
"@types/react-dom": "^19",
29+
"@vitest/coverage-v8": "^4.1.8",
2830
"eslint": "^9",
2931
"eslint-config-next": "16.2.7",
3032
"jsdom": "^29.1.1",

sonar-project.properties

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
sonar.projectKey=arnabnandy7_api-response-comparator
2+
sonar.organization=arnabnandy7
3+
4+
sonar.sources=src
5+
sonar.tests=test
6+
7+
sonar.javascript.lcov.reportPaths=coverage/lcov.info
8+
sonar.coverage.exclusions=src/**/*.d.ts

vitest.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,12 @@ export default defineConfig({
88
},
99
test: {
1010
environment: 'jsdom',
11+
coverage: {
12+
provider: 'v8',
13+
reporter: ['text', 'json', 'html', 'lcov'],
14+
reportsDirectory: './coverage',
15+
include: ['src/**/*.{ts,tsx}'],
16+
exclude: ['src/**/*.d.ts'],
17+
},
1118
},
1219
});

0 commit comments

Comments
 (0)