Skip to content

Commit

Permalink
v1.3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
E.Azer Koçulu committed Dec 9, 2011
1 parent eb5544e commit 857a5c3
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 29 deletions.
50 changes: 26 additions & 24 deletions lib/highkick.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ function kick(options,callback){

try {
test.apply(undefined,args);
callback && callback();
callback();
} catch(error){
callback && callback(error);
callback(error);
}
}

(function(i, error){
(function iter(i, error){

if(error){
return mark(tests[i-1], error);
Expand All @@ -64,39 +64,41 @@ function kick(options,callback){
}

var test = tests[i],
next = arguments.callee.bind(undefined, i+1),
marker = mark.bind(undefined,test),
callback;
testCallback;

function next(error){
if(!error && options.ordered){
return;
}

iter(i+1, error);
}

if(options.ordered){
callback = function(){
testCallback = function(error){
marker.apply(null, arguments);
next();
iter(i+1, error);
}
} else {
callback = marker;
testCallback = marker;
}

var args = [callback];
var args = [testCallback];

try {

typeof module.init != 'function' ? callTestFn(test, args, !options.ordered && next) : module.init(options, function(error/* args to pass test functions */){
if(error) {
return callback(error);
}
typeof module.init != 'function' ? callTestFn(test, args, next) : module.init(options, function(error/* args to pass test functions */){
if(error) {
return callback(error);
}

var mergeArgs = [0, 0];
Array.prototype.push.apply(mergeArgs, Array.prototype.slice.call(arguments, 1));
args.splice.apply(args, mergeArgs);
var mergeArgs = [0, 0];
Array.prototype.push.apply(mergeArgs, Array.prototype.slice.call(arguments, 1));

args.splice.apply(args, mergeArgs);

callTestFn(test, args, !options.ordered && next);
});
callTestFn(test, args, next);
});

} catch(error) {
callback(error);
}

})(0);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name":"highkick",
"version":"1.3.2",
"version":"1.3.3",
"description":"Asynchronous, no-style, super simple testing tool.",
"author":"Azer Koculu <azer@kodfabrik.com>",
"keywords":["testing", "test"],
Expand Down
8 changes: 8 additions & 0 deletions test/fail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports.testError = function fail(callback){
callback(new Error('error'));
}

module.exports.testFail = function testFail(){
throw new Error('fail');
}

24 changes: 20 additions & 4 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ function init(options, callback){
callback(null, 3.14);
}

function testFail(pi, callback){
highkick({ module:require('./fail'), 'silent':true, 'name':'fail' }, function(error, result){
assert.equal(result.fail, 2);
callback();
});
}

function testOrderedFail(pi, callback){
highkick({ module:require('./fail'), 'ordered':true, 'silent':true, 'name':'ordered fail' }, function(error, result){
assert.equal(result.fail, 2);
callback();
});
}

function testAsync1(pi, callback){
assert.equal(++counter, 1);
assert.equal(pi, 3.14);
Expand Down Expand Up @@ -42,7 +56,7 @@ function testNested(test, callback){

function testOrdered(test, callback){
assert.equal(++counter, 5);
highkick({ module:require('./ordered'), 'silent':true, 'ordered':true, 'name':'ordered' },function(error,result){
highkick({ module:require('./ordered'), 'silent':false, 'ordered':true, 'name':'ordered' },function(error,result){
!error && result.len == 0 && (error = new Error('Missing test functions.'));
if(error) return callback(error);
callback(result.fail ? new Error('Fail') : undefined);
Expand All @@ -53,7 +67,9 @@ module.exports = {
'init':init,
'testAsync1':testAsync1,
'testAsync2':testAsync2,
'testSync':testSync,
'testNested':testNested,
'testOrdered':testOrdered
'testSync': testSync,
'testFail': testFail,
'testNested': testNested,
'testOrdered': testOrdered,
'testOrderedFail': testOrderedFail
}

0 comments on commit 857a5c3

Please sign in to comment.