Skip to content

Commit

Permalink
add _growl() function override
Browse files Browse the repository at this point in the history
  • Loading branch information
BuonOmo committed Aug 15, 2017
1 parent 075bd51 commit a47d29a
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions browser-entry.js
Expand Up @@ -167,6 +167,40 @@ mocha.run = function (fn) {
});
};

/**
* Use HTML notifications instead of Growl
*/
Mocha.prototype._growl = mocha._growl = function (runner, reporter) {
runner.on('end', function () {
var stats = reporter.stats;
if (!('Notification' in window)) return;
var notification, title, msg;
if (stats.failures) {
title = 'Failed';
msg = stats.failures + ' of ' + runner.total + ' tests failed';
} else {
title = 'Passed';
msg = stats.passes + ' tests passed in ' + stats.duration + 'ms';
}
var options = { body: msg };
if (Notification.permission === 'granted') {
notification = new Notification(title, options);
} else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
if (permission === 'granted') {
notification = new Notification(title, options);
}
});
}
if (notification) {
notification.onclick = function () {
window.focus();
this.close();
};
}
});
};

/**
* Expose the process shim.
* https://github.com/mochajs/mocha/pull/916
Expand Down

0 comments on commit a47d29a

Please sign in to comment.