-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.js
43 lines (38 loc) · 1.33 KB
/
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
43
// @flow
'use strict';
const test = require('ava');
const fixtures = require('fixturez');
const spawn = require('./');
const f = fixtures(__dirname, { root: __dirname });
test('argv', async t => {
let { code, stdout, stderr } = await spawn('node', [f.find('argv.js'), 'foo', 'bar']);
t.is(code, 0);
t.deepEqual(stdout, Buffer.from('foo bar'));
t.deepEqual(stderr, Buffer.from(''));
});
test('event: stdout', async t => {
t.plan(1);
let child = spawn('node', [f.find('stdout.js')]);
child.on('stdout', data => t.deepEqual(data, Buffer.from('some stdout')));
child.on('stderr', data => t.fail('stderr: ' + data));
await child;
});
test('event: stderr', async t => {
t.plan(1);
let child = spawn('node', [f.find('stderr.js')]);
child.on('stdout', data => t.fail('stdout: ' + data));
child.on('stderr', data => t.deepEqual(data, Buffer.from('some stderr')));
await child;
});
test('exit code 0', async t => {
let res = await spawn('node', [f.find('exit0.js')]);
t.is(res.code, 0);
t.deepEqual(res.stdout, Buffer.from('some stdout'));
t.deepEqual(res.stderr, Buffer.from('some stderr'));
});
test('exit code 1', async t => {
let { code, stdout, stderr } = await spawn('node', [f.find('exit1.js')]);
t.is(code, 1);
t.deepEqual(stdout, Buffer.from('some stdout'));
t.deepEqual(stderr, Buffer.from('some stderr'));
});