Skip to content

Commit bda593d

Browse files
authored
Merge pull request #125 from Typeform/TU-13737-Measure-Unit-Test-Coverage
[TU-13737] Add SonarCloud test coverage configuration
2 parents ef1c507 + c98d7cb commit bda593d

File tree

6 files changed

+588
-10
lines changed

6 files changed

+588
-10
lines changed

.github/workflows/pr.yml

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
matrix:
1313
node_version:
1414
- 18 # end of life 2025-04-30
15-
- 20 # end of life 2025-04-30
15+
- 20 # end of life 2025-04-30 # please update "Upload coverage file" step if you change this
1616
name: build-lint-test - node ${{ matrix.node_version }}
1717
steps:
1818
- name: Check out Git repository
@@ -44,7 +44,54 @@ jobs:
4444
run: yarn lint
4545

4646
- name: Unit tests
47-
run: yarn test:unit
47+
run: yarn test:unit --coverage
4848

4949
- name: Integration tests
50-
run: (yarn server &) && sleep 1 && yarn test:integration
50+
run: (yarn server &) && sleep 1 && yarn test:integration --coverage
51+
52+
- name: Merge coverage reports and generate lcov.info
53+
run: |
54+
mkdir -p .nyc_output
55+
npx nyc merge ./coverage
56+
npx nyc report --reporter=lcov --temp-dir ./coverage
57+
58+
- name: Upload coverage file
59+
uses: actions/upload-artifact@v4
60+
if: ${{ matrix.node_version == '20' }}
61+
with:
62+
name: coverage-report
63+
path: ./coverage/lcov.info
64+
retention-days: 1
65+
66+
sonarcloud:
67+
name: Test and Code Quality Report (SonarCloud)
68+
needs:
69+
- build-lint-test
70+
runs-on: ubuntu-latest
71+
steps:
72+
- name: Check out Git repository
73+
uses: actions/checkout@v4
74+
with:
75+
fetch-depth: 0
76+
77+
- name: Download coverage file
78+
uses: actions/download-artifact@v4
79+
with:
80+
name: coverage-report
81+
82+
- name: Move the coverage file to a proper location
83+
run: |
84+
mkdir -p coverage
85+
mv lcov.info coverage/lcov.info
86+
87+
- name: Verify coverage file ready
88+
run: ls -lah ./coverage/lcov.info
89+
90+
- name: SonarCloud Scan
91+
uses: SonarSource/sonarcloud-github-action@v2
92+
with:
93+
args: >
94+
-Dsonar.projectVersion=${{ github.run_id }}
95+
env:
96+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
97+
SONAR_TOKEN: ${{ secrets.SONAR_CLOUD_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ yarn-error.log
77
.idea/
88
params.js
99
params.json
10+
coverage*

.nycrc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"extends": "@istanbuljs/nyc-config-typescript",
3+
"all": true,
4+
"include": [
5+
"src/**/*.ts"
6+
],
7+
"exclude": [
8+
"**/*.d.ts",
9+
"**/tests/**",
10+
"**/node_modules/**"
11+
],
12+
"reporter": [
13+
"lcov",
14+
"text-summary"
15+
],
16+
"report-dir": "./coverage",
17+
"check-coverage": false
18+
}

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"devDependencies": {
6262
"@commitlint/cli": "^8.1.0",
6363
"@commitlint/config-conventional": "^8.1.0",
64+
"@istanbuljs/nyc-config-typescript": "^1.0.2",
6465
"@semantic-release/commit-analyzer": "^11.1.0",
6566
"@semantic-release/exec": "^6.0.3",
6667
"@semantic-release/github": "^9.2.4",
@@ -75,6 +76,7 @@
7576
"json-server": "^0.15.1",
7677
"lint-staged": "^13.2.2",
7778
"nodemon": "^1.19.2",
79+
"nyc": "^17.0.0",
7880
"prettier": "^2.8.8",
7981
"rollup": "^1.21.2",
8082
"rollup-plugin-commonjs": "^10.1.0",

sonar-project.properties

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
sonar.projectKey=Typeform_js-api-client
2+
sonar.organization=typeform
3+
sonar.projectVersion=dev
4+
5+
sonar.sources=src
6+
sonar.tests=tests
7+
8+
sonar.inclusions=packages/*/src/**/*.ts,src/**/*.js
9+
sonar.exclusions=node_modules/**,dist/**,**/*.spec.ts,**/*.test.ts
10+
11+
sonar.test.exclusions=node_modules/**,dist/**
12+
13+
sonar.javascript.lcov.reportPaths=./coverage/lcov.info

0 commit comments

Comments
 (0)