Skip to content

Commit

Permalink
Added notification center support for osx systems
Browse files Browse the repository at this point in the history
clean up logs + commented code

Invoke notification center process if defined
  • Loading branch information
AvnerCohen committed Nov 1, 2012
1 parent 26a1e21 commit ffd48a7
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ var parseConfig = function(configFilePath, cliOptions) {
files: [],
exclude: [],
logLevel: constant.LOG_INFO,
osxNotifications: {
notify: false,
host: "localhost",
port: 1337
},
colors: true,
autoWatch: false,
reporters: ['progress'],
Expand Down
57 changes: 57 additions & 0 deletions lib/osx-notifier.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//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 log = require('./logger').create('osx-notifier');
var spawn = require('child_process').spawn;
var path = require('path');
var http = require('http');
var root = path.dirname(__dirname);
var osxNotifier = {};

var TITLE = "Testacular results";

osxNotifier.spawn = function(config_osx, globalEmitter) {
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);
});

globalEmitter.on('run_complete', function(browsers, results) {
notify(results, config_osx);
});

};

var notify = function(results, config_osx) {
var isFailed = ( results.exitCode !== 0 );
var str_request = isFailed ? 'fail' : 'pass';
var message = "Passed: " + results.success + "\nFailed: " + results.failed;
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();

};

exports.osxNotifier = osxNotifier;
6 changes: 6 additions & 0 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var Launcher = require('./launcher').Launcher;
var FileList = require('./file-list').List;
var watcher = require('./watcher');
var preprocessor = require('./preprocessor');
var osxNotifier = require('./osx-notifier').osxNotifier;


// TODO(vojta): get this whole mess under test
Expand Down Expand Up @@ -58,6 +59,11 @@ exports.start = function(cliOptions) {
if (config.browsers && config.browsers.length) {
launcher.launch(config.browsers, config.port, config.urlRoot, config.captureTimeout, 3);
}

if (config.osxNotifications && config.osxNotifications.notify){
osxNotifier.spawn(config.osxNotifications, globalEmitter);
};

});

var resultReporter = reporter.createReporters(config.reporters, config);
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"http-proxy": ">=0.8.2",
"optimist": ">= 0.3.4",
"coffee-script": ">= 1.3.3",
"xmlbuilder": ">= 0.4.2"
"xmlbuilder": ">= 0.4.2",
"node-osx-notifier": ">= 0.1.0"
},
"devDependencies": {
"jasmine-node": ">= 1.0.11",
Expand Down

0 comments on commit ffd48a7

Please sign in to comment.