diff --git a/browser-entry.js b/browser-entry.js index 2d1aeecea5..83334d0b29 100644 --- a/browser-entry.js +++ b/browser-entry.js @@ -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 diff --git a/test/browser/notification.html b/test/browser/notification.html new file mode 100644 index 0000000000..fbee672109 --- /dev/null +++ b/test/browser/notification.html @@ -0,0 +1,26 @@ + + + Mocha + + + + + + + + + +
+ + + diff --git a/test/browser/notification.spec.js b/test/browser/notification.spec.js new file mode 100644 index 0000000000..7ab61a2a62 --- /dev/null +++ b/test/browser/notification.spec.js @@ -0,0 +1,7 @@ +'use strict'; + +describe('Notification', function () { + it('should ask for notification, or show a notification', function () { + assert(true); + }); +});