Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
petrbela committed Jun 8, 2013
0 parents commit 2aa3ab4
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
node_modules
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
@@ -0,0 +1,3 @@
Please see the [Contributing to Karma] guide for information on contributing to this project.

[Contributing to Karma]: https://github.com/karma-runner/karma/blob/master/CONTRIBUTING.md
20 changes: 20 additions & 0 deletions LICENSE
@@ -0,0 +1,20 @@
The MIT License

Copyright (C) 2011-2013 Vojta Jína and contributors.

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.
12 changes: 12 additions & 0 deletions README.md
@@ -0,0 +1,12 @@
# karma-osx-reporter

> Reporter using Mac OS 10.8 Mountain Lion's Notification Center to display results.
Built on top of [node-osx-notifier] and based on [AvnerCohen's code].

For more information on Karma see the [homepage].


[node-osx-notifier]: https://github.com/azoff/node-osx-notifier
[AvnerCohen's code]: https://github.com/karma-runner/karma/commit/ffd48a7f9aa7bc9a27516393d4d592edc6b628f7
[homepage]: http://karma-runner.github.io
82 changes: 82 additions & 0 deletions index.js
@@ -0,0 +1,82 @@
//Manage notification center in osx
//Based on https://npmjs.org/package/node-osx-notifier
//Configuration sample:
// osxNotifications = {
// notify: true,
// host: "localhost", //Defaults to localhost
// port: 1337 //defaults to 1337
// };
var util = require('util');
var spawn = require('child_process').spawn;
var path = require('path');
var http = require('http');
var root = path.dirname(__dirname);
var osxNotifier = {};

var config_osx = {
host: "localhost",
port: 1337
}

var OSXReporter = function(helper, logger) {
var log = logger.create('reporter.osx');

// Start local server that will send messages to Notification Center
var center = spawn(path.join(root, "/node_modules/node-osx-notifier/lib/node-osx-notifier.js"), [config_osx.port, config_osx.host]);
log.debug("Notification center started..");
center.on('exit', function(code) {
log.info('node-osx-notifier exited with code ' + code);
});

this.adapters = [];

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

var str_request = null,
title = null,
message = null;

if (results.disconnected || results.error) {
str_request = 'fail';
title = util.format('ERROR - %s', browser.name);
message = 'Test error';
}
else if (results.failed) {
str_request = 'fail';
title = util.format('FAILED - %s', browser.name);
message = util.format('%d/%d tests failed in %s.', results.failed, results.total, time);
}
else {
str_request = 'pass';
title = util.format('PASSED - %s', browser.name);
message = util.format('%d tests passed in %s.', results.success, time);
}

var uri = '/' + str_request + "?title=" + encodeURIComponent(title) + "&message=" + encodeURIComponent(message);
var options = {
host: config_osx.host,
port: config_osx.port,
path: uri,
method: 'GET'
};

log.debug("Sending request to osx notification center.");

var req = http.request(options, null);

req.on('error', function(err) {
log.error('error: ' + err.message);
});

req.end();
};
};

OSXReporter.$inject = ['helper', 'logger'];

// PUBLISH DI MODULE
module.exports = {
'reporter:osx': ['type', OSXReporter]
};
27 changes: 27 additions & 0 deletions package.json
@@ -0,0 +1,27 @@
{
"name": "karma-osx-reporter",
"version": "0.0.1",
"description": "A Karma plugin. Report results with OSX Notification Center.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git://github.com/petrbela/karma-osx-reporter.git"
},
"keywords": [
"karma-plugin",
"reporter",
"osx",
"notification center"
],
"author": "Petr Bela <github@petrbela.com>",
"dependencies": {
"node-osx-notifier": ">= 0.1.0"
},
"peerDependencies": {
"karma": "~0.9"
},
"license": "MIT"
}

0 comments on commit 2aa3ab4

Please sign in to comment.