1 | # karma-mocha-reporter
|
2 |
|
3 | > Karma reporter plugin with mocha style logging.
|
4 |
|
5 | > [![NPM version](https://badge.fury.io/js/karma-mocha-reporter.svg)](http://badge.fury.io/js/karma-mocha-reporter)
|
6 | [![Build Status](https://secure.travis-ci.org/litixsoft/karma-mocha-reporter.svg?branch=master)](https://travis-ci.org/litixsoft/karma-mocha-reporter)
|
7 | [![david-dm](https://david-dm.org/litixsoft/karma-mocha-reporter.svg?theme=shields.io)](https://david-dm.org/litixsoft/karma-mocha-reporter/)
|
8 | [![david-dm](https://david-dm.org/litixsoft/karma-mocha-reporter/dev-status.svg?theme=shields.io)](https://david-dm.org/litixsoft/karma-mocha-reporter#info=devDependencies&view=table)
|
9 |
|
10 | ## How does it look like
|
11 | ![screenshot](demo/screen.png)
|
12 |
|
13 | ## Installation
|
14 | The easiest way is to keep `karma-mocha-reporter` as a devDependency in your `package.json`.
|
15 | ```json
|
16 | {
|
17 | "devDependencies": {
|
18 | "karma": "^1.0.0",
|
19 | "karma-mocha-reporter": "^2.0.0"
|
20 | }
|
21 | }
|
22 | ```
|
23 |
|
24 | You can simply do it by:
|
25 |
|
26 | $ npm install karma-mocha-reporter --save-dev
|
27 |
|
28 | ## Configuration
|
29 | ```js
|
30 | // karma.conf.js
|
31 | module.exports = function(config) {
|
32 | config.set({
|
33 | frameworks: ['jasmine'],
|
34 |
|
35 | // reporters configuration
|
36 | reporters: ['mocha']
|
37 | });
|
38 | };
|
39 | ```
|
40 |
|
41 | ## Options
|
42 | ### colors
|
43 | **Type:** Object | Boolean
|
44 |
|
45 | Lets you overwrite the default colors. Possible values are all colors and background colors from [chalk](https://github.com/chalk/chalk#colors).
|
46 |
|
47 | **Possible Values:**
|
48 |
|
49 | Value | Description | Default
|
50 | ------ | ----------- | -------
|
51 | `success` | success messages | green
|
52 | `info` | info messages | grey
|
53 | `warning` | warn messages | yellow
|
54 | `error` | error messages | red
|
55 |
|
56 | ```js
|
57 | // karma.conf.js
|
58 | module.exports = function(config) {
|
59 | config.set({
|
60 | frameworks: ['jasmine'],
|
61 |
|
62 | // reporters configuration
|
63 | reporters: ['mocha'],
|
64 |
|
65 | // reporter options
|
66 | mochaReporter: {
|
67 | colors: {
|
68 | success: 'blue',
|
69 | info: 'bgGreen',
|
70 | warning: 'cyan',
|
71 | error: 'bgRed'
|
72 | },
|
73 | symbols: {
|
74 | success: '+',
|
75 | info: '#',
|
76 | warning: '!',
|
77 | error: 'x'
|
78 | }
|
79 | }
|
80 | });
|
81 | };
|
82 | ```
|
83 |
|
84 | To disable the colors please use the `colors` option in the karma config.
|
85 |
|
86 | ```js
|
87 | // karma.conf.js
|
88 | module.exports = function(config) {
|
89 | config.set({
|
90 | frameworks: ['jasmine'],
|
91 |
|
92 | // reporters configuration
|
93 | reporters: ['mocha'],
|
94 |
|
95 | // disable colors
|
96 | colors: false
|
97 | });
|
98 | };
|
99 | ```
|
100 |
|
101 | ### symbols
|
102 | **Type:** Object
|
103 |
|
104 | Lets you overwrite the default symbols.
|
105 |
|
106 | **Possible Values:**
|
107 |
|
108 | Value | Description | Default
|
109 | ------ | ----------- | -------
|
110 | `success` | success messages | ✔
|
111 | `info` | info messages | ℹ
|
112 | `warning` | warn messages | ⚠
|
113 | `error` | error messages | ✖
|
114 |
|
115 | ```js
|
116 | // karma.conf.js
|
117 | module.exports = function(config) {
|
118 | config.set({
|
119 | frameworks: ['jasmine'],
|
120 |
|
121 | // reporters configuration
|
122 | reporters: ['mocha'],
|
123 |
|
124 | // reporter options
|
125 | mochaReporter: {
|
126 | symbols: {
|
127 | success: '+',
|
128 | info: '#',
|
129 | warning: '!',
|
130 | error: 'x'
|
131 | }
|
132 | }
|
133 | });
|
134 | };
|
135 | ```
|
136 |
|
137 | ### output
|
138 | **Type:** String
|
139 |
|
140 | **Possible Values:**
|
141 |
|
142 | Value | Description
|
143 | ------ | -----------
|
144 | `full` (default) | all output is printed to the console
|
145 | `autowatch` | first run will have the full output and the next runs just output the summary and errors in mocha style
|
146 | `minimal` | only the summary and errors are printed to the console in mocha style
|
147 | `noFailures` | the failure details are not logged
|
148 |
|
149 | ```js
|
150 | // karma.conf.js
|
151 | module.exports = function(config) {
|
152 | config.set({
|
153 | frameworks: ['jasmine'],
|
154 |
|
155 | // reporters configuration
|
156 | reporters: ['mocha'],
|
157 |
|
158 | // reporter options
|
159 | mochaReporter: {
|
160 | output: 'autowatch'
|
161 | }
|
162 | });
|
163 | };
|
164 | ```
|
165 |
|
166 | ### showDiff
|
167 | **Type:** String | Boolean
|
168 |
|
169 | Shows a diff output. Is disabled by default. All credits to the contributors of [mocha](https://github.com/mochajs/mocha), since the diff logic is used from there and customized for this module.
|
170 |
|
171 | ![screenshot](demo/diff.png)
|
172 |
|
173 | Currently only works with karma-mocha >= v0.2.2 Not supported for karma-jasmine since the additional properties needed to render the diff are not supported in jasmine yet.
|
174 |
|
175 | **Possible Values:**
|
176 |
|
177 | Value | Description
|
178 | ------ | -----------
|
179 | `true` | prints each diff in its own line, same as `'unified'`
|
180 | `'unified'` | prints each diff in its own line
|
181 | `'inline'` | prints diffs inline
|
182 |
|
183 | ```js
|
184 | // karma.conf.js
|
185 | module.exports = function(config) {
|
186 | config.set({
|
187 | frameworks: ['mocha', 'chai'],
|
188 |
|
189 | // reporters configuration
|
190 | reporters: ['mocha'],
|
191 |
|
192 | // reporter options
|
193 | mochaReporter: {
|
194 | showDiff: true
|
195 | }
|
196 | });
|
197 | };
|
198 | ```
|
199 |
|
200 | ### divider
|
201 | **Type:** String
|
202 |
|
203 | **Default:** 80 equals signs ('=')
|
204 |
|
205 | The string to output between multiple test runs. Set to `false` or empty string to disable
|
206 |
|
207 | ```js
|
208 | // karma.conf.js
|
209 | module.exports = function(config) {
|
210 | config.set({
|
211 | frameworks: ['jasmine'],
|
212 |
|
213 | // reporters configuration
|
214 | reporters: ['mocha'],
|
215 |
|
216 | // reporter options
|
217 | mochaReporter: {
|
218 | divider: ''
|
219 | }
|
220 | });
|
221 | };
|
222 | ```
|
223 |
|
224 | ### ignoreSkipped
|
225 | **Type:** Boolean
|
226 |
|
227 | **Possible Values:**
|
228 | * `false` (default)
|
229 | * `true`
|
230 |
|
231 | When setting the ignoreSkipped flag to true, the reporter will ignore the skipped tests in the output and you will see
|
232 | only the tests that where really executed. The summary will still contain the number of skipped tests.
|
233 |
|
234 | ### maxLogLines
|
235 | **Type:** Number
|
236 |
|
237 | Lets you set the maximum number of lines which are printed for a failure. The default value is 999. Helps to cut long stack traces.
|
238 | Set the value to `-1` to disable stack traces.
|
239 |
|
240 | ### printFirstSuccess
|
241 | **Type:** Boolean
|
242 |
|
243 | **Possible Values:**
|
244 | * `false` (default)
|
245 | * `true`
|
246 |
|
247 | Prints the result of an it block after it is run in one browser. This options is useful when you have tests which are conditionally run in one browser only.
|
248 | Otherwise the result of the it block would not be printed because it was not run in all browsers.
|
249 |
|
250 | ```js
|
251 | // testfile.spec.js
|
252 | if (navigator.userAgent.match(/firefox/i)) {
|
253 | describe('Firefox tests', function() {
|
254 | it('this would only be reported when printFirstSuccess is true', function() {
|
255 | console.log('firefox test');
|
256 | });
|
257 | });
|
258 | }
|
259 |
|
260 | describe('Other tests', function() {
|
261 | it('this should be always reported', function() {
|
262 | console.log('hello world');
|
263 | });
|
264 | });
|
265 | ```
|
266 |
|
267 |
|
268 | ## Contributing
|
269 | In lieu of a formal styleguide take care to maintain the existing coding style. Lint and test your code using [grunt](http://gruntjs.com/).
|
270 |
|
271 | You can preview your changes by running:
|
272 |
|
273 | $ npm run demo
|
274 |
|
275 | ## Author
|
276 | [Litixsoft GmbH](http://www.litixsoft.de)
|
277 |
|
278 | ## License
|
279 | Copyright (C) 2013-2017 Litixsoft GmbH <info@litixsoft.de>
|
280 | Licensed under the MIT license.
|
281 |
|
282 | Permission is hereby granted, free of charge, to any person obtaining a copy
|
283 | of this software and associated documentation files (the "Software"), to deal
|
284 | in the Software without restriction, including without limitation the rights
|
285 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
286 | copies of the Software, and to permit persons to whom the Software is
|
287 | furnished to do so, subject to the following conditions:
|
288 |
|
289 | The above copyright notice and this permission notice shall be included i
|
290 | all copies or substantial portions of the Software.
|
291 |
|
292 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
293 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
294 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
295 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
296 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
297 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
298 | THE SOFTWARE.
|