-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c4ad862
commit 321a308
Showing
3 changed files
with
94 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
var | ||
assert = require("assert"), | ||
Promise = require("../index").Promise, | ||
PromiseTracker = require("../index").PromiseTracker, | ||
|
||
tests = [{ | ||
promises : [0, 0, 0, 0, 0], | ||
timeFun : function(idx) { | ||
return 100; | ||
}, | ||
order : [0, 1, 2, 3, 4], | ||
title : "All blocking promises", | ||
}, { | ||
promises : [1, 1, 1, 1, 1], | ||
timeFun : function(idx) { | ||
return 150 - idx * 20; | ||
}, | ||
order : [4, 3, 2, 1, 0], | ||
title : "All non blocking promises", | ||
}, { | ||
promises : [0, 1, 1, 1, 0], | ||
timeFun : function(idx) { | ||
return 150 - idx * 20; | ||
}, | ||
order : [0, 3, 2, 1, 4], | ||
title : "Mixed : Starting and ending with blocking promises", | ||
}, { | ||
promises : [1, 1, 1, 1, 0], | ||
timeFun : function(idx) { | ||
return 150 - idx * 20; | ||
}, | ||
order : [3, 2, 1, 0, 4], | ||
title : "Mixed : Starting with non blocking promises", | ||
}, { | ||
promises : [0, 1, 1, 1, 1], | ||
timeFun : function(idx) { | ||
return 150 - idx * 20; | ||
}, | ||
order : [0, 4, 3, 2, 1], | ||
title : "Mixed : Ending with non blocking promises", | ||
}], | ||
functions = ["addAsyncBlocking", "addAsyncNonBlocking"]; | ||
|
||
describe("Then Tests", function() { | ||
for(var i = 0; i < tests.length; i++) { | ||
(function() { | ||
var | ||
test = tests[i]; | ||
it(test.title, function(done) { | ||
var | ||
tracker = new PromiseTracker(), | ||
order = [], | ||
checkOrder = function() { | ||
if(order.length === test.promises.length) { | ||
assert.deepEqual(order, test.order); | ||
done(); | ||
} | ||
}; | ||
|
||
for(var j = 0; j < test.promises.length; j++) { | ||
(function() { | ||
var _j = j; | ||
tracker[functions[test.promises[j]]](function (pi) { | ||
return new Promise(function(resolve, reject) { | ||
setTimeout(function() { | ||
resolve(); | ||
}, test.timeFun(pi)); | ||
}); | ||
}, j, this).then(function() { | ||
order.push(_j); | ||
checkOrder(); | ||
}); | ||
})(); | ||
} | ||
}); | ||
})(); | ||
} | ||
}); |