|
1 | 1 | 'use strict' |
2 | 2 |
|
3 | | -// const test = require('ava') |
| 3 | +const test = require('ava') |
4 | 4 |
|
5 | | -// const tinyrun = require('tinyrun') |
| 5 | +const noop = () => {} |
6 | 6 |
|
7 | | -// test('run multiple tasks', async () => { |
8 | | -// const tasks = [ |
9 | | -// { name: 'task1', command: 'echo foo' }, |
10 | | -// { name: 'task2', command: 'echo bar' } |
11 | | -// ] |
| 7 | +const tinyrun = require('tinyrun') |
12 | 8 |
|
13 | | -// // const output = await tinyrun(tasks) |
14 | | -// }) |
| 9 | +test('run multiple tasks', async t => { |
| 10 | + const durations = [] |
| 11 | + |
| 12 | + const promises = await tinyrun({ |
| 13 | + tasks: [ |
| 14 | + { name: 'task1', cmd: 'sleep 1 && echo foo' }, |
| 15 | + { name: 'task2', cmd: 'echo bar' } |
| 16 | + ], |
| 17 | + stdout: noop, |
| 18 | + stderr: noop, |
| 19 | + start: noop, |
| 20 | + exit: ({ duration }, task) => durations.push({ name: task.name, duration }), |
| 21 | + childOpts: { shell: true } |
| 22 | + }) |
| 23 | + |
| 24 | + t.true(Array.isArray(promises)) |
| 25 | + t.is(promises.length, 2) |
| 26 | + t.is(promises[0].name, 'task1') |
| 27 | + t.is(promises[1].name, 'task2') |
| 28 | + |
| 29 | + t.true(promises[0].subprocess instanceof Promise) |
| 30 | + t.true(promises[1].subprocess instanceof Promise) |
| 31 | + |
| 32 | + const resolved = await Promise.resolve(promises).then(async tasks => { |
| 33 | + return Promise.all( |
| 34 | + tasks.map(async task => { |
| 35 | + task.subprocess = await task.subprocess |
| 36 | + return task |
| 37 | + }) |
| 38 | + ) |
| 39 | + }) |
| 40 | + |
| 41 | + t.is(resolved[0].subprocess.stdout, 'foo') |
| 42 | + t.is(resolved[1].subprocess.stdout, 'bar') |
| 43 | + t.true(durations[1].duration >= 1000) |
| 44 | +}) |
0 commit comments