Skip to content

Commit

Permalink
[test] Implement basic runner for multiple tests
Browse files Browse the repository at this point in the history
Features:

  * timeout
  * running tests in separate processes
  * printing basic summary
  • Loading branch information
mmalecki committed Dec 18, 2011
1 parent 2ccc5c7 commit a4079c6
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions test/core/run
@@ -0,0 +1,71 @@
#!/usr/bin/env node
/*
run.js: test runner for core tests
Copyright (c) 2011 Nodejitsu
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.
*/

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

var testTimeout = 15000;
var results = {};

function runTest(test, callback) {
var child = spawn(path.join(__dirname, 'run-single'), [ test ]);

var killTimeout = setTimeout(function () {
child.kill();
console.log(test.yellow + ' timed out'.red);
}, testTimeout);

child.on('exit', function (exitCode) {
clearTimeout(killTimeout);

console.log(test.yellow + ' exited with ' +
((exitCode) ? exitCode.toString().red : exitCode.toString().green));
results[test] = { exitCode: exitCode };
callback();
//
// We don't want tests to be stopped after first failure, and that's what
// async does when it receives truthy value in callback.
//
});
};

var tests = process.argv.slice(2);
async.forEachSeries(tests, runTest, function () {
var failed = [], ok = [];
for (var test in results) {
(results[test].exitCode != 0 ? failed : ok).push(test);
}

console.log('\nSummary:');
console.log((' ' + failed.length + '\tfailed tests').red);
console.log((' ' + ok.length + '\tpassed tests').green);
});

// vim:filetype=javascript

0 comments on commit a4079c6

Please sign in to comment.