completed testHarness and added testHarness test.

This commit is contained in:
Brandon Nozaki Miller 2014-09-03 18:05:10 -07:00
parent 0189a44ee3
commit 4063264542
4 changed files with 180 additions and 81 deletions

View file

@ -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.serve(
function(){
ipc.server.on(
ipc.server.on(
'pass',
function(data,socket){
ipc.log(socket.id.good);
socket
function(test,socket){
ipc.log(socket.id.good,'passed',test.data);
tests[socket.id].pass.push(test);
passes.push(test);
}
);
);
ipc.server.on(
ipc.server.on(
'fail',
function(err,socket){
ipc.log(socket.id.warn,err);
socket
function(test,socket){
ipc.log(socket.id.warn,'failed',test.data);
tests[socket.id].fail.push(test);
fails.push(test);
}
);
);
ipc.server.on(
'start',
ipc.server.on(
'start.test',
function(data,socket){
ipc.log(socket.id.notice, 'started'.debug);
events.trigger(
'started-test-'+socket.id,
socket.id
);
}
);
socket.id=data.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')
if(!data.id){
ipc.log('start.test duration not passed for unknown test, so failing test'.error);
socket.destroy();
return;
}
for(var i =0; i<tests.length; i++){
tests[tests[i]]={
if(!data.duration){
ipc.log(data.id.notice, 'start.test duration not passed, so failing test'.error);
ipc.disconnect(data.id);
return;
}
ipc.log(data.id.notice, 'started'.debug);
tests[data.id].started=true;
clearTimeout(
tests[data.id].delay
);
tests[data.id].delay=setTimeout(
(
function(test){
return function(){
ipc.log(test.warn," failed to complete ".error);
tests[test].fail.push('end.test');
fails.push(test+' >> 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<testFolders.length; i++){
tests[testFolders[i]]={
started : false,
pass : false,
fail : true,
pass : [],
fail : [],
delay : setTimeout(
(
function(test){
return function(){
events.trigger(
'startFailed',
test
);
ipc.log(test.warn," failed to start ".error);
tests[test].fail.push('start.test');
fails.push(test+' >> start.test');
testCount--;
checkComplete();
}
}
)(tests[i]),
)(testFolders[i]),
1000
)
};
runTests(tests[i])
runTests(testFolders[i])
}
}
);
}
);
ipc.server.define.listen['pass']='This event should be called when a test has passed';
ipc.server.define.listen['fail']='This event should be called when a test has failed, it accepts an argument for error conditions';
ipc.server.start();
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<tests.length; i++){
events.on(
'started-test-'+tests[i],
function(id){
tests[id].started=true;
clearTimeout(
tests[id].delay
for(var i =0; i<testFiles.length; i++){
cmd.run(
'node tests/'+dir+'/'+testFiles[i]
);
}
);
cmd.run('node '+tests[i]);
}
}
);
}
function checkComplete(){
if(testCount)
return;
ipc.log('####################################\n\n RESULTS\n\n####################################\n\n'.rainbow,tests,'\n\n');
ipc.log('####################################\n\n PASSES\n\n####################################\n\n'.good,passes.join('\n').good,'\n\n');
ipc.log('####################################\n\n FAILS\n\n####################################\n\n'.warn,fails.join('\n').warn,'\n\n');
ipc.log('####################################\n\n COUNT\n\n####################################\n\n'.data,(passes.length+' ').good,(fails.length+' ').warn,'\n\n');
process.exit(0);
}

View file

@ -0,0 +1,41 @@
var ipc = require('../../../node-ipc');
ipc.config.id = __dirname.split('/');
ipc.config.id = ipc.config.id[ipc.config.id.length-1]
ipc.config.maxRetries=1;
ipc.connectTo(
'testHarness',
function(){
ipc.of.testHarness.on(
'connect',
function(){
ipc.of.testHarness.emit(
'start.test',
{
id : ipc.config.id,
duration: 1000
}
);
ipc.of.testHarness.emit(
'pass',
'test-harness-pass-test'
);
ipc.of.testHarness.emit(
'fail',
'test-harness-fail-test'
);
setTimeout(
function(){
//delay exit incase you want to test failure of start.test by modifying event name
ipc.of.testHarness.emit(
'end.test'
);
ipc.of.testHarness.disconnect();
},
1000
);
}
);
}
);