UNPKG

9.55 kBMarkdownView Raw
1# grunt-karma-sonar
2[![Build Status](https://travis-ci.org/mdasberg/grunt-karma-sonar.svg?branch=master)](https://travis-ci.org/mdasberg/grunt-karma-sonar) [![npm version](https://img.shields.io/node/v/grunt-karma-sonar.svg)](https://github.com/mdasberg/grunt-karma-sonar) [![dependency Status](https://img.shields.io/david/mdasberg/grunt-karma-sonar.svg)](https://david-dm.org/mdasberg/grunt-karma-sonar) [![devDependency Status](https://img.shields.io/david/dev/mdasberg/grunt-karma-sonar.svg)](https://david-dm.org/mdasberg/grunt-karma-sonar#info=devDependencies) [![npm downloads](https://img.shields.io/npm/dm/grunt-karma-sonar.svg?style=flat-square)](https://www.npmjs.com/package/grunt-karma-sonar)
3
4> Grunt plugin for integrating karma and protractor reports with sonar.
5
6Currently the following frameworks are supported for both unit and integration testing:
7- jasmine / jasmine2 (the default)
8- cucumber
9
10To enable integration test result and coverage in Sonar, you need to install the following plugin [sonar-javascript-integrationtests](https://github.com/nvnoorloos/sonar-javascript-integrationtests)
11
12## Getting Started
13This plugin requires Grunt `~0.4.5`
14
15If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
16
17```shell
18npm install grunt-karma-sonar --save-dev
19```
20
21Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
22
23```js
24grunt.loadNpmTasks('grunt-karma-sonar');
25```
26
27## The "karmaSonar" task
28
29### Overview
30In your project's Gruntfile, add a section named `karmaSonar` to the data object passed into `grunt.initConfig()`.
31
32```js
33grunt.initConfig({
34 karmaSonar: {
35 options: {
36 // Task-specific options go here.
37 },
38 your_target: {
39 // Target-specific file lists and/or options go here.
40 },
41 },
42})
43```
44
45### Options
46
47#### options.dynamicAnalysis
48Type: `String`
49Default: 'reuseReports'
50
51Should be the sonar.property dynamicAnalysis
52
53#### options.sourceEncoding
54Type: `String`
55Default: 'UTF-8'
56
57Should be the sonar.property sourceEncoding
58
59#### options.language
60Type: `String`
61Default: 'js'
62
63Should be the sonar.property language (Starting with SonarQube 4.2, multi-language projects are supported. To enable this, set the value to null)
64
65#### options.scmDisabled
66Type: `String`
67Default: 'true'
68
69Should be the sonar.property scmDisabled
70
71#### options.defaultOutputDir
72Type: `String`
73Default: '.tmp/sonar/'
74
75Should be the location where the karmaSonar plugin will put it's temporary files.
76
77#### options.excludedProperties
78Type: `Array`
79Default: []
80
81Should be a list of sonar properties to exclude
82
83#### options.instance.hostUrl
84Type: `String`
85Default: 'http://localhost:9000'
86
87Should be the sonar.property host.url
88
89#### options.instance.jdbcUrl
90Type: `String`
91Default: 'jdbc:h2:tcp://localhost:9092/sonar'
92
93Should be the sonar.property jdbc.url
94
95#### options.instance.jdbcUsername
96Type: `String`
97Default: 'sonar'
98
99Should be the sonar.property jdbc.username
100
101#### options.instance.jdbcPassword
102Type: `String`
103Default: 'sonar'
104
105Should be the sonar.property jdbc.password
106
107#### options.instance.login
108Type: `String`
109Default: 'admin'
110
111Should be the sonar.property login
112
113#### options.instance.password
114Type: `String`
115Default: 'admin'
116
117Should be the sonar.property password
118
119#### options.instance.runnerProperties
120Type: `Object`
121
122Should be the list of key(`sonar key`) value pairs.
123
124```js
125runnerProperties: {
126 'sonar.links.homepage': 'https://github.com/mdasberg/grunt-karma-sonar',
127 'sonar.branch': 'master'
128}
129```
130
131#### options.debug
132Type: `Boolean`
133Default: 'false'
134
135If true sonar-runner debug logging will be turned on.
136
137#### project
138Type: `Object`,
139Mandatory: true
140
141Should be the project information for sonar
142
143#### project.key
144Type: `String`
145Mandatory: true`
146
147Should be the project key for sonar
148
149#### project.name
150Type: `String`
151Mandatory: true`
152
153Should be the project name for sonar
154
155#### project.version
156Type: `String`
157
158Should be the project version for sonar
159
160#### paths
161Type: `Array`
162
163Should be the paths that contain the code, tests and results
164
165#### paths[].cwd
166Type: `String`
167Default: '.'
168
169Should be the current working directory that contain the source, tests and results folders are located
170
171#### paths[].src
172Type: `String`
173
174Should be the directory containing the sources within the cwd.
175
176#### paths[].test
177Type: `String`
178
179Should be the directory containing the tests within the cwd.
180
181#### paths[].reports
182Type: `Object`
183
184Should be the object containing the reports.
185
186#### paths[].reports.unit
187Type: `String` or `Object` ie: {src: '...', framework: 'jasmine'} (Supported frameworks are: cucumber, jasmine/jasmine2(default))
188
189Should be the location of the karma-junit-reporter report within the cwd.
190
191#### paths[].reports.coverage
192Type: `String`
193
194Should be the glob for the lcov.info files within the cwd.
195
196#### paths[].reports.itUnit
197Type: `String` or `Object` ie: {src: '...', framework: 'jasmine'} (Supported frameworks are: cucumber, jasmine/jasmine2(default))
198
199Should be the location of the protractor report within the cwd.
200
201#### paths[].reports.itCoverage
202Type: `String`
203
204Should be the glob for the integration test lcov.info files within the cwd.
205
206### Usage Examples
207
208#### Default Options
209
210```js
211grunt.initConfig({
212 karmaSonar: {
213 options: {
214
215 },
216 your_target: {
217 project: {
218 key: 'grunt-sonar',
219 name: 'Grunt sonar plugin',
220 version: '0.2.13'
221 },
222 paths: [
223 {
224 cwd: '...', // the current working directory'
225 src: '...', // the source directory within the cwd
226 test: '...', // the test directory within the cwd
227 reports: {
228 unit: '../path/result.xml', // the result file within the cwd
229 coverage: '../path/**/lcov.info', // the glob for lcov files'
230 itCoverage: '../path/**/lcov.info' // the glob for integration lcov files'
231 }
232 },
233 {
234 cwd: '...', // the current working directory'
235 src: '...', // the source directory within the cwd
236 test: '...', // the test directory within the cwd
237 reports: {
238 unit: '../path/result.xml', // the result file within the cwd
239 coverage: '../path/**/lcov.info', // the glob for lcov files'
240 itCoverage: '../path/**/lcov.info' // the glob for integration lcov files'
241 }
242 ],
243 exclusions: []
244 }
245 }
246})
247```
248
249#### Custom Options
250In this example, custom options are used to do something else with whatever else. So if the `testing` file has the content `Testing` and the `123` file had the content `1 2 3`, the generated result in this case would be `Testing: 1 2 3 !!!`
251
252```js
253grunt.initConfig({
254 karmaSonar: {
255 options: {
256 defaultOutputDir: '.tmp/sonar/custom_options/',
257 instance: {
258 hostUrl : 'http://localhost:20001',
259 jdbcUrl : 'jdbc:h2:tcp://localhost:20003/sonar',
260 login: 'admin',
261 password: 'admin'
262 }
263 },
264 your_target: {
265 project: {
266 key: 'grunt-sonar',
267 name: 'Grunt sonar plugin',
268 version: '0.2.13'
269 },
270 paths: [...],
271 exclusions: []
272 }
273 }
274})
275```
276
277Deciding Where To Get Sonar-runner from
278-------------------------------
279
280By default, this package will download sonar-runner from `https://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=org.codehaus.sonar.runner&a=sonar-runner-dist&v=LATEST&p=zip`,
281but only when sonar-runner is not available on the path.
282
283##### Downloading from a custom URL
284
285If for some reason sonatype is down, or the Great Firewall is blocking sonatype, you may need to use
286a download mirror url. To set a mirror, set npm config property `sonarrunner_cdnurl`.
287Default is ``.
288
289```shell
290npm install grunt-karma-sonar --sonarrunner_cdnurl=http://some-mirror.org/path/to/downloads
291```
292
293Or add property into your `.npmrc` file (https://www.npmjs.org/doc/files/npmrc.html)
294
295```
296sonarrunner_cdnurl=http://some-mirror.org/path/to/downloads
297```
298
299Another option is to use PATH variable `SONARRUNNER_CDNURL`.
300```shell
301SONARRUNNER_CDNURL=http://some-mirror.org/path/to/downloads npm install grunt-karma-sonar
302```
303
304Note: It will try to find `sonar-runner-dist.zip` in the cdn url.
305
306##### Downloading from a custom Dir
307
308If for some reason sonatype is down, or the Great Firewall is blocking sonatype, you may need to use
309a download mirror directory. To set a mirror, set npm config property `sonarrunner_cdndir`.
310Default is ``.
311
312```shell
313npm install grunt-karma-sonar --sonarrunner_cdndir=/some/path/downloads
314```
315
316Or add property into your `.npmrc` file (https://www.npmjs.org/doc/files/npmrc.html)
317
318```
319sonarrunner_cdndir=/some/path/downloads
320```
321
322Another option is to use PATH variable `SONARRUNNER_CDNDIR`.
323```shell
324SONARRUNNER_CDNDIR=/some/path/downloads npm install grunt-karma-sonar
325```
326
327Note: It can be the case that there are multiple versions available at the download mirror.
328If this is the case the latest version will be used.
329
330
331## Contributing
332In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).
333
334## Release History
335_(Nothing yet)_
336