SonarQube with Jest Unit Tests

前端 未结 1 714
予麋鹿
予麋鹿 2021-02-04 04:50

I\'ve been trying to find out how to populate SonarQube with both my Jest Unit Tests and the .net Unit Tests.

I have a

相关标签:
1条回答
  • 2021-02-04 05:31

    Looks like I've figured out the way to make it work. The trick is to have both sonar.sources and sonar.tests point to same directory (because we have both tests and source in the same directory) then use sonar.tests.inclusions to pattern match test files with .test.js or .spec.js extension.

    Here's a sample sonar-project.properties which assumes the following:

    1. src/components/Foo/Foo.jsx the main component.
    2. src/components/Foo/Foo.spec.jsx the test file.
    # Source
    sonar.sources=src
    # Where to find tests file, also src
    sonar.tests=src
    # But we get specific here
    # We don't need to exclude it in sonar.sources because it is automatically taken care of
    sonar.test.inclusions=src/**/*.spec.js,src/**/*.spec.jsx,src/**/*.test.js,src/**/*.test.jsx
    
    # Now specify path of lcov and testlog
    sonar.javascript.lcov.reportPaths=coverage/jest/lcov.info
    sonar.testExecutionReportPaths=coverage/jest/testlog.xml
    

    Now your test files will also show up.

    More information here

    0 讨论(0)
提交回复
热议问题