-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
75 lines (65 loc) · 2.84 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
var notifier = require('node-notifier');
var interpolate = require('interpolate');
var NotifyPlugin = function () {
this.passCount = 0;
this.failCount = 0;
this.browserName = '';
this.defaults = {
notifier: 'notificationcenter',
success: {
title: 'Success',
message: 'All {passed} e2e test(s) have passed on {browser}',
icon: __dirname + '/assets/pass.png'
},
fail: {
title: 'Fail',
message: '{failed} e2e test(s) have failed on {browser}',
icon: __dirname + '/assets/fail.png'
},
subtitle: 'E2E',
sound: false,
wait: false,
notifyOnErrorOnly: false
}
};
NotifyPlugin.prototype.postTest = function (passed, info) {
passed ? this.passCount++ : this.failCount++;
var me = this;
browser.getCapabilities().then(function (capabilities) {
me.browserName = capabilities.get('browserName');
});
return;
};
NotifyPlugin.prototype.teardown = function () {
var Notification = require('node-notifier/notifiers/' + (this.config.notifier || this.defaults.notifier));
var notification = {
message: '',
title: '',
sound: this.config.sound !== undefined ? this.config.sound : this.defaults.sound,
subtitle: this.config.subtitle || this.defaults.subtitle,
wait: this.config.wait || this.defaults.wait
}
if (this.failCount === 0) {
var title = (this.config.success || {}).title || this.defaults.success.title;
var message = (this.config.success || {}).message || this.defaults.success.message;
notification.message = interpolate(message, {passed: this.passCount, failed: this.failCount, browser: this.browserName});
notification.title = interpolate(title, {passed: this.passCount, failed: this.failCount, browser: this.browserName});
notification.icon = (this.config.success || {}).icon || this.defaults.success.icon;
} else {
var title = (this.config.fail || {}).title || this.defaults.fail.title;
var message = (this.config.fail || {}).message || this.defaults.fail.message;
notification.message = interpolate(message, {passed: this.passCount, failed: this.failCount, browser: this.browserName});
notification.title = interpolate(title, {passed: this.passCount, failed: this.failCount, browser: this.browserName});
notification.icon = (this.config.fail || {}).icon || this.defaults.fail.icon;
}
if ((this.config.notifyOnErrorOnly === true || this.defaults.notifyOnErrorOnly)) {
if (this.failCount > 0) {
new Notification(this.config.options || {}).notify(notification);
}
} else {
new Notification(this.config.options || {}).notify(notification);
}
return;
};
var notifyPlugin = new NotifyPlugin();
module.exports = notifyPlugin;