UNPKG

7.9 kBMarkdownView Raw
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
14The 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
24You can simply do it by:
25
26 $ npm install karma-mocha-reporter --save-dev
27
28## Configuration
29```js
30// karma.conf.js
31module.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
45Lets 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
49Value | 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
58module.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
84To disable the colors please use the `colors` option in the karma config.
85
86```js
87// karma.conf.js
88module.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
104Lets you overwrite the default symbols.
105
106**Possible Values:**
107
108Value | 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
117module.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
142Value | 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
151module.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
169Shows 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
173Currently 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
177Value | 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
185module.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
205The string to output between multiple test runs. Set to `false` or empty string to disable
206
207```js
208// karma.conf.js
209module.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
231When setting the ignoreSkipped flag to true, the reporter will ignore the skipped tests in the output and you will see
232only the tests that where really executed. The summary will still contain the number of skipped tests.
233
234### maxLogLines
235**Type:** Number
236
237Lets you set the maximum number of lines which are printed for a failure. The default value is 999. Helps to cut long stack traces.
238Set the value to `-1` to disable stack traces.
239
240### printFirstSuccess
241**Type:** Boolean
242
243**Possible Values:**
244 * `false` (default)
245 * `true`
246
247Prints 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.
248Otherwise 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
252if (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
260describe('Other tests', function() {
261 it('this should be always reported', function() {
262 console.log('hello world');
263 });
264});
265```
266
267
268## Contributing
269In lieu of a formal styleguide take care to maintain the existing coding style. Lint and test your code using [grunt](http://gruntjs.com/).
270
271You can preview your changes by running:
272
273 $ npm run demo
274
275## Author
276[Litixsoft GmbH](http://www.litixsoft.de)
277
278## License
279Copyright (C) 2013-2017 Litixsoft GmbH <info@litixsoft.de>
280Licensed under the MIT license.
281
282Permission is hereby granted, free of charge, to any person obtaining a copy
283of this software and associated documentation files (the "Software"), to deal
284in the Software without restriction, including without limitation the rights
285to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
286copies of the Software, and to permit persons to whom the Software is
287furnished to do so, subject to the following conditions:
288
289The above copyright notice and this permission notice shall be included i
290all copies or substantial portions of the Software.
291
292THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
293IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
294FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
295AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
296LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
297OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
298THE SOFTWARE.