Skip to content

Instantly share code, notes, and snippets.

@nicokruger
Created February 23, 2012 07:44
Show Gist options
  • Save nicokruger/1891363 to your computer and use it in GitHub Desktop.
Save nicokruger/1891363 to your computer and use it in GitHub Desktop.
bgtest-runner-mocha-libnotify
var exec = require("child_process").exec,
spawn = require("child_process").spawn,
command = "mocha -R json tests/*-test.js",
_ = require("underscore");
var child = exec(command, function (error, stdout, stderr) {
var output, STATUS, ICON, status;
if (stderr) {
STATUS="BROKEN";
ICON="/usr/share/icons/gnome/32x32/actions/gtk-close.png";
output = "Command run failure: " + error + "\n" + stderr;
} else {
try {
var results = JSON.parse(stdout);
output = "<b>Failures: " + results.stats.failures + "</b>\n";
output += "Successes: " + results.stats.passes + "\n";
if (results.stats.failures > 0) {
STATUS="FAILURE";
ICON="/usr/share/icons/gnome/32x32/actions/gtk-close.png";
output += "\n\n<b>Failure details</b>\n-----------\n";
output += _(results.failures).map(function (f) { return f.fullTitle + "\n"; });
} else {
STATUS="Success";
ICON="/usr/share/icons/gnome/32x32/actions/add.png";
}
} catch (e) {
output = stdout;
STATUS="BROKEN";
ICON="/usr/share/icons/gnome/32x32/actions/gtk-close.png";
}
}
spawn("notify-send", [STATUS, output, "-i", ICON, "-t", "10000"]);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment