-
-
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 9 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
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 |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| 'use strict'; | ||
| /** | ||
| * @module Growl | ||
| */ | ||
|
|
||
| var fs = require('fs'); | ||
| var os = require('os'); | ||
| var path = require('path'); | ||
|
|
||
| /** | ||
| * @summary | ||
| * Checks if Growl support seems likely. | ||
| * | ||
| * @description | ||
| * Glosses over the distinction between an unsupported platform | ||
| * and one that lacks prerequisite software installations. | ||
| * Autofails when run in browser. | ||
| * | ||
| * @public | ||
| * @see {@link https://github.com/tj/node-growl/blob/master/README.md|Prerequisite Installs} | ||
| * @see {@link Mocha#growl} | ||
| * @see {@link Mocha#isGrowlCapable} | ||
| * @return {boolean} whether Growl support can be expected | ||
| */ | ||
| exports.isCapable = function() { | ||
| return !process.browser && which(getSupportBinaries()) !== ''; | ||
| }; | ||
|
|
||
| /** | ||
| * Implements desktop notifications as a pseudo-reporter. | ||
| * | ||
| * @public | ||
| * @see {@link Mocha#_growl} | ||
| * @param {Runner} runner - Runner instance. | ||
| */ | ||
| exports.notify = function(runner) { | ||
| var sendNotification = function() { | ||
| var growl = require('growl'); | ||
| var stats = runner.stats; | ||
| var msg; | ||
| var options; | ||
|
|
||
| if (stats.failures) { | ||
| msg = stats.failures + ' of ' + runner.total + ' tests failed'; | ||
| options = { | ||
| name: 'mocha', | ||
| title: 'Failed', | ||
| image: image('error') | ||
| }; | ||
| } else { | ||
| msg = stats.passes + ' tests passed in ' + stats.duration + 'ms'; | ||
| options = { | ||
| name: 'mocha', | ||
| title: 'Passed', | ||
| image: image('ok') | ||
| }; | ||
| } | ||
| growl(msg, options, onCompletion); | ||
| }; | ||
|
|
||
| /** | ||
| * @summary | ||
| * Callback for result of attempted Growl notification. | ||
| * | ||
| * @description | ||
| * Despite its appearance, this is <strong>not</strong> an Error-first | ||
| * callback -- all parameters are populated regardless of success. | ||
| * | ||
| * @callback Growl~growlCB | ||
| * @param {*} err - Error object, or <code>null</code> if successful. | ||
| * @param {string} stdout - <code>stdout</code> from notification delivery | ||
| * process. | ||
| * @param {string} stderr - <code>stderr</code> from notification delivery | ||
| * process. It will include timestamp and executed command with arguments. | ||
| */ | ||
|
|
||
| function onCompletion(err, stdout, stderr) { | ||
| if (err) { | ||
| var detail = | ||
| err.code === 'ENOENT' ? 'prerequisite software not found' : err.message; | ||
| console.error('Growl notification error:', detail); | ||
| } | ||
| } | ||
|
|
||
| runner.once('end', sendNotification); | ||
| }; | ||
|
|
||
| /** | ||
| * Returns Growl image `name` path. | ||
| * | ||
| * @private | ||
| * @param {string} name - Basename of associated Growl image. | ||
| * @return {string} Pathname to Growl image | ||
| */ | ||
| function image(name) { | ||
| return path.join(__dirname, '..', 'assets', 'growl', name + '.png'); | ||
| } | ||
|
|
||
| /** | ||
| * @summary | ||
| * Locates a binary in the user's `PATH` environment variable. | ||
| * | ||
| * @description | ||
| * Takes a list of command names and searches the path for each executable | ||
| * file that would be run had these commands actually been invoked. | ||
| * | ||
| * @private | ||
| * @param {string[]} binaries - Names of binary files to search for. | ||
| * @return {string} absolute path of first binary found, or empty string if none | ||
| */ | ||
| function which(binaries) { | ||
| var paths = process.env.PATH.split(path.delimiter); | ||
|
|
||
| for (var n = 0, blen = binaries.length; n < blen; n++) { | ||
| var binary = binaries[n]; | ||
| var loc; | ||
| for (var i = 0, plen = paths.length; i < plen; i++) { | ||
| loc = path.join(paths[i], binary); | ||
| if (fs.existsSync(loc)) { | ||
| return loc; | ||
| } | ||
| } | ||
| } | ||
| return ''; | ||
| } | ||
|
|
||
| /** | ||
| * @summary | ||
| * Gets platform-specific Growl support binaries. | ||
| * | ||
| * @description | ||
| * Somewhat brittle dependency on `growl` package implementation, but it | ||
| * rarely changes. | ||
| * | ||
| * @private | ||
| * @see {@link https://github.com/tj/node-growl/blob/master/lib/growl.js#L28-L126|setupCmd} | ||
| * @return {string[]} names of Growl support binaries | ||
| */ | ||
| function getSupportBinaries() { | ||
| var binaries = { | ||
| Darwin: ['terminal-notifier', 'growlnotify'], | ||
| Linux: ['notify-send', 'growl'], | ||
| Windows_NT: ['growlnotify'] | ||
| }; | ||
| return binaries[os.type()] || []; | ||
plroebuck marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
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
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.