@trenskow/parallel 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.js +3 -0
  2. package/package.json +1 -1
  3. package/test.js +8 -0
package/index.js CHANGED
@@ -2,8 +2,11 @@
2
2
 
3
3
  export default (promises) => {
4
4
 
5
+ if (typeof promises === 'undefined') throw new TypeError('No promises was provided.');
5
6
  if (!Array.isArray(promises)) promises = [promises];
6
7
 
8
+ if (promises.length === 0) return Promise.resolve([]);
9
+
7
10
  promises.forEach((promise) => {
8
11
  if (typeof (promise || {}).then !== 'function') throw new Error('Promise is not thenable.');
9
12
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trenskow/parallel",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "A small library for doing async tasks in parallel.",
5
5
  "main": "index.js",
6
6
  "type": "module",
package/test.js CHANGED
@@ -16,6 +16,14 @@ describe('parallel', () => {
16
16
  expect(() => parallel(123)).to.throw('Promise is not thenable.');
17
17
  });
18
18
 
19
+ it ('should throw an error if no promises are provided.', () => {
20
+ expect(() => parallel()).to.throw('No promises was provided.');
21
+ });
22
+
23
+ it ('should come back with empty array if an empty array was provided.', async () => {
24
+ return expect(parallel([])).to.eventually.be.eql([]);
25
+ });
26
+
19
27
  it ('should eventually come back with [1, 2, 3]', async () => {
20
28
  const called = [false, false, false];
21
29
  return (async () => {