From 58a785b0cb5e442e7c00ae7be66881406861fb51 Mon Sep 17 00:00:00 2001 From: GSRN Date: Tue, 16 Sep 2025 23:04:43 +0200 Subject: [PATCH] chore: Enhance frontend CI workflow for improved test coverage reporting ### Summary of Changes - Updated the test command in the CI workflow to use `npx vitest` for running tests with coverage. - Added a verification step to check for the presence of coverage files (`lcov.info` and `clover.xml`). - Configured Vitest to output JUnit test results and detailed coverage reports in the specified directory. ### Expected Results - Improved visibility and reliability of test coverage metrics, facilitating better quality assurance processes. --- .gitea/workflows/frontend.yml | 25 ++++++++++++++++++++++--- frontend/vitest.config.js | 16 ++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/frontend.yml b/.gitea/workflows/frontend.yml index c04b25f..ad4c0ba 100644 --- a/.gitea/workflows/frontend.yml +++ b/.gitea/workflows/frontend.yml @@ -70,8 +70,23 @@ jobs: - name: Run tests run: | - npm test -- --run --coverage --reporter=verbose - npm run test:coverage + npx vitest run --coverage --reporter=verbose + + - name: Verify coverage files + run: | + echo "Checking coverage files..." + ls -la coverage/ + echo "Required coverage files:" + if [ -f "coverage/lcov.info" ]; then + echo "✓ lcov.info found" + else + echo "✗ lcov.info missing" + fi + if [ -f "coverage/clover.xml" ]; then + echo "✓ clover.xml found" + else + echo "✗ clover.xml missing" + fi - name: Send results to SonarQube run: | @@ -84,7 +99,11 @@ jobs: -Dsonar.host.url=${{ secrets.SONAR_HOST_URL }} \ -Dsonar.login=${{ secrets.SONAR_TOKEN }} \ -Dsonar.projectKey=labfusion-frontend \ - -Dsonar.projectName=LabFusion Frontend + -Dsonar.projectName=LabFusion Frontend \ + -Dsonar.sources=src \ + -Dsonar.tests=src \ + -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info \ + -Dsonar.coverageReportPaths=coverage/clover.xml - name: Test results summary if: always() diff --git a/frontend/vitest.config.js b/frontend/vitest.config.js index efad883..39a1484 100644 --- a/frontend/vitest.config.js +++ b/frontend/vitest.config.js @@ -7,5 +7,21 @@ export default defineConfig({ environment: 'jsdom', setupFiles: ['./src/setupTests.js'], globals: true, + reporter: ['verbose', 'junit'], + outputFile: { + junit: './coverage/test-results.xml' + }, + coverage: { + provider: 'v8', + reporter: ['text', 'html', 'lcov', 'clover'], + reportsDirectory: './coverage', + include: ['src/**/*.{js,jsx}'], + exclude: [ + 'src/**/*.test.{js,jsx}', + 'src/**/*.spec.{js,jsx}', + 'src/setupTests.js', + 'src/index.js' + ] + } }, });