Permalink
Browse files

split test file and more test

  • Loading branch information...
1 parent 2592f76 commit 0ed743670f0011a3c40dac4875d46e9bf838fcc8 @hokaccha committed Nov 9, 2011
Showing with 261 additions and 215 deletions.
  1. +0 −215 test/basic.js
  2. +71 −0 test/each.js
  3. +75 −0 test/forEach.js
  4. +80 −0 test/paralle.js
  5. +35 −0 test/wait.js
View
@@ -59,219 +59,4 @@ module.exports = nodeunit.testCase({
t.done();
});
},
- 'forEach': function(t) {
- var start = Date.now();
- chain(function(next) {
- next(null, ['foo', 'bar']);
- })
- .forEach(function(key, val, next) {
- setTimeout(function() {
- next(null, key + ':' + val);
- }, 100);
- })
- .chain(function(results, next) {
- t.equal(results.length, 2);
- t.equal(results[0], '0:foo');
- t.equal(results[1], '1:bar');
- t.ok(Date.now() - start >= 190);
- t.done();
- })
- .end(t.done);
- },
- 'Chain.forEach': function(t) {
- var start = Date.now();
- chain.forEach(['foo', 'bar'], function(key, val, next) {
- setTimeout(function() {
- next(null, key + ':' + val);
- }, 100);
- })
- .chain(function(results, next) {
- t.equal(results.length, 2);
- t.equal(results[0], '0:foo');
- t.equal(results[1], '1:bar');
- t.ok(Date.now() - start >= 190);
- next();
- })
- .end(t.done);
- },
- 'forEachParallel': function(t) {
- var start = Date.now();
- chain(function(next) {
- next(null, ['foo', 'bar']);
- })
- .forEachParallel(function(key, val, next) {
- setTimeout(function() {
- next(null, key + ':' + val);
- }, 100);
- })
- .chain(function(results, next) {
- t.equal(results.length, 2);
- t.equal(results[0], '0:foo');
- t.equal(results[1], '1:bar');
- t.ok(Date.now() - start < 190);
- next();
- })
- .end(t.done);
- },
- 'Chain.forEachParallel': function(t) {
- var start = Date.now();
- chain.forEachParallel(['foo', 'bar'], function(key, val, next) {
- setTimeout(function() {
- next(null, key + ':' + val);
- }, 100);
- })
- .chain(function(results, next) {
- t.equal(results.length, 2);
- t.equal(results[0], '0:foo');
- t.equal(results[1], '1:bar');
- t.ok(Date.now() - start < 190);
- next();
- })
- .end(t.done);
- },
- 'parallel(array)': function(t) {
- var r = [];
- chain(function(next) {
- next(null, 'foo');
- })
- .parallel([
- function(next) {
- setTimeout(function() {
- r.push(1);
- next(null, 1);
- }, 100);
- },
- function(next) {
- setTimeout(function() {
- r.push(2);
- next(null, 2);
- }, 1)
- }
- ])
- .chain(function(results, next) {
- t.deepEqual(results, [1, 2]);
- t.deepEqual(r, [2, 1]);
- next();
- })
- .end(t.done);
- },
- 'parallel(obj)': function(t) {
- var r = [];
- chain.parallel({
- foo: function(next) {
- setTimeout(function() {
- r.push(1);
- next(null, 1);
- }, 100);
- },
- bar: function(next) {
- setTimeout(function() {
- r.push(2);
- next(null, 2);
- }, 1)
- }
- })
- .chain(function(results, next) {
- t.deepEqual(results, { foo: 1, bar: 2 });
- t.deepEqual(r, [2, 1]);
- next();
- })
- .end(t.done);
- },
- wait: function(t) {
- var start = Date.now();
- chain(function(next) {
- next(null, 'foo', 'bar');
- })
- .wait(100)
- .chain(function(foo, bar, next) {
- t.equal(foo, 'foo');
- t.equal(bar, 'bar');
- t.ok(Date.now() - start >= 90);
- next();
- })
- .end(function(err) {
- t.equal(err, null);
- t.done();
- });
- },
- 'Chain.wait': function(t) {
- var start = Date.now();
- chain
- .wait(100)
- .chain(function(next) {
- t.ok(Date.now() - start >= 90);
- next();
- })
- .end(function(err) {
- t.equal(err, null);
- t.done();
- });
- },
- 'each': function(t) {
- var start = Date.now();
- chain(function(next) {
- next(null, { foo: 'bar', hoge: 'fuga' });
- })
- .each(function(key, val, next) {
- setTimeout(function() {
- next(null, key + '/' + val);
- }, 100);
- })
- .chain(function(results, next) {
- t.equal(results.foo, 'foo/bar');
- t.equal(results.hoge, 'hoge/fuga');
- t.ok(Date.now() - start >= 190 );
- next();
- })
- .end(t.done);
- },
- 'eachParallel': function(t) {
- var start = Date.now();
- chain(function(next) {
- next(null, { foo: 'bar', hoge: 'fuga'});
- })
- .eachParallel(function(key, val, next) {
- setTimeout(function() {
- next(null, key + '/' + val);
- }, 100);
- })
- .chain(function(results, next) {
- t.equal(results.foo, 'foo/bar');
- t.equal(results.hoge, 'hoge/fuga');
- t.ok( Date.now() - start < 190 );
- next();
- })
- .end(t.done);
- },
- 'Chain.each': function(t) {
- var start = Date.now();
- chain.each({ foo: 'bar', hoge: 'fuga' }, function(key, val, next) {
- setTimeout(function() {
- next(null, key + '/' + val);
- }, 100);
- })
- .chain(function(results, next) {
- t.equal(results.foo, 'foo/bar');
- t.equal(results.hoge, 'hoge/fuga');
- t.ok( Date.now() - start >= 190 );
- next();
- })
- .end(t.done);
- },
- 'Chain.eachParallel': function(t) {
- var start = Date.now();
- chain.eachParallel({ foo: 'bar', hoge: 'fuga'}, function(key, val, next) {
- setTimeout(function() {
- next(null, key + '/' + val);
- }, 100);
- })
- .chain(function(results, next) {
- t.equal(results.foo, 'foo/bar');
- t.equal(results.hoge, 'hoge/fuga');
- t.ok( Date.now() - start < 190 );
- next();
- })
- .end(t.done);
- },
});
View
@@ -0,0 +1,71 @@
+var nodeunit = require('nodeunit');
+var chain = require('../index');
+
+module.exports = nodeunit.testCase({
+ '.each()': function(t) {
+ var start = Date.now();
+ chain(function(next) {
+ next(null, { foo: 'bar', hoge: 'fuga' });
+ })
+ .each(function(key, val, next) {
+ setTimeout(function() {
+ next(null, key + '/' + val);
+ }, 100);
+ })
+ .chain(function(results, next) {
+ t.equal(results.foo, 'foo/bar');
+ t.equal(results.hoge, 'hoge/fuga');
+ t.ok(Date.now() - start >= 190 );
+ next();
+ })
+ .end(t.done);
+ },
+ '.eachParallel()': function(t) {
+ var start = Date.now();
+ chain(function(next) {
+ next(null, { foo: 'bar', hoge: 'fuga'});
+ })
+ .eachParallel(function(key, val, next) {
+ setTimeout(function() {
+ next(null, key + '/' + val);
+ }, 100);
+ })
+ .chain(function(results, next) {
+ t.equal(results.foo, 'foo/bar');
+ t.equal(results.hoge, 'hoge/fuga');
+ t.ok( Date.now() - start < 190 );
+ next();
+ })
+ .end(t.done);
+ },
+ 'Chain.each()': function(t) {
+ var start = Date.now();
+ chain.each({ foo: 'bar', hoge: 'fuga' }, function(key, val, next) {
+ setTimeout(function() {
+ next(null, key + '/' + val);
+ }, 100);
+ })
+ .chain(function(results, next) {
+ t.equal(results.foo, 'foo/bar');
+ t.equal(results.hoge, 'hoge/fuga');
+ t.ok( Date.now() - start >= 190 );
+ next();
+ })
+ .end(t.done);
+ },
+ 'Chain.eachParallel()': function(t) {
+ var start = Date.now();
+ chain.eachParallel({ foo: 'bar', hoge: 'fuga'}, function(key, val, next) {
+ setTimeout(function() {
+ next(null, key + '/' + val);
+ }, 100);
+ })
+ .chain(function(results, next) {
+ t.equal(results.foo, 'foo/bar');
+ t.equal(results.hoge, 'hoge/fuga');
+ t.ok( Date.now() - start < 190 );
+ next();
+ })
+ .end(t.done);
+ },
+});
View
@@ -0,0 +1,75 @@
+var nodeunit = require('nodeunit');
+var chain = require('../index');
+
+module.exports = nodeunit.testCase({
+ '.forEach()': function(t) {
+ var start = Date.now();
+ chain(function(next) {
+ next(null, ['foo', 'bar']);
+ })
+ .forEach(function(key, val, next) {
+ setTimeout(function() {
+ next(null, key + ':' + val);
+ }, 100);
+ })
+ .chain(function(results, next) {
+ t.equal(results.length, 2);
+ t.equal(results[0], '0:foo');
+ t.equal(results[1], '1:bar');
+ t.ok(Date.now() - start >= 190);
+ t.done();
+ })
+ .end(t.done);
+ },
+ '.forEachParallel()': function(t) {
+ var start = Date.now();
+ chain(function(next) {
+ next(null, ['foo', 'bar']);
+ })
+ .forEachParallel(function(key, val, next) {
+ setTimeout(function() {
+ next(null, key + ':' + val);
+ }, 100);
+ })
+ .chain(function(results, next) {
+ t.equal(results.length, 2);
+ t.equal(results[0], '0:foo');
+ t.equal(results[1], '1:bar');
+ t.ok(Date.now() - start < 190);
+ next();
+ })
+ .end(t.done);
+ },
+ 'Chain.forEach()': function(t) {
+ var start = Date.now();
+ chain.forEach(['foo', 'bar'], function(key, val, next) {
+ setTimeout(function() {
+ next(null, key + ':' + val);
+ }, 100);
+ })
+ .chain(function(results, next) {
+ t.equal(results.length, 2);
+ t.equal(results[0], '0:foo');
+ t.equal(results[1], '1:bar');
+ t.ok(Date.now() - start >= 190);
+ next();
+ })
+ .end(t.done);
+ },
+ 'Chain.forEachParallel()': function(t) {
+ var start = Date.now();
+ chain.forEachParallel(['foo', 'bar'], function(key, val, next) {
+ setTimeout(function() {
+ next(null, key + ':' + val);
+ }, 100);
+ })
+ .chain(function(results, next) {
+ t.equal(results.length, 2);
+ t.equal(results[0], '0:foo');
+ t.equal(results[1], '1:bar');
+ t.ok(Date.now() - start < 190);
+ next();
+ })
+ .end(t.done);
+ }
+});
Oops, something went wrong.

0 comments on commit 0ed7436

Please sign in to comment.