Coverage

48%
177
85
92

/home/ubuntu/src/github.com/dalekjs/dalek-reporter-console/index.js

100%
44
44
0
LineHitsSource
1/*!
2 *
3 * Copyright (c) 2013 Sebastian Golasch
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 */
24
251'use strict';
26
27// int. globals
281var reporter = null;
29
30/**
31 * Daleks basic reporter, all the lovely colors & symbols you see when running dalek.
32 * The reporter will be installed by default.
33 *
34 * If you would like to use the reporter in addition to another one,
35 * you can start dalek with a special command line argument
36 *
37 * ```bash
38 * $ dalek your_test.js -r console,junit
39 * ```
40 *
41 * or you can add it to your Dalekfile
42 *
43 * ```javascript
44 * "reporter": ["console", "junit"]
45 * ```
46 *
47 * @class Reporter
48 * @constructor
49 * @part Console
50 * @api
51 */
52
531var Reporter = function (opts) {
541 var loglevel = opts && opts.logLevel ? parseInt(opts.logLevel, 10) : 1;
551 this.level = (loglevel >= -1 && loglevel <= 5) ? loglevel : 1;
561 this.events = opts.events;
57
58 // set color & symbols flags
591 this.noColor = opts.config.config.noColors;
601 this.noSymbols = opts.config.config.noSymbols;
61
621 this.importLogModule();
631 this.startListening();
64};
65
66/**
67 * @module Reporter
68 */
69
701module.exports = function (opts) {
711 if (reporter === null) {
721 reporter = new Reporter(opts);
73 }
74
751 return reporter;
76};
77
781Reporter.prototype = {
79
80 /**
81 * Imports an output module with the correct log state
82 *
83 * @method importLogModule
84 * @param {object} data
85 * @chainable
86 */
87
88 importLogModule: function () {
891 var logModule = require('./lib/levelbase');
901 if (this.level !== -1) {
911 logModule = require('./lib/loglevel/level' + this.level);
92 }
93
941 var methods = Object.keys(logModule.prototype);
95
961 methods.forEach(function (method) {
9719 this[method] = logModule.prototype[method];
98 }.bind(this));
991 return this;
100 },
101
102 /**
103 * Connects to all the event listeners
104 *
105 * @method startListening
106 * @param {object} data
107 * @chainable
108 */
109
110 startListening: function () {
111 // assertion & action status
1121 this.events.on('report:assertion', this.outputAssertionResult.bind(this));
1131 this.events.on('report:assertion:status', this.outputAssertionExpectation.bind(this));
1141 this.events.on('report:action', this.outputAction.bind(this));
115
116 // test status
1171 this.events.on('report:test:finished', this.outputTestFinished.bind(this));
1181 this.events.on('report:test:started', this.outputTestStarted.bind(this));
119
120 // runner status
1211 this.events.on('report:runner:started', this.outputRunnerStarted.bind(this));
1221 this.events.on('report:runner:finished', this.outputRunnerFinished.bind(this));
123
124 // session & browser status
1251 this.events.on('report:run:browser', this.outputRunBrowser.bind(this));
1261 this.events.on('report:driver:status', this.outputOSVersion.bind(this));
1271 this.events.on('report:driver:session', this.outputBrowserVersion.bind(this));
128
129 // remote connections
1301 this.events.on('report:remote:ready', this.remoteConnectionReady.bind(this));
1311 this.events.on('report:remote:established', this.remoteConnectionEstablished.bind(this));
1321 this.events.on('report:remote:closed', this.remoteConnectionClosed.bind(this));
133
134 // logs
1351 this.events.on('report:log:system', this.outputLogUser.bind(this, 'system'));
1361 this.events.on('report:log:driver', this.outputLogUser.bind(this, 'driver'));
1371 this.events.on('report:log:browser', this.outputLogUser.bind(this, 'browser'));
1381 this.events.on('report:log:user', this.outputLogUser.bind(this, 'user'));
1391 this.events.on('report:log:system:webdriver', this.outputLogUser.bind(this, 'webdriver'));
140
141 // errors & warnings
1421 this.events.on('error', this.outputError.bind(this));
1431 this.events.on('warning', this.outputWarning.bind(this));
144
145 // reports
1461 this.events.on('report:written', this.outputReportWritten.bind(this));
147
1481 return this;
149 }
150};
151

/home/ubuntu/src/github.com/dalekjs/dalek-reporter-console/lib/levelbase.js

29%
82
24
58
LineHitsSource
1/*!
2 *
3 * Copyright (c) 2013 Sebastian Golasch
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 */
24
251'use strict';
26
27// ext. libs
281var clc = require('cli-color');
29
30/**
31 * @class LevelBase
32 * @constructor
33 * @param {object} opts
34 */
35
361var LevelBase = function (opts) {
370 this.noColor = !!(opts && opts.noColor);
380 this.noSymbols = !!(opts && opts.noSymbols);
39};
40
41/**
42 * @module LevelBase
43 */
44
451module.exports = LevelBase;
46
47/**
48 * Outputs a string
49 *
50 * @method outputTestStarted
51 * @param {object} data
52 * @chainable
53 */
54
551LevelBase.prototype.echo = function (message, options) {
560 options = options || {};
570 var nl = options.nl === false ? '' :'\n';
580 var coloredOutput = clc;
590 message = options.ec === true ? message + ' ' : message;
60
61 // should a newline be outputted before the current message
620 if (options.pnl) {
630 console.log('');
64 }
65
66 // output a message without any colors
670 if (this.noColor) {
680 process.stdout.write(message + nl);
690 return this;
70 }
71
72 // check if we have a foreground color, then apply
730 if (options.foreground) {
740 coloredOutput = coloredOutput[options.foreground];
75 }
76
77 // check if we have a font style, then apply
780 if (options.style) {
790 coloredOutput = coloredOutput[options.style];
80 }
81
82 // check if we have a background color, then apply
830 if (options.background) {
840 coloredOutput = coloredOutput[options.background];
85 }
86
87 // check if we need to indent the string
880 if (options.indent) {
890 var indention = 0;
900 for (var i = 0; i <= indention; i++) {
910 indention += ' ';
92 }
930 message = indention + message;
94 }
95
96 // output the message
970 process.stdout.write(coloredOutput(message + nl));
980 return this;
99};
100
101/**
102 * Outputs a symbol
103 *
104 * @method outputTestStarted
105 * @param {object} data
106 * @return {string} symbol
107 */
108
1091LevelBase.prototype.symbol = function (symbol) {
1100 if (this.noSymbols || process.platform === 'win32') {
1110 return symbol;
112 }
113
114 // switch to a nicer UTF-8 symbol
1150 switch (symbol) {
116 case '*':
1170 symbol = '✔';
1180 break;
119 case 'x':
1200 symbol = '✘';
1210 break;
122 case '>':
1230 symbol = '▶';
1240 break;
125 case '->':
1260 symbol = '↝';
1270 break;
128 case '>>':
1290 symbol = '>>';
1300 break;
131 case '<>':
1320 symbol = '☁';
1330 break;
134 }
135
1360 return symbol;
137};
138
139/**
140 * Does nothing
141 *
142 * @method outputRunnerStarted
143 * @param {object} data
144 * @chainable
145 */
146
1471LevelBase.prototype.outputRunnerStarted = function () {
1480 return this;
149};
150
151/**
152 * Does nothing
153 *
154 * @method outputTestFinished
155 * @param {object} data
156 * @chainable
157 */
158
1591LevelBase.prototype.outputTestFinished = function () {
1600 return this;
161};
162
163/**
164 * Does nothing
165 *
166 * @method outputRunnerFinished
167 * @param {object} data
168 * @chainable
169 */
170
1711LevelBase.prototype.outputRunnerFinished = function () {
1720 return this;
173};
174
175/**
176 * Does nothing
177 *
178 * @method outputAssertionResult
179 * @param {object} data
180 * @chainable
181 */
182
1831LevelBase.prototype.outputAssertionResult = function () {
1840 return this;
185};
186
187/**
188 * Does nothing
189 *
190 * @method outputRunBrowser
191 * @param {object} browser
192 * @chainable
193 */
194
1951LevelBase.prototype.outputRunBrowser = function () {
1960 return this;
197};
198
199/**
200 * Does nothing
201 *
202 * @method outputAction
203 * @chainable
204 */
205
2061LevelBase.prototype.outputAction = function () {
2070 return this;
208};
209
210/**
211 * Does nothing
212 *
213 * @method outputAssertionExpectation
214 * @param {object} data
215 * @chainable
216 */
217
2181LevelBase.prototype.outputAssertionExpectation = function () {
2190 return this;
220};
221
222/**
223 * Does nothing
224 *
225 * @method outputAction
226 * @param {object} data
227 * @chainable
228 */
229
2301LevelBase.prototype.outputAction = function () {
2310 return this;
232};
233
234/**
235 * Does nothing
236 *
237 * @method outputTestStarted
238 * @param {object} data
239 * @chainable
240 */
241
2421LevelBase.prototype.outputTestStarted = function () {
2430 return this;
244};
245
246/**
247 * Does nothing
248 *
249 * @method outputLogUser
250 * @param {object} data
251 * @chainable
252 */
253
2541LevelBase.prototype.outputLogUser = function () {
2550 return this;
256};
257
258/**
259 * Does nothing
260 *
261 * @method outputBrowserVersion
262 * @param {object} data
263 * @chainable
264 */
265
2661LevelBase.prototype.outputBrowserVersion = function () {
2670 return this;
268};
269
270/**
271 * Does nothing
272 *
273 * @method outputOSVersion
274 * @param {object} data
275 * @chainable
276 */
277
2781LevelBase.prototype.outputOSVersion = function () {
2790 return this;
280};
281
282/**
283 * Does nothing
284 *
285 * @method outputReportWritten
286 * @param {object} data
287 * @chainable
288 */
289
2901LevelBase.prototype.outputReportWritten = function () {
2910 return this;
292};
293
294/**
295 * Does nothing
296 *
297 * @method outputWarning
298 * @param {object} data
299 * @chainable
300 */
301
3021LevelBase.prototype.outputWarning = function () {
3030 return this;
304};
305
306/**
307 * Does nothing
308 *
309 * @method outputError
310 * @param {object} data
311 * @chainable
312 */
313
3141LevelBase.prototype.outputError = function () {
3150 return this;
316};
317
318/**
319 * Does nothing
320 *
321 * @method remoteConnectionEstablished
322 * @param {object} data
323 * @chainable
324 */
325
3261LevelBase.prototype.remoteConnectionEstablished = function () {
3270 return this;
328};
329
330/**
331 * Does nothing
332 *
333 * @method remoteConnectionClosed
334 * @param {object} data
335 * @chainable
336 */
337
3381LevelBase.prototype.remoteConnectionClosed = function () {
3390 return this;
340};
341
342/**
343 * Does nothing
344 *
345 * @method remoteConnectionReady
346 * @param {object} data
347 * @chainable
348 */
349
3501LevelBase.prototype.remoteConnectionReady = function () {
3510 return this;
352};
353

/home/ubuntu/src/github.com/dalekjs/dalek-reporter-console/lib/loglevel/level0.js

100%
4
4
0
LineHitsSource
1/*!
2 *
3 * Copyright (c) 2013 Sebastian Golasch
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 */
24
251'use strict';
26
27// int. libs
281var Log = require('../levelbase');
29
30/**
31 * @class LogLevel0
32 * @constructor
33 * @param {object} opts
34 */
35
361var LogLevel0 = Log;
37
38/**
39 * @module LogLevel0
40 */
41
421module.exports = LogLevel0;
43

/home/ubuntu/src/github.com/dalekjs/dalek-reporter-console/lib/loglevel/level1.js

27%
47
13
34
LineHitsSource
1/*!
2 *
3 * Copyright (c) 2013 Sebastian Golasch
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 */
24
251'use strict';
26
27// int. libs
281var Log = require('./level0');
29
30/**
31 * @class LogLevel1
32 * @constructor
33 * @param {object} opts
34 */
35
361var LogLevel1 = Log;
37
38/**
39 * @module LogLevel1
40 */
41
421module.exports = LogLevel1;
43
44/**
45 * Outputs a browser or user log message
46 *
47 * @method outputLogUser
48 * @param {string} type
49 * @param {string} message
50 * @chainable
51 */
52
531LogLevel1.prototype.outputLogUser = function (type, message) {
540 if (type === 'browser' || type === 'user') {
550 this.echo(this.symbol('<>'), {nl: false, ec: true, foreground: 'cyan'});
560 this.echo('[' + type.toUpperCase() + ']', {nl: false, foreground: 'whiteBright', background: 'bgCyanBright'});
570 this.echo(' ' + message, {foreground: 'cyan'});
58 }
590 return this;
60};
61
62/**
63 * Outputs a message when the testrunner starts
64 *
65 * @method outputRunnerStarted
66 * @return {LogLevel1}
67 */
68
691LogLevel1.prototype.outputRunnerStarted = function () {
700 this.echo('Running tests', {foreground: 'magentaBright'});
710 return this;
72};
73
74/**
75 * Outputs a message when a test is finished
76 *
77 * @method outputTestFinished
78 * @param {object} data
79 * @return {LogLevel1}
80 */
81
821LogLevel1.prototype.outputTestFinished = function (data) {
830 this.echo('.', {nl: false, foreground: (data.status ? 'greenBright' : 'redBright')});
840 return this;
85};
86
87/**
88 * Outputs a message when an error occurs
89 *
90 * @method outputError
91 * @param {object} data
92 * @return {LogLevel1}
93 */
94
951LogLevel1.prototype.outputError = function (data) {
960 this.echo(this.symbol('>>') + ' ERROR:', {nl: false, ec: true, foreground: 'redBright'});
970 this.echo(String(data), {nl: true, foreground: 'redBright'});
980 return this;
99};
100
101/**
102 * Outputs a message when a warning occurs
103 *
104 * @method outputWarning
105 * @param {object} data
106 * @return {LogLevel1}
107 */
108
1091LogLevel1.prototype.outputWarning = function (data) {
1100 this.echo(this.symbol('>>') + ' WARNING:', {nl: false, ec: true, foreground: 'yellowBright'});
1110 this.echo(String(data), {nl: true, foreground: 'yellowBright'});
1120 return this;
113};
114
115/**
116 * Outputs a message when the testrunner has been finished
117 *
118 * @method outputRunnerFinished
119 * @param {object} data
120 * @return {LogLevel1}
121 */
122
1231LogLevel1.prototype.outputRunnerFinished = function (data) {
1240 var elapsedTime = data.elapsedTime;
1250 var timeOutput = '';
126
127 // generate formatted time output
1280 if (elapsedTime.hours > 0) {
1290 timeOutput += elapsedTime.hours + ' hrs ';
130 }
131
1320 if (elapsedTime.minutes > 0) {
1330 timeOutput += elapsedTime.minutes + ' min ';
134 }
135
1360 timeOutput += Math.round(elapsedTime.seconds * Math.pow(10, 2)) / Math.pow(10, 2) + ' sec';
137
138 // newline FTW!
1390 this.echo('', {nl: true});
140
141 // echo the assertion & time status
1420 this.echo(' ' +
143 data.assertionsPassed + '/' + data.assertions + ' assertions passed.' + ' Elapsed Time: ' + timeOutput + ' ',
144 {foreground: (data.status ? 'black' : 'whiteBright'), background: (data.status ? 'bgGreenBright' : 'bgRedBright')}
145 );
1460 return this;
147};
148
149/**
150 * Outputs a message when the remote connection has been established
151 *
152 * @method remoteConnectionEstablished
153 * @param {object} data
154 * @chainable
155 */
156
1571LogLevel1.prototype.remoteConnectionReady = function (data) {
1580 this.echo('Remote connection is ready on IP:', {nl: false, ec: true, foreground: 'magentaBright'});
1590 this.echo(data.ip + ':' + data.port, {foreground: 'yellowBright'});
1600 return this;
161};
162
163/**
164 * Outputs a message when the remote connection has been established
165 *
166 * @method remoteConnectionEstablished
167 * @param {object} data
168 * @chainable
169 */
170
1711LogLevel1.prototype.remoteConnectionEstablished = function (data) {
1720 this.echo('Starting session:', {nl: false, ec: true, foreground: 'greenBright'});
1730 this.echo(data.browser + ':' + data.id, {foreground: 'cyanBright'});
1740 return this;
175};
176
177/**
178 * Outputs a message when the remote connection has been closed
179 *
180 * @method remoteConnectionClosed
181 * @param {object} data
182 * @chainable
183 */
184
1851LogLevel1.prototype.remoteConnectionClosed = function (data) {
1860 this.echo('Closing session:', {nl: false, ec: true, foreground: 'greenBright'});
1870 this.echo(data.browser + ':' + data.id, {foreground: 'cyanBright'});
1880 return this;
189};
190