-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Growl: Web notifications & Desktop prerequisite software check #3542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
e2204c1
feat(Growl): Check notification support _before_ use!
plroebuck b9e557f
docs(growl.js): Correct access level of `notify` method [skip ci]
plroebuck 1902023
docs(growl.js,mocha.js): Minor changes to improve specificity [skip ci]
plroebuck 08ec0a8
docs(mocha.js): Remove unneeded JSDoc tag [skip ci]
plroebuck ddeca7e
refactor(growl.js): Simplify completion callback error reporting
plroebuck 9b0907a
refactor(growl.js): Change event listener style
plroebuck 64c09eb
test(unit/mocha.spec.js): Convert `context` to `describe`
plroebuck 4773475
refactor(lib/growl.js): Convert `switch` to KV lookup
plroebuck 8a16c9a
refactor(lib/growl.js): Remove `path.exists` anachronism
plroebuck da25205
docs(docs/index.md): Add Growl section to user guide [skip travis][sk…
plroebuck f81efdc
Merge branch 'master' into growl
plroebuck a5df791
docs(docs/index.md): Make markdownlint happy
plroebuck cfb1182
Merge branch 'growl' of https://github.com/plroebuck/mocha into growl
plroebuck 1271f8b
test(unit/mocha.spec.js): Minor tweaks to Growl-related tests
plroebuck c303f63
docs(docs/index.md): Updates to user guide for desktop notification s…
plroebuck 20dddf0
feat(lib/browser/growl.js): Added web notification support for `Mocha…
plroebuck f1c81af
feat(lib/growl.js): Updated notification appearance
plroebuck fb9b696
refactor(lib/mocha.js): Change `Mocha#growl` notification support err…
plroebuck c9a8d9b
build(browserify): Updated browserify settings to bundle web notifica…
plroebuck 519f2cd
docs(growl): Fix JSDoc module header
plroebuck b4ea1de
docs(docs/index.md): Unescape left tag delimmiters in HTML codefence
plroebuck 7e7a67c
docs(user guide): Minor wordsmithing [skip travis][skip appveyor]
plroebuck 528437a
docs(user guide): Make HTML examples more similar
plroebuck a1dce65
ci(appveyor.yml): Change URL for GrowlForWindows (GfW)
plroebuck 3fe39c1
Merge branch 'master' into growl
plroebuck 81c21da
Merge branch 'master' into growl
plroebuck 63ca450
build(scripts/package-json-cullify.js): Renamed browserify-related sc…
plroebuck 52b3f03
refactor(browser/growl.js): Adapt code to recommendations following r…
plroebuck 8616d25
Merge branch 'growl' of https://github.com/plroebuck/mocha into growl
plroebuck 2d73c2a
docs(docs/index.md): Update browser usage links to reference upcoming…
plroebuck f1a8db1
docs(browser/growl.js): Update JSDoc with minor tweaks
plroebuck 621a604
refactor(browser/growl.js): Flatten `isPermitted` ask() return value
plroebuck 372fab6
Merge branch 'master' into growl
plroebuck 1f06d4e
Merge branch 'master' into growl
plroebuck 8f72bfb
docs(docs/index.md): Update "unpkg.com" links to reference latest moc…
plroebuck fd7ea35
fix(lib/growl.js): Add file extension to Windows binary
plroebuck ba00cf8
chore(assets/mocha-logo-96.png): Add new resolution of PNG logo [ci s…
plroebuck e33da70
Merge branch 'growl' of https://github.com/plroebuck/mocha into growl
plroebuck 7348df2
refactor(lib/growl.js): Use 96px resolution logo for desktop notifica…
plroebuck a64c15b
refactor(browser/growl.js): Hardcode language and direction
plroebuck 30c9cd4
fix(browser/growl.js): Use notification logo
plroebuck ad2fad5
fix(package-scripts.js): Remove quotes around `dedefine` script
plroebuck dd8bc02
build(package.json): Add new property "notifyLogo"
plroebuck dbb2dfa
refactor(browser/growl.js): Remove notification tag generation
plroebuck 0f2f5b3
Merge branch 'master' into growl
plroebuck 20d1733
fix(browser/growl.js): Save timer references to avoid Sinon interfering
plroebuck 0688e93
Merge branch 'growl' of https://github.com/plroebuck/mocha into growl
plroebuck 5baeb00
docs(docs/index.md): Minor changes to documentation [ci skip]
plroebuck dd7bc9c
docs(browser/growl.js): Removed unnecessary JSDoc tag
plroebuck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,167 @@ | ||
| 'use strict'; | ||
|
|
||
| // just stub out growl | ||
| /** | ||
| * Web Notifications module. | ||
| * @module Growl | ||
| */ | ||
|
|
||
| module.exports = require('../utils').noop; | ||
| /** | ||
| * Save timer references to avoid Sinon interfering (see GH-237). | ||
| */ | ||
| var Date = global.Date; | ||
| var setTimeout = global.setTimeout; | ||
|
|
||
| /** | ||
| * Checks if browser notification support exists. | ||
| * | ||
| * @public | ||
| * @see {@link https://caniuse.com/#feat=notifications|Browser support (notifications)} | ||
| * @see {@link https://caniuse.com/#feat=promises|Browser support (promises)} | ||
| * @see {@link Mocha#growl} | ||
| * @see {@link Mocha#isGrowlCapable} | ||
| * @return {boolean} whether browser notification support exists | ||
| */ | ||
| exports.isCapable = function() { | ||
| var hasNotificationSupport = 'Notification' in window; | ||
| var hasPromiseSupport = typeof Promise === 'function'; | ||
| return process.browser && hasNotificationSupport && hasPromiseSupport; | ||
| }; | ||
|
|
||
| /** | ||
| * Implements browser notifications as a pseudo-reporter. | ||
| * | ||
| * @public | ||
| * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/notification|Notification API} | ||
| * @see {@link https://developers.google.com/web/fundamentals/push-notifications/display-a-notification|Displaying a Notification} | ||
| * @see {@link Growl#isPermitted} | ||
| * @see {@link Mocha#_growl} | ||
| * @param {Runner} runner - Runner instance. | ||
| */ | ||
| exports.notify = function(runner) { | ||
| var promise = isPermitted(); | ||
|
|
||
| /** | ||
| * Attempt notification. | ||
| */ | ||
| var sendNotification = function() { | ||
| // If user hasn't responded yet... "No notification for you!" (Seinfeld) | ||
| Promise.race([promise, Promise.resolve(undefined)]) | ||
plroebuck marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .then(canNotify) | ||
| .then(function() { | ||
| display(runner); | ||
| }) | ||
| .catch(notPermitted); | ||
| }; | ||
|
|
||
| runner.once('end', sendNotification); | ||
| }; | ||
|
|
||
| /** | ||
| * Checks if browser notification is permitted by user. | ||
| * | ||
| * @private | ||
| * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Notification/permission|Notification.permission} | ||
| * @see {@link Mocha#growl} | ||
| * @see {@link Mocha#isGrowlPermitted} | ||
| * @returns {Promise<boolean>} promise determining if browser notification | ||
| * permissible when fulfilled. | ||
| */ | ||
| function isPermitted() { | ||
| var permitted = { | ||
| granted: function allow() { | ||
| return Promise.resolve(true); | ||
plroebuck marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| denied: function deny() { | ||
| return Promise.resolve(false); | ||
| }, | ||
| default: function ask() { | ||
| return Notification.requestPermission().then(function(permission) { | ||
| return permission === 'granted'; | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| return permitted[Notification.permission](); | ||
| } | ||
|
|
||
| /** | ||
| * @summary | ||
| * Determines if notification should proceed. | ||
| * | ||
| * @description | ||
| * Notification shall <strong>not</strong> proceed unless `value` is true. | ||
| * | ||
| * `value` will equal one of: | ||
| * <ul> | ||
| * <li><code>true</code> (from `isPermitted`)</li> | ||
| * <li><code>false</code> (from `isPermitted`)</li> | ||
| * <li><code>undefined</code> (from `Promise.race`)</li> | ||
| * </ul> | ||
| * | ||
| * @private | ||
| * @param {boolean|undefined} value - Determines if notification permissible. | ||
| * @returns {Promise<undefined>} Notification can proceed | ||
| */ | ||
| function canNotify(value) { | ||
| if (!value) { | ||
| var why = value === false ? 'blocked' : 'unacknowledged'; | ||
| var reason = 'not permitted by user (' + why + ')'; | ||
| return Promise.reject(new Error(reason)); | ||
| } | ||
| return Promise.resolve(); | ||
| } | ||
|
|
||
| /** | ||
| * Displays the notification. | ||
| * | ||
| * @private | ||
| * @param {Runner} runner - Runner instance. | ||
| */ | ||
| function display(runner) { | ||
| var stats = runner.stats; | ||
| var symbol = { | ||
| cross: '\u274C', | ||
| tick: '\u2705' | ||
| }; | ||
| var logo = require('../../package').notifyLogo; | ||
| var _message; | ||
| var message; | ||
| var title; | ||
|
|
||
| if (stats.failures) { | ||
| _message = stats.failures + ' of ' + runner.total + ' tests failed'; | ||
| message = symbol.cross + ' ' + _message; | ||
| title = 'Failed'; | ||
| } else { | ||
| _message = stats.passes + ' tests passed in ' + stats.duration + 'ms'; | ||
| message = symbol.tick + ' ' + _message; | ||
| title = 'Passed'; | ||
| } | ||
|
|
||
| // Send notification | ||
| var options = { | ||
| badge: logo, | ||
| body: message, | ||
| dir: 'ltr', | ||
| icon: logo, | ||
| lang: 'en-US', | ||
| name: 'mocha', | ||
| requireInteraction: false, | ||
| timestamp: Date.now() | ||
| }; | ||
| var notification = new Notification(title, options); | ||
|
|
||
| // Autoclose after brief delay (makes various browsers act same) | ||
| var FORCE_DURATION = 4000; | ||
| setTimeout(notification.close.bind(notification), FORCE_DURATION); | ||
| } | ||
|
|
||
| /** | ||
| * As notifications are tangential to our purpose, just log the error. | ||
| * | ||
| * @private | ||
| * @param {Error} err - Why notification didn't happen. | ||
| */ | ||
| function notPermitted(err) { | ||
| console.error('notification error:', err.message); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.