diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b0361a8..c17ed57 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,10 +1,12 @@ name: Build + on: push: branches: - fix/sonar_testCoverage pull_request: types: [opened, synchronize, reopened] + jobs: sonarcloud: name: SonarQube Cloud @@ -12,9 +14,27 @@ jobs: steps: - uses: actions/checkout@v4 with: - fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + fetch-depth: 0 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: 20.18.2 + + - name: Install dependencies + run: npm install + + - name: Run tests and generate coverage + run: npm run coverage + - name: SonarQube Cloud Scan uses: SonarSource/sonarcloud-github-action@master env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + with: + args: > + -Dsonar.projectKey=AntaresSimulatorTeam_antares-datamanager-front + -Dsonar.organization=antaressimulatorteam + -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info + -Dsonar.typescript.lcov.reportPaths=coverage/lcov.info diff --git a/.gitignore b/.gitignore index 8f05a06..e86027c 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,6 @@ dist-ssr *.njsproj *.sln *.sw? + +# Coverage couverture +coverage/ diff --git a/package.json b/package.json index 3872777..cae139b 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", "preview": "vite preview", "cy:open": "cypress open", - "prepare": "husky && husky install" + "prepare": "husky && husky install", + "coverage": "vitest run --coverage" }, "dependencies": { "@floating-ui/react": "^0.26.28", diff --git a/sonar-project.properties b/sonar-project.properties index c0b9c30..c23aee6 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -12,3 +12,6 @@ sonar.sources=src # Encoding of the source code. Default is default system encoding sonar.sourceEncoding=UTF-8 + +# Test coverage report +sonar.typescript.lcov.reportPaths=coverage/lcov.info