forked from petrbela/karma-osx-reporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
58 lines (49 loc) · 1.76 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 spawn = require('child_process').spawn;
var path = require('path');
var dbus = require('dbus-native');
var UbuntuReporter = function(helper, logger) {
var log = logger.create('reporter.ubuntu');
var notifications = null;
var notificationId = 0;
var sessionBus = dbus.systemBus();
sessionBus.getService('org.freedesktop.Notifications').getInterface(
'/org/freedesktop/Notifications',
'org.freedesktop.Notifications', function(err, service) {
notifications = service;
});
this.onBrowserComplete = function(browser) {
var results = browser.lastResult;
var time = helper.formatTimeInterval(results.totalTime);
var icon = null,
title = null,
message = null;
log.debug(results);
if (results.failed) {
icon = 'dialog-error';
title = util.format('FAILED - %s', browser.name);
message = util.format('%d/%d tests failed in %s.', results.failed, results.total, time);
}
else if (results.disconnected || results.error) {
icon = 'face-crying';
title = util.format('ERROR - %s', browser.name);
message = 'Test error';
}
else {
icon = 'emblem-default'; // Currently, this is a green tick mark. Didn't find better stock id.
title = util.format('PASSED - %s', browser.name);
message = util.format('%d tests passed in %s.', results.success, time);
}
if (notifications) {
notifications.Notify('', notificationId, icon, title, message, [], [], 5, function(err, id) {
notificationId = id;
});
} else {
log.info("Notification service not ready yet");
}
};
};
// PUBLISH DI MODULE
module.exports = {
'reporter:ubuntu': ['type', UbuntuReporter]
};