Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Cataldo committed Jul 16, 2014
0 parents commit e383b8b
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License

Copyright (C) 2011-2013 Google, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# karma-notify-reporter

> Report test results using OSX Notification Center, [Growl](http://growl.info/) or notify-send.
Built on top of [node-notifier](https://github.com/mikaelbr/node-notifier).

By default Notification Center will be used on Mac, notify-send will be used on Linux, and Growl will be used if neither Mac 10.8 or Linux.

## Installation

```js
npm install karma-notify-reporter --save-dev
```

###

## Configuration
```js
// karma.conf.js
module.exports = function(config) {
config.set({
reporters: ['progress', 'notify'],

// Optional Settings
notifyReporter: {
reportEachFailure: true, // Default: false, Will notify on every failed sepc
reportSuccess: false, // Default: true, Will notify when a suite was successful
}
});
};
```

You can pass list of reporters as a CLI argument too:
```bash
karma start --reporters notify,dots
```
Binary file added images/error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/failed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/success.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
84 changes: 84 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
var Notification = require('node-notifier'),
util = require('util'),
path = require('path');

var messages = {
success : {
displayName : 'Success',
title : 'PASSED - %s',
message : '%d tests passed in %s.',
icon : path.join(__dirname, 'images/success.png')
},
failed : {
displayName : 'Failure',
title : 'FAILED - %s',
message : '%d/%d tests failed in %s.',
icon : path.join(__dirname, 'images/failed.png')
},
error : {
displayName : 'Aborted',
title : 'ERROR - %s',
message : '',
icon : path.join(__dirname, 'images/error.png')
},
specFailed : {
displayName : 'Spec Failure',
title : 'Spec Failed - %s',
message : '%s',
icon : path.join(__dirname, 'images/failed.png')
}
};


var NotifyReporter = function(baseReporterDecorator, helper, logger, config, formatError) {
var log = logger.create('reporter.notify'),
reporterConfig = config.notifyReporter || {},
reportSuccess = typeof reporterConfig.reportSuccess !== 'undefined' ? reporterConfig.reportSuccess : true,
reportEachFailure = typeof reporterConfig.reportEachFailure !== 'undefined' ? reporterConfig.reportEachFailure : true,
notifier = new Notification(),
msg;

baseReporterDecorator(this);

this.adapters = [];

this.onBrowserComplete = function(browser) {
var results = browser.lastResult,
time = helper.formatTimeInterval(results.totalTime);

if (results.disconnected || results.error) {
msg = messages.error;
return notifier.notify(helper.merge(messages.error, {'title': util.format(msg.title, browser.name)}));
}

if (results.failed) {
msg = messages.failed;
return notifier.notify(helper.merge(msg, {'message': util.format(msg.message, results.failed, results.total, time), 'title': util.format(msg.title, browser.name)}));
}

if(reportSuccess) {
msg = messages.success;
notifier.notify(helper.merge(msg, {'message': util.format(msg.message, results.success, time), 'title': util.format(msg.title, browser.name)}));
}
};

if (reporterConfig.reportEachFailure){
this.specFailure = function(browser, result) {
var specName = result.suite.join(' ') + ' ' + result.description,
message = util.format('%s: FAILED\n', specName);

result.log.forEach(function(log) {
message += formatError(log, '\t');
});

msg = messages.specFailed;
notifier.notify(helper.merge(msg, {'message': util.format(msg.message, message), 'title': util.format(msg.title, browser.name)}));
};
}
};

NotifyReporter.$inject = ['baseReporterDecorator', 'helper', 'logger', 'config', 'formatError'];

module.exports = {
'reporter:notify': ['type', NotifyReporter]
};
30 changes: 30 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "karma-notify-reporter",
"version": "0.1.0",
"description": "A Karma plugin. Report results with OSX Notification Center, Growl or notify-send.",
"author": "Justin Cataldo <jdcataldo@gmail.com>",
"main": "index.js",
"repository": {
"type": "git",
"url": "git://github.com/jdcataldo/karma-notify-reporter.git"
},
"bugs": {
"url": "http://github.com/jdcataldo/karma-notify-reporter/issues",
"email": "jdcataldo@gmail.com"
},
"keywords": [
"karma-plugin",
"karma-reporter",
"osx",
"notification center",
"growl",
"notify-send"
],
"dependencies": {
"node-notifier": "^3.0.6"
},
"peerDependencies": {
"karma": ">=0.9"
},
"license": "MIT"
}

0 comments on commit e383b8b

Please sign in to comment.