From bab964f68041cb190ba1c3efbf5b9f04c638fd70 Mon Sep 17 00:00:00 2001 From: andrewtan2000 Date: Wed, 7 Aug 2024 23:28:29 +0800 Subject: [PATCH] upload coverage reports to sonarcloud --- .github/workflows/build.yml | 7 ++++--- jest.config.js | 6 ++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fa4d430..962182c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -48,8 +48,8 @@ jobs: - name: Clean Install dependencies run: npm ci - - name: Run unit tests - run: npm test + - name: Run tests and generate coverage report + run: npm test -- --coverage #Run sonar cloud scan - name: SonarCloud Scan @@ -57,7 +57,8 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - + with: + args: -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info - name: Build run: npm run build env: diff --git a/jest.config.js b/jest.config.js index 29904f1..f0f9dc4 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,3 +1,9 @@ module.exports = { testEnvironment: 'jest-environment-jsdom', + collectCoverage: true, + collectCoverageFrom: [ + 'src/**/*.{js,jsx,ts,tsx}', + '!src/**/*.d.ts', + ], + coverageDirectory: 'coverage', }; \ No newline at end of file