I'm trying to output some test coverage (lcov) reports from istanbul into sonarqube to analyse our test coverage using thoughtworks GO. There is a coverage/html folder being output but sonarqube reports the following error No coverage property. Skip Sensor. Here's my properties file, what am I missing ?
sonar.projectKey=transformers.allspark.ui
sonar.projectName=Transformers Allspark UI
sonar.projectVersion=1.0
sonar.host.url=https://sonarqube-security.test.ctmers.io
sonar.sources=.
sonar.projectBaseDir=.
sonar.language=js
sonar.sourceEncoding=UTF-8
sonar.javascript.lcov.reportPath=coverage/html
Thanks for responding. I've managed to fix this by replacing the last line with this : sonar.javascript.lcov.reportPath=coverage/html/lcov.info. It appears that sonarqube needs a path to a file (lcov.info) and not just the folder. Also my istanbul configuration was wrong because it needed to output lcov and not just a standard report.
Related
When using #vue/cli-plugin-unit-jest, I am receiving coverage reports each time I run my unit tests, regardless of whether I have the --coverage flag in the execution line or not. I do not want to receive coverage reports on all of my untested files. When searching for an answer online, there are numerous questions about how to turn that feature on, not turn it off. I can't find it in the documentation either.
How do you disable the Coverage on Untested Files feature in Jest?
Disabling coverage similar to enabling it, just prefix the pattern with an ! like so:
{
"collectCoverageFrom": [
"**/*.{js,jsx}",
"!**/node_modules/**",
"!**/folder-with-untested-files/**"
]
}
Or disable coverage all together with "collectCoverage": false.
If that does not work, then you have this params overridden somewhere in your code.
"collectCoverage": false
in jest.config.js
You can also suppress coverage from the command line. The package I'm working with provides a test script, and I was able to pass the collectCoverage option in as a flag. The relative path here works because my test runner is called by npm and that should set the working directory to the root of my project:
npm run test -- path/to/your.spec.js --collectCoverage=false
And the other way around, you can specific a single file to collect coverage from. It'll override any broad-ranging glob you may have already defined in your project's test config files. One reminder, you collect coverage from your source file, not your spec file. And one other reminder, you can list pretty much any file you want in that coverage option, so make sure you get it right:
npm run test -- path/to/your.spec.js --collectCoverageFrom=path/to/your/source/file.js
Package.json
testw": "jest --watch --collectCoverage=false"
watches the test files for change
npm command
npm run testw Yourfilename.js
"collectCoverage": false
in package.json, will disable coverage, collection, As mentioned by #Herman you can also put ! before file pattern in value of property collectCoverageFrom in package.json
In my case, in package.json I have this statement collectCoverage:false and still I was getting errors. Then I realized I also have collectCoverageFrom line and I removed it since I did not need it. After removing the below line it worked as a charm.
"collectCoverageFrom": [
...,
...
]
I use sonarqube for JS Project, I would like to integrate the XML result for the unit test. I have this error :
ERROR: Caused by: Line 2 of report refers to a file which is not configured as a test file: modules/project/projectTest.js
I don't understand why this error is here.
The projectTest file get analysed, do I need to set something so that sonarqube can handle them as test files.
My XML result file :
<testExecutions version="1">
<file path="modules/proejct/projectTest.js">
<testCase name="Test" duration="16"/>
</file>
</testExecutions>
Thank you for your hlep
Files referenced in your unit test report need to be test files, in other words they should be configured by sonar.tests property. See docs https://docs.sonarqube.org/display/SONAR/Analysis+Parameters
I'm developing a nodeJS + angular stacked application. To generate the code coverage reports for the backend I use istanbul and mocha. However, the coverage reports show incorrect figures.
If I run istanbul cover _mocha --print detail /path/to/tests* I get full coverage (but only on the file that is requires by the test spec). On the other hand if I run istanbul cover _mocha --print detail --include-all-sources /path/to/tests* istanbul also checks the test coverage for the frontend code (angular, which I test with karma/jasmine separately).
How do I run istanbul so it includes only the backend source files?
According to istanbul help cover output
$ ./node_modules/.bin/istanbul help cover
Usage: istanbul cover [<options>] <executable-js-file-or-command> [--<arguments-to-jsfile>]
Options are:
--config <path-to-config>
the configuration file to use, defaults to .istanbul.yml
--root <path>
the root path to look for files to instrument, defaults to .
-x <exclude-pattern> [-x <exclude-pattern>]
one or more glob patterns e.g. "**/vendor/**"
-i <include-pattern> [-i <include-pattern>]
one or more glob patterns e.g. "**/*.js"
--[no-]default-excludes
apply default excludes [ **/node_modules/**, **/test/**,
**/tests/** ], defaults to true
--hook-run-in-context
hook vm.runInThisContext in addition to require (supports
RequireJS), defaults to false
--post-require-hook <file> | <module>
JS module that exports a function for post-require processing
--report <format> [--report <format>]
report format, defaults to lcov (= lcov.info + HTML)
--dir <report-dir>
report directory, defaults to ./coverage
--print <type>
type of report to print to console, one of summary (default),
detail, both or none
--verbose, -v
verbose mode
--[no-]preserve-comments
remove / preserve comments in the output, defaults to false
--include-all-sources
instrument all unused sources after running tests, defaults to
false
--[no-]include-pid
include PID in output coverage filename
You should use the -X to exclude some files from coverage reporting. i.e:
$ ./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha test -X dist/index.js
Will execute the test, and ignore the dist/index.js file on coverage reporting
Do you have your backend code and your frontend code in separate directories? For example /test/api and /test/dashboard or whatever. If you keep your code separate, you can tell istanbul to report on each at a time like so:
istanbul cover _mocha test/api/**/*.js
Makes sense? Would that work for you at all?
Let me know.
I also faced a similar situation and hence thought it's worth sharing if it could help someone though its an old post. Istanbul takes the current directory (.) as a coverage directory while running the command. In order to include just a specific directory to coverage scope use "--root /dir/" option. This would generate coverage report only for the files in that directory.
I am using JSCover to capture coverage of my javascript files. JSCover outputs coverage in json format and I can use the given html files to view the coverage results.
I am converting the json file to lcov using:
java -cp JSCover-all.jar jscover.report.Main --format=LCOV REPORT-DIR SRC-DIRECTORY
This is what I set in my sonar.propoerties file
sonar.javascript.jstestdriver.reportsPath= C:/...reports
sonar.javascript.lcov.reportPath=C:/.../JSCover/target/jscover.lcov
sonar.dynamicAnalysis=reuseReports
But I am not able to see coverage. Why?
I just found out about JsChilicat and saw the code coverage example and I want to do something similar for my code. As I can see from the GitHub page I have to execute a command in the following manner:
java -jar jschilicat.jar -chilicat -workingDir=/Users/jschilicat/dev/results \ -libs=/dev/libs -src=/dev/src -src-test=/dev/test/
Do I need to write a specific test and place it in the test folder so that code coverage report will be generated? Or I can leave this folder empty?
Thanks in advance.
you have to enable the output reports explicitly with jsChiliCat (Note the -junitReport and -coverage options in the example below).
The options you provide to the chilicat jar command give you with the ability to set the location of your JS Src, Tests and Libraries. However the GitHub example is incorrect, you need to omit the '=' signs from the command line options. The following example worked for my POC project...
java -jar lib/jschilicat-dist/libs/jschilicat.jar -chilicat -workingDir target -src src/js -src-test src/test -libs src/lib -junitReport -coverage
HTH,
Paul