Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code coverage problem [Solution] #5

Open
pglez82 opened this issue Mar 22, 2023 · 0 comments
Open

Code coverage problem [Solution] #5

pglez82 opened this issue Mar 22, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@pglez82
Copy link
Owner

pglez82 commented Mar 22, 2023

Code coverage was computed not taking into account the restapi code coverage. This was due to two reasons:

  1. A bug in jest (the test runner), that saves the file paths with relative paths instead of absolute. This is a problem in the restapi because the tests were stored in a folder 'tests'.
  2. Having two github actions jobs for executing the unitary tests was actually making two different test reports, that when uploaded to SonarCloud, were being overwritten.

In order to solve these two issues, the following changes need to be made:

  1. Take outside the tests directory the tests for the restapi. Update the package.json of this module accordingly.
  2. Replace the two github actions jobs for the unit tests in only one. This job should install the dependencies and run the tests for both modules (or more if it is the case in your project). When doing this, we only upload to sonarcloud one test coverage report so everything will work as expected.
  unit-tests:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - uses: actions/setup-node@v3
      with:
        node-version: 18
    - run: npm --prefix webapp ci
    - run: npm --prefix restapi ci
    - run: npm --prefix webapp test --coverage --watchAll
    - run: npm --prefix restapi test --coverage --watchAll
    - name: Analyze with SonarCloud
      uses: sonarsource/sonarcloud-github-action@master
      env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
@pglez82 pglez82 added the bug Something isn't working label Mar 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant