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 |
|
6 | Currently the following frameworks are supported for both unit and integration testing:
|
7 | - jasmine / jasmine2 (the default)
|
8 | - cucumber
|
9 |
|
10 | To 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
|
13 | This plugin requires Grunt `~0.4.5`
|
14 |
|
15 | If 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
|
18 | npm install grunt-karma-sonar --save-dev
|
19 | ```
|
20 |
|
21 | Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
|
22 |
|
23 | ```js
|
24 | grunt.loadNpmTasks('grunt-karma-sonar');
|
25 | ```
|
26 |
|
27 | ## The "karmaSonar" task
|
28 |
|
29 | ### Overview
|
30 | In your project's Gruntfile, add a section named `karmaSonar` to the data object passed into `grunt.initConfig()`.
|
31 |
|
32 | ```js
|
33 | grunt.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
|
48 | Type: `String`
|
49 | Default: 'reuseReports'
|
50 |
|
51 | Should be the sonar.property dynamicAnalysis
|
52 |
|
53 | #### options.sourceEncoding
|
54 | Type: `String`
|
55 | Default: 'UTF-8'
|
56 |
|
57 | Should be the sonar.property sourceEncoding
|
58 |
|
59 | #### options.language
|
60 | Type: `String`
|
61 | Default: 'js'
|
62 |
|
63 | Should 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
|
66 | Type: `String`
|
67 | Default: 'true'
|
68 |
|
69 | Should be the sonar.property scmDisabled
|
70 |
|
71 | #### options.defaultOutputDir
|
72 | Type: `String`
|
73 | Default: '.tmp/sonar/'
|
74 |
|
75 | Should be the location where the karmaSonar plugin will put it's temporary files.
|
76 |
|
77 | #### options.excludedProperties
|
78 | Type: `Array`
|
79 | Default: []
|
80 |
|
81 | Should be a list of sonar properties to exclude
|
82 |
|
83 | #### options.instance.hostUrl
|
84 | Type: `String`
|
85 | Default: 'http://localhost:9000'
|
86 |
|
87 | Should be the sonar.property host.url
|
88 |
|
89 | #### options.instance.jdbcUrl
|
90 | Type: `String`
|
91 | Default: 'jdbc:h2:tcp://localhost:9092/sonar'
|
92 |
|
93 | Should be the sonar.property jdbc.url
|
94 |
|
95 | #### options.instance.jdbcUsername
|
96 | Type: `String`
|
97 | Default: 'sonar'
|
98 |
|
99 | Should be the sonar.property jdbc.username
|
100 |
|
101 | #### options.instance.jdbcPassword
|
102 | Type: `String`
|
103 | Default: 'sonar'
|
104 |
|
105 | Should be the sonar.property jdbc.password
|
106 |
|
107 | #### options.instance.login
|
108 | Type: `String`
|
109 | Default: 'admin'
|
110 |
|
111 | Should be the sonar.property login
|
112 |
|
113 | #### options.instance.password
|
114 | Type: `String`
|
115 | Default: 'admin'
|
116 |
|
117 | Should be the sonar.property password
|
118 |
|
119 | #### options.instance.runnerProperties
|
120 | Type: `Object`
|
121 |
|
122 | Should be the list of key(`sonar key`) value pairs.
|
123 |
|
124 | ```js
|
125 | runnerProperties: {
|
126 | 'sonar.links.homepage': 'https://github.com/mdasberg/grunt-karma-sonar',
|
127 | 'sonar.branch': 'master'
|
128 | }
|
129 | ```
|
130 |
|
131 | #### options.debug
|
132 | Type: `Boolean`
|
133 | Default: 'false'
|
134 |
|
135 | If true sonar-runner debug logging will be turned on.
|
136 |
|
137 | #### project
|
138 | Type: `Object`,
|
139 | Mandatory: true
|
140 |
|
141 | Should be the project information for sonar
|
142 |
|
143 | #### project.key
|
144 | Type: `String`
|
145 | Mandatory: true`
|
146 |
|
147 | Should be the project key for sonar
|
148 |
|
149 | #### project.name
|
150 | Type: `String`
|
151 | Mandatory: true`
|
152 |
|
153 | Should be the project name for sonar
|
154 |
|
155 | #### project.version
|
156 | Type: `String`
|
157 |
|
158 | Should be the project version for sonar
|
159 |
|
160 | #### paths
|
161 | Type: `Array`
|
162 |
|
163 | Should be the paths that contain the code, tests and results
|
164 |
|
165 | #### paths[].cwd
|
166 | Type: `String`
|
167 | Default: '.'
|
168 |
|
169 | Should be the current working directory that contain the source, tests and results folders are located
|
170 |
|
171 | #### paths[].src
|
172 | Type: `String`
|
173 |
|
174 | Should be the directory containing the sources within the cwd.
|
175 |
|
176 | #### paths[].test
|
177 | Type: `String`
|
178 |
|
179 | Should be the directory containing the tests within the cwd.
|
180 |
|
181 | #### paths[].reports
|
182 | Type: `Object`
|
183 |
|
184 | Should be the object containing the reports.
|
185 |
|
186 | #### paths[].reports.unit
|
187 | Type: `String` or `Object` ie: {src: '...', framework: 'jasmine'} (Supported frameworks are: cucumber, jasmine/jasmine2(default))
|
188 |
|
189 | Should be the location of the karma-junit-reporter report within the cwd.
|
190 |
|
191 | #### paths[].reports.coverage
|
192 | Type: `String`
|
193 |
|
194 | Should be the glob for the lcov.info files within the cwd.
|
195 |
|
196 | #### paths[].reports.itUnit
|
197 | Type: `String` or `Object` ie: {src: '...', framework: 'jasmine'} (Supported frameworks are: cucumber, jasmine/jasmine2(default))
|
198 |
|
199 | Should be the location of the protractor report within the cwd.
|
200 |
|
201 | #### paths[].reports.itCoverage
|
202 | Type: `String`
|
203 |
|
204 | Should be the glob for the integration test lcov.info files within the cwd.
|
205 |
|
206 | ### Usage Examples
|
207 |
|
208 | #### Default Options
|
209 |
|
210 | ```js
|
211 | grunt.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
|
250 | In 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
|
253 | grunt.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 |
|
277 | Deciding Where To Get Sonar-runner from
|
278 | -------------------------------
|
279 |
|
280 | By 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`,
|
281 | but only when sonar-runner is not available on the path.
|
282 |
|
283 | ##### Downloading from a custom URL
|
284 |
|
285 | If for some reason sonatype is down, or the Great Firewall is blocking sonatype, you may need to use
|
286 | a download mirror url. To set a mirror, set npm config property `sonarrunner_cdnurl`.
|
287 | Default is ``.
|
288 |
|
289 | ```shell
|
290 | npm install grunt-karma-sonar --sonarrunner_cdnurl=http://some-mirror.org/path/to/downloads
|
291 | ```
|
292 |
|
293 | Or add property into your `.npmrc` file (https://www.npmjs.org/doc/files/npmrc.html)
|
294 |
|
295 | ```
|
296 | sonarrunner_cdnurl=http://some-mirror.org/path/to/downloads
|
297 | ```
|
298 |
|
299 | Another option is to use PATH variable `SONARRUNNER_CDNURL`.
|
300 | ```shell
|
301 | SONARRUNNER_CDNURL=http://some-mirror.org/path/to/downloads npm install grunt-karma-sonar
|
302 | ```
|
303 |
|
304 | Note: It will try to find `sonar-runner-dist.zip` in the cdn url.
|
305 |
|
306 | ##### Downloading from a custom Dir
|
307 |
|
308 | If for some reason sonatype is down, or the Great Firewall is blocking sonatype, you may need to use
|
309 | a download mirror directory. To set a mirror, set npm config property `sonarrunner_cdndir`.
|
310 | Default is ``.
|
311 |
|
312 | ```shell
|
313 | npm install grunt-karma-sonar --sonarrunner_cdndir=/some/path/downloads
|
314 | ```
|
315 |
|
316 | Or add property into your `.npmrc` file (https://www.npmjs.org/doc/files/npmrc.html)
|
317 |
|
318 | ```
|
319 | sonarrunner_cdndir=/some/path/downloads
|
320 | ```
|
321 |
|
322 | Another option is to use PATH variable `SONARRUNNER_CDNDIR`.
|
323 | ```shell
|
324 | SONARRUNNER_CDNDIR=/some/path/downloads npm install grunt-karma-sonar
|
325 | ```
|
326 |
|
327 | Note: It can be the case that there are multiple versions available at the download mirror.
|
328 | If this is the case the latest version will be used.
|
329 |
|
330 |
|
331 | ## Contributing
|
332 | In 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 |
|