Skip to content

Commit

Permalink
Force nw process to end when tests fail.
Browse files Browse the repository at this point in the history
* `gui.App.crashRenderer` does not end the NW.js app, causing `ember nw:test` to hang
* Also update nw-runner to not swallow diagnostic lines (even though they don't appear in the final output--something to investigate)
  • Loading branch information
brzpegasus committed Apr 16, 2015
1 parent 61d5697 commit 904333d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
25 changes: 15 additions & 10 deletions blueprints/node-webkit/files/nw-runner.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
var exec = require('child_process').exec;
var findNw = require('./node_modules/ember-cli-node-webkit/lib/helpers/find-nw');

runNw(findNw({
root: './'
}));

function runNw(nwPath) {
var nw = exec(nwPath + ' ./dist/tests');
nw.stdout.on('data', function (data) {
var hasErrors = false;

nw.stdout.on('data', function(data) {
process.stdout.write(data);
});

// Cleanup nw.js output to be TAP (test anything protocol) compliant
nw.stderr.on('data', function (data) {
nw.stderr.on('data', function(data) {
if (data.indexOf('[qunit-logger]') > -1) {
data = data.replace(/\[.*\] /g, "");
data = data.replace(/\, source.*/g, "");
data = data.replace(/\"/g, "");
data = data.replace('[qunit-logger] ', '');
console.log(data);
data = data.replace(/.*\[qunit-logger] (.*)"", source:.*/g, '$1');
data = data.replace(/\\n/g, '\n# ');
process.stdout.write(data);

if (data === '# done with errors') {
hasErrors = true;
}
}
});

nw.on('exit', function (code) {
setTimeout(function () {
process.exit(code);
nw.on('exit', function(code) {
setTimeout(function() {
process.exit(hasErrors ? 1 : code);
}, 2000);
});
}
21 changes: 8 additions & 13 deletions blueprints/node-webkit/files/vendor/node-webkit/qunit-logger.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/* global define */
/* global window */
/* global QUnit */
/* global define, window, QUnit */
// dead stupid script to format test output from nw.js to the console
define('vendor/node-webkit/qunit-logger', function () {
function log(content) {
Expand All @@ -14,6 +12,7 @@ define('vendor/node-webkit/qunit-logger', function () {
var totalTestCount = 0;
var testCount = 0;
var tests = {};

QUnit.begin(function (details) {
if (details.totalTests >= 1) {
totalTestCount = details.totalTests;
Expand All @@ -32,13 +31,15 @@ define('vendor/node-webkit/qunit-logger', function () {
QUnit.log(function (details) {
if (details.result !== true) {
var actualTestCount = testCount + 1;

log('not ok ' + actualTestCount + ' - ' + details.module + ' - ' + details.name);
log('# actual: -');
log('# ' + details.actual);
log('# expected: -');
log('# ' + details.expected);
log('# message: -');
log('# ' + details.message);

if (details.source) {
log('# ' + details.source);
}
Expand All @@ -50,14 +51,8 @@ define('vendor/node-webkit/qunit-logger', function () {
}
});

QUnit.done(function (details) {
var gui = require('nw.gui');
if (details.failed === 0) {
// quit with no error
gui.App.quit();
} else {
// fail out
gui.App.crashRenderer();
}
QUnit.done(function(details) {
log('# done' + (details.failed === 0 ? '' : ' with errors'));
require('nw.gui').App.quit();
});
})();
});

0 comments on commit 904333d

Please sign in to comment.