Skip to content

Commit

Permalink
add _growl() function override
Browse files Browse the repository at this point in the history
  • Loading branch information
Ulysse Buonomo committed Aug 15, 2017
1 parent 075bd51 commit ae9549e
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions browser-entry.js
Original file line number Diff line number Diff line change
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 ae9549e

Please sign in to comment.