-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest.js
42 lines (35 loc) · 1018 Bytes
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import test from 'ava';
import delay from 'delay';
import timeSpan from 'time-span';
import pMapSeries from './index.js';
const fixtureError = new Error('fixture');
test('main', async t => {
let index = 0;
const delayMs = 100;
const end = timeSpan();
const input = [Promise.resolve(1), 2, 3, Promise.resolve(4)];
const mappedValues = await pMapSeries(input, async (value, currentIndex) => {
t.is(value, currentIndex + 1);
t.is(index, currentIndex);
index++;
await delay(delayMs);
return value * 10;
});
t.deepEqual(mappedValues, [10, 20, 30, 40]);
t.true(end() > (delayMs - 20));
});
test('rejection input rejects the promise', async t => {
await t.throwsAsync(
pMapSeries([1, Promise.reject(fixtureError)], () => {}),
{message: fixtureError.message}
);
await t.throwsAsync(
pMapSeries([1, Promise.resolve(2)], async () => {
throw fixtureError;
}),
{message: fixtureError.message}
);
});
test('handles empty iterable', async t => {
t.deepEqual(await pMapSeries([]), []);
});