grunt-qunit-sonar
Grunt plugin for qunit unit test with coverage
Getting Started
This plugin has two external dependencies, both must be downloaded, extracted and registered in the PATH environment variable:
Install the module with: npm install grunt-unit-sonar
Then load it from your own grunt.js
file:
grunt;
Documentation
'qunit-sonar': {
mysubtask: {
"minimum": 0.01, //min coverage; 80% default
"srcDir": "src", //your source here
"depDirs": ["tests","libs"], //your depended files
"outDir": "test_results", //where you want save reports (LCov and xml)
"testFiles": "tests/TestsChart.html" // html file where you include unit tests
}
}
grunt.registerTask('default', 'qunit-sonar');
How it works
-
Run qunit-sonar task from from directory where you store Gruntfile.js:
grunt qunit-sonar//or just grunt if qunit-sonar is a default taskgrunt -
In your outDir directory you should see something like this:
|-outDir|--| |--in| |--out| jsTestDriverconf-coveragedat| TEST-projects-tools-gruntxml| -
Create pom file for sonar:
4.0.0Your-group-idModuleName1.0pomName your modulejsSonarLoginSonarPasswordreuseReportstrue/path/to/outDir/path/to/outDir//path/to/outDir/jsTestDriver.conf-coverage.daturl-to-sonar-serverDB driver (example: com.microsoft.sqlserver.jdbc.SQLServerDriver)url for sonar DB (example: jdbc:sqlserver://your.sonar.db.ip.or.url;database=SONAR;SelectMethod=Cursor/path/to/moduleSource//path/to/testDir/YourModuleTests.jscom.googlecode.jstd-maven-pluginjstd-maven-pluginsonar version (example: 1.3.5.1)true"C:\Program Files\Internet Explorer\iexplore.exe"9876/path/to/outDirrun-teststest<!-- pom.xml, the build/plugins section -->org.apache.maven.pluginsmaven-failsafe-plugin/path/to/outDirscm:svn:http://javascript-plugin-for-sonar.googlecode.com/svn/trunk/samplescm:svn:http://javascript-plugin-for-sonar.googlecode.com/svn/trunk/samplehttp://javascript-plugin-for-sonar.googlecode.com<!-- JsTestDriver Dependencies -->com.googlecode.jstd-maven-pluginjstd-maven-plugin1.3.2.5testjstd-maven-plugin google code repohttp://jstd-maven-plugin.googlecode.com/svn/maven2jstd-maven-plugin google code repohttp://jstd-maven-plugin.googlecode.com/svn/maven2 -
So now we should send generated reports (jsTestDriver.conf-coverage.dat, TEST-projects-tools-grunt.xml) to sonar qube. We will use maven for this (http://maven.apache.org/download.cgi). If you use sonar v3.6+ you can use maven Maven 3.1+. If your sonar version less than v3.6 I would recomend to use Maven 3.0.5.
Example:
mvn -X -f "PATH_TO_YOUR_POM_FILE/js_pom.xml" sonar:sonar
Contributing
Please use the issue tracker and pull requests.
License
Copyright (c) 2013 Dmytro Ovcharenko Licensed under the MIT license.