forked from karma-runner/karma-growl-reporter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
58 lines (46 loc) · 1.51 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
var util = require('util');
var growl = require('growl');
var path = require('path');
var MSG_SUCCESS = '%d tests passed in %s.';
var MSG_FAILURE = '%d/%d tests failed in %s.';
var MSG_ERROR = '';
var OPTIONS = {
success: {
title: 'PASSED - %s',
image: path.join(__dirname, 'images/success.png')
},
failed: {
title: 'FAILED - %s',
image: path.join(__dirname, 'images/failed.png')
},
error: {
title: 'ERROR - %s',
image: path.join(__dirname, 'images/error.png')
}
};
var GrowlReporter = function(helper, logger, config) {
var log = logger.create('reporter.growl');
var optionsFor = function(type, browser) {
var prefix = config && config.prefix ? config.prefix : '';
return helper.merge(OPTIONS[type], {title: prefix + util.format(OPTIONS[type].title, browser)});
};
this.adapters = [];
this.onBrowserComplete = function(browser) {
var results = browser.lastResult;
var time = helper.formatTimeInterval(results.totalTime);
if (results.disconnected || results.error) {
return growl(MSG_ERROR, optionsFor('error', browser.name));
}
if (results.failed) {
return growl(util.format(MSG_FAILURE, results.failed, results.total, time),
optionsFor('failed', browser.name));
}
growl(util.format(MSG_SUCCESS, results.success, time), optionsFor('success',
browser.name));
};
};
GrowlReporter.$inject = ['helper', 'logger','config.growlReporter'];
// PUBLISH DI MODULE
module.exports = {
'reporter:growl': ['type', GrowlReporter]
};