diff --git a/testHarness/test.js b/testHarness/test.js index 296e51b..12aea20 100644 --- a/testHarness/test.js +++ b/testHarness/test.js @@ -2,107 +2,165 @@ var ipc = require('../node-ipc'), cmd = require('node-cmd'), fs = require('fs'), events= require('event-pubsub')(), - tests = {}; + tests = {}, + testCount=0, + fails=[], + passes=[]; ipc.config.id = 'testHarness'; -events.on( - 'startFailed', - function(test){ - ipc.log(test.warn," failed to start ".error) - } -); - ipc.serve( function(){ - ipc.server.on( - 'pass', - function(data,socket){ - ipc.log(socket.id.good); - socket - } - ); - ipc.server.on( - 'fail', - function(err,socket){ - ipc.log(socket.id.warn,err); - socket - } - ); - - ipc.server.on( - 'start', - function(data,socket){ - ipc.log(socket.id.notice, 'started'.debug); - events.trigger( - 'started-test-'+socket.id, - socket.id - ); - } - ); - - - ipc.log('TestHarness started.'.debug, 'Loading Tests.'.notice); - - fs.readdir( - 'tests', - function(err,tests){ - if(err){ - ipc.log('You must execute the testHarness from the testHarness directory') - return; - } - for(var i =0; i> end.test'); + testCount--; + tests[socket.id].delay=null; + checkComplete(); + } + } + )(data.id), + data.duration + ) + } +); + +ipc.server.on( + 'end.test', + function(data,socket){ + ipc.log(socket.id.notice, 'completed'.debug); + + clearTimeout( + tests[socket.id].delay + ); + + tests[socket.id].delay=null; + + testCount--; + checkComplete(); + } +); + +ipc.log('TestHarness started.'.debug, 'Loading Tests.'.notice); + +ipc.server.define.listen['start.test']='This event should be called when a test is starting. It accepts an object with test details including the test id and duration'; +ipc.server.define.listen['end.test']='This event should be called when a test is completed.'; +ipc.server.define.listen['pass']='This event should be called when a test has passed, it accepts the name of the test portion which passed'; +ipc.server.define.listen['fail']='This event should be called when a test has failed, it accepts the name of the test portion which failed'; ipc.server.start(); +fs.readdir( + 'tests', + function(err,testFolders){ + if(err){ + ipc.log(err,'You must execute the testHarness from the testHarness directory'.error) + return; + } + testCount=testFolders.length; + + for(var i =0; i> start.test'); + testCount--; + checkComplete(); + } + } + )(testFolders[i]), + 1000 + ) + }; + + runTests(testFolders[i]) + } + } +); + function runTests(dir){ fs.readdir( 'tests/'+dir, - function(err,tests){ + function(err,testFiles){ if(err){ - ipc.log('You must execute the testHarness from the testHarness directory') + ipc.log(err,'You must execute the testHarness from the testHarness directory'.error) return; } - for(var i =0; i