From af997d914bf0ce0d6dbefde40e2858f332266ebc Mon Sep 17 00:00:00 2001 From: Brian Carlson Date: Tue, 14 Dec 2010 18:50:18 -0600 Subject: [PATCH] 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 --- Makefile | 18 ++++++++++++++++++ test/run.js | 25 ------------------------- test/test-helper.js | 38 +++++++++++++++++++------------------- 3 files changed, 37 insertions(+), 44 deletions(-) create mode 100644 Makefile delete mode 100755 test/run.js diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..27c26ef --- /dev/null +++ b/Makefile @@ -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 diff --git a/test/run.js b/test/run.js deleted file mode 100755 index aa609f8..0000000 --- a/test/run.js +++ /dev/null @@ -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 + '/'); -} - diff --git a/test/test-helper.js b/test/test-helper.js index 46c0309..6d94b49 100644 --- a/test/test-helper.js +++ b/test/test-helper.js @@ -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) {