Skip to content

Commit 36113dd

Browse files
committed
Switch to ava for tests, and add tests for series(), parallel() and map().
1 parent 27ec488 commit 36113dd

File tree

1 file changed

+45
-11
lines changed

1 file changed

+45
-11
lines changed

test/index.js

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,50 @@
1-
import assert from 'assert';
2-
import { series, parallel } from '../src';
1+
import test from 'ava';
2+
import { spy } from 'sinon';
3+
import { series, parallel, map } from '..';
34

4-
assert.equal(typeof series, 'function');
5+
const get = v => Promise.resolve(v);
56

6-
assert.equal(typeof parallel, 'function');
7+
const sleep = time => new Promise( r => setTimeout(r, time) );
78

8-
parallel([
9-
() => Promise.resolve('a'),
10-
() => Promise.resolve('b')
11-
]).then( out => {
12-
assert.deepEqual(out, ['a', 'b']);
139

14-
console.log('✅ success');
15-
process.exit(0);
10+
test('series', async t => {
11+
t.is(typeof series, 'function');
12+
13+
t.deepEqual(
14+
await series([
15+
async () => await get(1),
16+
async () => await get(2)
17+
]),
18+
[1, 2]
19+
);
20+
});
21+
22+
23+
test('parallel', async t => {
24+
t.is(typeof parallel, 'function', 'should be a function');
25+
26+
t.deepEqual(
27+
await parallel([
28+
async () => await get(1),
29+
async () => await get(2)
30+
]),
31+
[1, 2]
32+
);
33+
});
34+
35+
36+
test('map', async t => {
37+
t.is(typeof map, 'function');
38+
39+
let fn = spy( async value => (await sleep(50), await get(value * 2)) );
40+
41+
let start = Date.now();
42+
43+
let out = await map([1, 2, 3], fn);
44+
45+
t.deepEqual(out, [2, 4, 6]);
46+
47+
let elapsed = Date.now() - start;
48+
49+
t.true(elapsed < 100, 'Should invoke in parallel');
1650
});

0 commit comments

Comments
 (0)