1 var assert = require('assert');
2 var Pend = require('./');
14 name: "callback twice",
15 fn: testCallbackTwice,
18 name: "calling wait twice",
19 fn: testCallingWaitTwice,
26 var testCount = tests.length;
30 function doOneTest() {
31 var test = tests.shift();
33 console.log(testCount + " tests passed.");
36 process.stdout.write(test.name + "...");
38 process.stdout.write("OK\n");
43 function testBasic(cb) {
44 var pend = new Pend();
46 pend.go(function(cb) {
48 setTimeout(function() {
53 pend.go(function(cb) {
55 setTimeout(function() {
60 pend.wait(function(err) {
61 assert.deepEqual(results, [1,2,3,4]);
64 assert.deepEqual(results, [1, 2]);
67 function testWithMax(cb) {
68 var pend = new Pend();
71 pend.go(function(cb) {
73 setTimeout(function() {
78 pend.go(function(cb) {
80 setTimeout(function() {
85 pend.go(function(cb) {
87 setTimeout(function() {
92 pend.wait(function(err) {
93 assert.deepEqual(results, ['a', 'b', 1, 'c', 1, 2]);
96 assert.deepEqual(results, ['a', 'b']);
99 function testCallbackTwice(cb) {
100 var pend = new Pend();
101 pend.go(function(cb) {
104 pend.go(function(cb) {
106 assert.throws(cb, /callback called twice/);
111 function testCallingWaitTwice(cb) {
112 var pend = new Pend();
113 pend.go(function(cb) {
116 pend.wait(function() {
117 pend.go(function(cb) {
120 pend.go(function(cb) {
123 pend.go(function(cb) {
130 function testHoldFn(cb) {
131 var pend = new Pend();
132 setTimeout(pend.hold(), 100);
133 pend.go(function(cb) {