refactored test execution to use makefile

integration tests all running in the same process were stepping on eachother. each test file is now run within its own node process
This commit is contained in:
Brian Carlson 2010-12-14 18:50:18 -06:00
parent f34470db41
commit af997d914b
3 changed files with 37 additions and 44 deletions

18
Makefile Normal file
View File

@ -0,0 +1,18 @@
SHELL := /bin/bash
user=postgres
password=1234
host=localhost
port=5432
database=postgres
test-unit:
@find test/unit -name "*-tests.js" | xargs -n 1 -I file node file
test-integration:
@find test/integration -name "*-tests.js" | xargs -n 1 -I file node file -u $(user) --password $(password) -p $(port) -d $(database) -h $(host)
test-all: test-unit test-integration
test: test-unit
.PHONY : test

View File

@ -1,25 +0,0 @@
//executes all the unit tests
var fs = require('fs');
var args = require(__dirname + '/cli');
var runDir = function(dir) {
fs.readdirSync(dir).forEach(function(file) {
if(file.indexOf(".js") < 0) {
return runDir(fs.realpathSync(dir + file) + "/");
}
require(dir + file.split('.js') [0]);
});
};
var arg = args.test;
if(arg == 'all') {
runDir(__dirname+'/unit/');
runDir(__dirname+'/integration/');
}
else {
runDir(__dirname+'/' + arg + '/');
}

View File

@ -1,4 +1,3 @@
require.paths.unshift(__dirname + '/../lib/');
Client = require('client');
@ -101,14 +100,6 @@ assert.isNull = function(item, message) {
assert.ok(item === null, message);
};
['equal', 'length', 'empty', 'strictEqual', 'emits', 'equalBuffers', 'same', 'calls', 'ok'].forEach(function(name) {
var old = assert[name];
assert[name] = function() {
test.assertCount++
return old.apply(this, arguments);
};
});
test = function(name, action) {
test.testCount ++;
var result = action();
@ -120,26 +111,35 @@ test = function(name, action) {
}
};
test.assertCount = test.assertCount || 0;
//print out the filename
process.stdout.write(require('path').basename(process.argv[1]));
test.testCount = test.testCount || 0;
test.ignored = test.ignored || [];
test.errors = test.errors || [];
test.start = test.start || new Date();
process.on('exit', function() {
console.log('');
var duration = ((new Date() - test.start)/1000);
console.log(test.testCount + ' tests ' + test.assertCount + ' assertions in ' + duration + ' seconds');
test.ignored.forEach(function(name) {
console.log("Ignored: " + name);
});
test.errors.forEach(function(error) {
console.log("Error: " + error.name);
});
if(test.ignored.length || test.errors.length) {
test.ignored.forEach(function(name) {
console.log("Ignored: " + name);
});
test.errors.forEach(function(error) {
console.log("Error: " + error.name);
});
console.log('');
}
test.errors.forEach(function(error) {
throw error.e;
});
});
process.on('uncaughtException', function(err) {
console.error("\n %s", err.stack || err.toString())
//causes xargs to abort right away
process.exit(255);
});
var count = 0;
var Sink = function(expected, timeout, callback) {