summaryrefslogtreecommitdiff
path: root/test/concat.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/concat.js')
-rw-r--r--test/concat.js194
1 files changed, 93 insertions, 101 deletions
diff --git a/test/concat.js b/test/concat.js
index 75f8db7..229a9da 100644
--- a/test/concat.js
+++ b/test/concat.js
@@ -6,16 +6,16 @@ describe('concat', function() {
this.timeout(250);
function concatIteratee(callOrder, val, next) {
- setTimeout(function() {
+ setTimeout(() => {
callOrder.push(val);
next(null, [val, val+1]);
}, val * 25);
}
- context('concat', function() {
+ context('concat', () => {
it('basics', function(done) {
var callOrder = [];
- async.concat([1, 3, 2], concatIteratee.bind(this, callOrder), function(err, result) {
+ async.concat([1, 3, 2], concatIteratee.bind(this, callOrder), (err, result) => {
expect(err).to.eql(null);
expect(callOrder).to.eql([1, 2, 3]);
expect(result).to.eql([1, 2, 3, 4, 2, 3]);
@@ -23,114 +23,114 @@ describe('concat', function() {
});
});
- it('error', function(done) {
- async.concat([1, 3, 2], function(val, next) {
+ it('error', (done) => {
+ async.concat([1, 3, 2], (val, next) => {
if (val === 3) {
return next(new Error('fail'));
}
next(null, [val, val+1]);
- }, function(err, result) {
+ }, (err, result) => {
expect(err).to.not.eql(null);
expect(result).to.eql([1, 2]);
done();
});
});
- it('original untouched', function(done) {
+ it('original untouched', (done) => {
var arr = ['foo', 'bar', 'baz'];
- async.concat(arr, function(val, next) {
+ async.concat(arr, (val, next) => {
next(null, [val, val]);
- }, function(err, result) {
+ }, (err, result) => {
expect(arr).to.eql(['foo', 'bar', 'baz']);
expect(result).to.eql(['foo', 'foo', 'bar', 'bar', 'baz', 'baz']);
done();
});
});
- it('empty results', function(done) {
+ it('empty results', (done) => {
var arr = ['foo', 'bar', 'baz'];
- async.concat(arr, function(val, next) {
+ async.concat(arr, (val, next) => {
next(null);
- }, function(err, result) {
+ }, (err, result) => {
expect(err).to.eql(null);
expect(result).to.be.an('array').that.is.empty;
done();
});
});
- it('empty arrays', function(done) {
+ it('empty arrays', (done) => {
var arr = ['foo', 'bar', 'baz'];
- async.concat(arr, function(val, next) {
+ async.concat(arr, (val, next) => {
next(null, []);
- }, function(err, result) {
+ }, (err, result) => {
expect(err).to.eql(null);
expect(result).to.be.an('array').that.is.empty;
done();
});
});
- it('handles empty object', function(done) {
- async.concat({}, function(val, next) {
+ it('handles empty object', (done) => {
+ async.concat({}, (val, next) => {
assert(false, 'iteratee should not be called');
next();
- }, function(err, result) {
+ }, (err, result) => {
expect(err).to.eql(null);
expect(result).to.be.an('array').that.is.empty;
done();
});
});
- it('variadic', function(done) {
+ it('variadic', (done) => {
var arr = ['foo', 'bar', 'baz'];
- async.concat(arr, function(val, next) {
+ async.concat(arr, (val, next) => {
next(null, val, val);
- }, function(err, result) {
+ }, (err, result) => {
expect(err).to.eql(null);
expect(result).to.eql(['foo', 'foo', 'bar', 'bar', 'baz', 'baz']);
done();
});
});
- it('flattens arrays', function(done) {
+ it('flattens arrays', (done) => {
var arr = ['foo', 'bar'];
- async.concat(arr, function(val, next) {
+ async.concat(arr, (val, next) => {
next(null, [val, [val]]);
- }, function(err, result) {
+ }, (err, result) => {
expect(err).to.eql(null);
expect(result).to.eql(['foo', ['foo'], 'bar', ['bar']]);
done();
});
});
- it('handles fasly values', function(done) {
+ it('handles fasly values', (done) => {
var falsy = [null, undefined, 0, ''];
- async.concat(falsy, function(val, next) {
+ async.concat(falsy, (val, next) => {
next(null, val);
- }, function(err, result) {
+ }, (err, result) => {
expect(err).to.eql(null);
expect(result).to.eql(falsy);
done();
});
});
- it('handles objects', function(done) {
+ it('handles objects', (done) => {
var obj = {a: 'foo', b: 'bar', c: 'baz'};
- async.concat(obj, function(val, next) {
+ async.concat(obj, (val, next) => {
next(null, val);
- }, function(err, result) {
+ }, (err, result) => {
expect(err).to.eql(null);
expect(result).to.eql(['foo', 'bar', 'baz']);
done();
});
});
- it('main callback optional', function(done) {
+ it('main callback optional', (done) => {
var arr = [1, 2, 3];
var runs = [];
- async.concat(arr, function(val, next) {
+ async.concat(arr, (val, next) => {
runs.push(val);
var _done = (runs.length === arr.length);
- async.setImmediate(function() {
+ async.setImmediate(() => {
next(null);
if (_done) {
expect(runs).to.eql(arr);
@@ -140,35 +140,35 @@ describe('concat', function() {
});
});
- it('iteratee callback is only called once', function(done) {
- async.concat([1, 2], function(val, next) {
+ it('iteratee callback is only called once', (done) => {
+ async.concat([1, 2], (val, next) => {
try {
next(val);
} catch (exception) {
- expect(function() {
+ expect(() => {
next(exception);
}).to.throw(/already called/);
done();
}
- }, function() {
+ }, () => {
throw new Error();
});
});
- it('preserves order', function(done) {
+ it('preserves order', (done) => {
var arr = [30, 15];
- async.concat(arr, function(x, cb) {
- setTimeout(function() {
+ async.concat(arr, (x, cb) => {
+ setTimeout(() => {
cb(null, x);
}, x);
- }, function(err, result) {
+ }, (err, result) => {
expect(err).to.eql(null);
expect(result).to.eql(arr);
done();
});
});
- it('handles Map', function(done) {
+ it('handles Map', (done) => {
if (typeof Map !== 'function') {
return done();
}
@@ -179,28 +179,28 @@ describe('concat', function() {
['c', 'd']
]);
- async.concat(map, function(val, next) {
+ async.concat(map, (val, next) => {
next(null, val);
- }, function(err, result) {
+ }, (err, result) => {
expect(err).to.eql(null);
expect(result).to.eql(['a', 'b', 'b', 'c', 'c', 'd']);
done();
});
});
- it('handles sparse results', function(done) {
+ it('handles sparse results', (done) => {
var arr = [1, 2, 3, 4];
- async.concat(arr, function(val, next) {
+ async.concat(arr, (val, next) => {
if (val === 1 || val === 3) {
return next(null, val+1);
} else if (val === 2) {
- async.setImmediate(function() {
+ async.setImmediate(() => {
return next(null, val+1);
});
} else {
return next('error');
}
- }, function(err, result) {
+ }, (err, result) => {
expect(err).to.not.eql(null);
expect(result).to.eql([2, 4]);
async.setImmediate(done);
@@ -208,19 +208,19 @@ describe('concat', function() {
});
});
- context('concatLimit', function() {
+ context('concatLimit', () => {
var arr = ['foo', 'bar', 'baz'];
- it('basics', function(done) {
+ it('basics', (done) => {
var running = 0;
var concurrency = {'foo': 2, 'bar': 2, 'baz': 1};
- async.concatLimit(arr, 2, function(val, next) {
+ async.concatLimit(arr, 2, (val, next) => {
running++;
- async.setImmediate(function() {
+ async.setImmediate(() => {
expect(running).to.equal(concurrency[val]);
running--;
next(null, val, val);
})
- }, function(err, result) {
+ }, (err, result) => {
expect(running).to.equal(0);
expect(err).to.eql(null);
expect(result).to.eql(['foo', 'foo', 'bar', 'bar', 'baz', 'baz']);
@@ -228,45 +228,45 @@ describe('concat', function() {
});
});
- it('error', function(done) {
- async.concatLimit(arr, 1, function(val, next) {
+ it('error', (done) => {
+ async.concatLimit(arr, 1, (val, next) => {
if (val === 'bar') {
return next(new Error('fail'));
}
next(null, val);
- }, function(err, result) {
+ }, (err, result) => {
expect(err).to.not.eql(null);
expect(result).to.eql(['foo']);
done();
});
});
- it('handles objects', function(done) {
- async.concatLimit({'foo': 1, 'bar': 2, 'baz': 3}, 2, function(val, next) {
+ it('handles objects', (done) => {
+ async.concatLimit({'foo': 1, 'bar': 2, 'baz': 3}, 2, (val, next) => {
next(null, val+1);
- }, function(err, result) {
+ }, (err, result) => {
expect(err).to.eql(null);
expect(result).to.eql([2, 3, 4]);
done();
});
});
- it('handles empty object', function(done) {
- async.concatLimit({}, 2, function(val, next) {
+ it('handles empty object', (done) => {
+ async.concatLimit({}, 2, (val, next) => {
assert(false, 'iteratee should not be called');
next();
- }, function(err, result) {
+ }, (err, result) => {
expect(err).to.eql(null);
expect(result).to.be.an('array').that.is.empty;
done();
});
});
- it('handles undefined', function(done) {
- async.concatLimit(undefined, 2, function(val, next) {
+ it('handles undefined', (done) => {
+ async.concatLimit(undefined, 2, (val, next) => {
assert(false, 'iteratee should not be called');
next();
- }, function(err, result) {
+ }, (err, result) => {
expect(err).to.eql(null);
expect(result).to.be.an('array').that.is.empty;
done();
@@ -275,7 +275,7 @@ describe('concat', function() {
it('limit exceeds size', function(done) {
var callOrder = [];
- async.concatLimit([3, 2, 2, 1], 10, concatIteratee.bind(this, callOrder), function(err, result) {
+ async.concatLimit([3, 2, 2, 1], 10, concatIteratee.bind(this, callOrder), (err, result) => {
expect(err).to.eql(null);
expect(result).to.eql([3, 4, 2, 3, 2, 3, 1, 2]);
expect(callOrder).to.eql([1, 2, 2, 3]);
@@ -285,7 +285,7 @@ describe('concat', function() {
it('limit equal size', function(done) {
var callOrder = [];
- async.concatLimit([3, 2, 2, 1], 4, concatIteratee.bind(this, callOrder), function(err, result) {
+ async.concatLimit([3, 2, 2, 1], 4, concatIteratee.bind(this, callOrder), (err, result) => {
expect(err).to.eql(null);
expect(result).to.eql([3, 4, 2, 3, 2, 3, 1, 2]);
expect(callOrder).to.eql([1, 2, 2, 3]);
@@ -293,34 +293,32 @@ describe('concat', function() {
});
});
- it('zero limit', function() {
+ it('zero limit', () => {
expect(() => {
- async.concatLimit([3, 2, 2, 1], 0, function(val, next) {
+ async.concatLimit([3, 2, 2, 1], 0, (val, next) => {
assert(false, 'iteratee should not be called');
next();
- }, function() {
+ }, () => {
assert(false, 'callback should not be called');
});
}).to.throw(/limit/)
});
- it('does not continue replenishing after error', function(done) {
+ it('does not continue replenishing after error', (done) => {
var started = 0;
var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
var limit = 3;
- var step = 0;
- var maxSteps = arr.length;
- async.concatLimit(arr, limit, function(val, next) {
+ async.concatLimit(arr, limit, (val, next) => {
started++;
if (started === 3) {
return next(new Error('fail'));
}
- async.setImmediate(function() {
+ async.setImmediate(() => {
next();
});
- }, function(err, result) {
+ }, (err, result) => {
expect(err).to.not.eql(null);
expect(result).to.be.an('array').that.is.empty;
});
@@ -328,27 +326,21 @@ describe('concat', function() {
// wait `maxSteps` event loop cycles before calling done to ensure
// the iteratee is not called on more items in arr.
function waitCycle() {
- step++;
- if (step >= maxSteps) {
- expect(started).to.equal(3);
- done();
- return;
- } else {
- async.setImmediate(waitCycle);
- }
+ expect(started).to.equal(3);
+ done();
}
- async.setImmediate(waitCycle);
+ setTimeout(waitCycle, 25);
});
});
- context('concatSeries', function() {
- it('basics', function(done) {
+ context('concatSeries', () => {
+ it('basics', (done) => {
var callOrder = [];
var running = 0;
var iteratee = function (x, cb) {
running++;
- setTimeout(function() {
+ setTimeout(() => {
expect(running).to.equal(1);
running--;
callOrder.push(x);
@@ -360,7 +352,7 @@ describe('concat', function() {
cb(null, r);
}, x*25);
};
- async.concatSeries([1,3,2], iteratee, function(err, results) {
+ async.concatSeries([1,3,2], iteratee, (err, results) => {
expect(results).to.eql([1,3,2,1,2,1]);
expect(running).to.equal(0);
expect(callOrder).to.eql([1,3,2]);
@@ -369,45 +361,45 @@ describe('concat', function() {
});
});
- it('error', function(done) {
- async.concatSeries(['foo', 'bar', 'baz'], function(val, next) {
+ it('error', (done) => {
+ async.concatSeries(['foo', 'bar', 'baz'], (val, next) => {
if (val === 'bar') {
return next(new Error('fail'));
}
next(null, [val, val]);
- }, function(err, result) {
+ }, (err, result) => {
expect(err).to.not.eql(null);
expect(result).to.eql(['foo', 'foo']);
done();
});
});
- it('handles objects', function(done) {
- async.concatSeries({'foo': 1, 'bar': 2, 'baz': 3}, function(val, next) {
+ it('handles objects', (done) => {
+ async.concatSeries({'foo': 1, 'bar': 2, 'baz': 3}, (val, next) => {
return next(null, [val, val+1]);
- }, function(err, result) {
+ }, (err, result) => {
expect(err).to.eql(null);
expect(result).to.eql([1, 2, 2, 3, 3, 4]);
done();
});
});
- it('handles empty object', function(done) {
- async.concatSeries({}, function(val, next) {
+ it('handles empty object', (done) => {
+ async.concatSeries({}, (val, next) => {
assert(false, 'iteratee should not be called');
next();
- }, function(err, result) {
+ }, (err, result) => {
expect(err).to.eql(null);
expect(result).to.be.an('array').that.is.empty;
done();
});
});
- it('handles undefined', function(done) {
- async.concatSeries(undefined, function(val, next) {
+ it('handles undefined', (done) => {
+ async.concatSeries(undefined, (val, next) => {
assert(false, 'iteratee should not be called');
next();
- }, function(err, result) {
+ }, (err, result) => {
expect(err).to.eql(null);
expect(result).to.be.an('array').that.is.empty;
done();