-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
81 lines (69 loc) · 2.12 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
var dbus = require('dbus-native');
var sprintf = require("sprintf-js").sprintf;
var notifications = {
success: {
title: 'PASSED - %(browser.name)s',
body: '%(results.success)d tests passed in %(time)s.',
icon: 'dialog-information'
},
failed: {
title: 'FAILED - %(browser.name)s',
body: '%(results.failed)d/%(results.total)d tests failed in %(time)s.',
icon: 'dialog-warning'
},
error: {
title: 'ERROR - %(browser.name)s',
body: '',
icon: 'dialog-error'
}
};
var DBusReporter = function(helper, logger, config) {
var log = logger.create('reporter.dbus'),
// temporary notification function that will be
// overriden when DBus is initialized
notify = function() { log.warn("D-Bus has not been initialized yet."); },
prefix = config && config.prefix || '',
timeout = config && config.timeout || 5,
notifyOnlyFailures = config && config.notifyOnlyFailures || false;
dbus.sessionBus()
.getService('org.freedesktop.Notifications')
.getInterface(
'/org/freedesktop/Notifications',
'org.freedesktop.Notifications',
function(err, bus) {
notify = function(title, body, icon) {
if (prefix) {
title = prefix + ' - ' + title;
}
bus.Notify('Karma D-Bus reporter', 0, icon, title, body, [], [], timeout);
};
});
this.adapters = [];
this.onBrowserComplete = function(browser) {
var results = browser.lastResult,
data = {
browser: browser,
results: results,
time: helper.formatTimeInterval(results.totalTime)
},
message;
if (results.disconnected || results.error) {
message = notifications.error;
} else if (results.failed) {
message = notifications.failed;
} else {
if (notifyOnlyFailures) {
return;
}
message = notifications.success;
}
notify(
sprintf(message.title, data),
sprintf(message.body, data),
message.icon);
};
};
DBusReporter.$inject = ['helper', 'logger', 'config.dbusReporter'];
module.exports = {
'reporter:dbus': ['type', DBusReporter]
};