Skip to content

Commit

Permalink
allow node to print stacktrace
Browse files Browse the repository at this point in the history
  • Loading branch information
leetreveil committed Apr 2, 2013
1 parent 9b95892 commit aef46d0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 24 deletions.
46 changes: 22 additions & 24 deletions alltests.js
@@ -1,35 +1,33 @@
if (module == require.main) {

var spawn = require('child_process').spawn,
path = require('path');

var tests = ['test-fail.js', 'test-multinstance.js',
'test-namedtest.js', 'test-simple.js'];
var spawn = require('child_process').spawn;
var path = require('path');
var assert = require('assert');

testPassCount = 0;

for (var i=0; i < tests.length; i++) {
var test = tests[i];
var tests = {
'test-fail.js': 1,
'test-multinstance.js': 0,
'test-namedtest.js': 0,
'test-simple.js': 0,
'test-stacktrace': 8
};

for (var test in tests) {
var expectedRetCode = tests[test];
var testProcess = spawn(process.execPath, [path.join(__dirname, test)]);
testProcess.stdout.on('data', function(data) {

testProcess.stdout.on('data', function (data) {
process.stdout.write(data.toString());
});
testProcess.stderr.on('data', function(data) {

testProcess.stderr.on('data', function (data) {
process.stderr.write(data.toString());
});

testProcess.on('exit', function(code, signal) {
if (code === 0) { testPassCount++ };
});
(function (expectedRetCode) {
testProcess.on('exit', function (code, signal) {
assert.equal(expectedRetCode, code);
});
})(expectedRetCode);
}

process.once('exit', function(code, signal) {
if (testPassCount === 3) {
process.exit(0);
} else {
process.exit(1);
}
});
}
5 changes: 5 additions & 0 deletions test-stacktrace.js
@@ -0,0 +1,5 @@
var test = require('./testy')();
var assert = test.assert;
assert.equal(2, 3);


5 changes: 5 additions & 0 deletions testy.js
Expand Up @@ -17,6 +17,11 @@ process.once('exit', function (code) {
totalTestsRan += testies[i]._testsRan;
}

// if node process is already in an error state
// don't exit process manually. This allows
// exceptions to be printed to stderr.
if (code === 1) return;

if (totalExpectedTests === 0) process.exit(0);
process.exit((totalTestsRan === totalExpectedTests) ? 0 : 1);
})
Expand Down

0 comments on commit aef46d0

Please sign in to comment.