Skip to content
Myr

test.js

This file

Path

test.js

110 lines · 3.0 KiB · JavaScript

Last changed by

add `input` optionJames Talmagebefore adoption605a674

History of this file

Take it

fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df

line 1why, one step back
1import path from 'path';

add `input` optionJames Talmagebefore adoption605a674

line 2why, one step back
2import stream from 'stream';

initSindre Sorhusbefore adoptionbc16d6b

line 3
3import test from 'ava';

make `execa.spawn()` use the same argument normalization as `execa()`Sindre Sorhusbefore adoptiond6e3220

line 4why, one step back
4import getStream from 'get-stream';

tweaksSindre Sorhusbefore adoptione3505a8

line 5why, one step back
5import m from './';

initSindre Sorhusbefore adoptionbc16d6b

line 6
6

fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df

lines 7–8why, one step back
7process.env.PATH = path.join(__dirname, 'fixtures') + path.delimiter + process.env.PATH;
8

initSindre Sorhusbefore adoptionbc16d6b

line 9
9test('execa()', async t => {

fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df

line 10why, one step back
10 const {stdout} = await m('noop', ['foo']);

initSindre Sorhusbefore adoptionbc16d6b

lines 11–14
11 t.is(stdout, 'foo');
12});1314test('buffer', async t => {

fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df

line 15why, one step back
15 const {stdout} = await m('noop', ['foo'], {encoding: null});

initSindre Sorhusbefore adoptionbc16d6b

lines 16–19
16 t.true(Buffer.isBuffer(stdout));
17 t.is(stdout.toString(), 'foo');18});19

add `stdout`/`stderr` to errorsSindre Sorhusbefore adoption0ea8aaf

line 20why, one step back
20test('stdout/stderr available on errors', async t => {

meta tweaksSindre Sorhusbefore adoption858af26

lines 21–23why, one step back
21 const err = await t.throws(m('exit', ['2']));
22 t.is(typeof err.stdout, 'string');23 t.is(typeof err.stderr, 'string');

add `stdout`/`stderr` to errorsSindre Sorhusbefore adoption0ea8aaf

lines 24–25why, one step back
24});
25

Attach pid and kill() to returned promise (#11)Luke Horvatbefore adoption9da5484

line 26why, one step back
26test('include stdout in errors for improved debugging', async t => {

meta tweaksSindre Sorhusbefore adoption858af26

lines 27–28why, one step back
27 const err = await t.throws(m('./fixtures/error-message.js'));
28 t.true(err.message.indexOf('stdout') !== -1);

include stdout in errors for improved debuggingSindre Sorhusbefore adoptionaea8c9a

lines 29–30why, one step back
29});
30

Merge pull request #3 from sindresorhus/local-binsSindre Sorhusbefore adoptiona0c035c

line 31why, one step back
31test('execa.shell()', async t => {

fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df

line 32why, one step back
32 const {stdout} = await m.shell('node fixtures/noop foo');

Merge pull request #3 from sindresorhus/local-binsSindre Sorhusbefore adoptiona0c035c

lines 33–35why, one step back
33 t.is(stdout, 'foo');
34});35

make `execa.spawn()` use the same argument normalization as `execa()`Sindre Sorhusbefore adoptiond6e3220

line 36why, one step back
36test('execa.spawn()', async t => {

fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df

lines 37–38why, one step back
37 t.is(typeof m.spawn('noop').pid, 'number');
38 t.is((await getStream(m.spawn('noop', ['foo']).stdout)).trim(), 'foo');

expose `.spawn`Sindre Sorhusbefore adoptionb65479c

lines 39–40why, one step back
39});
40

add `execa.sync()` (#7)Sindre Sorhusbefore adoption9345d2c

line 41why, one step back
41test('execa.sync()', t => {

fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df

line 42why, one step back
42 const stdout = m.sync('noop', ['foo']);

add `execa.sync()` (#7)Sindre Sorhusbefore adoption9345d2c

lines 43–45why, one step back
43 t.is(stdout, 'foo');
44});45

add `execa.shellSync()`Sindre Sorhusbefore adoption71a58ee

lines 46–50why, one step back
46test('execa.shellSync()', t => {
47 const stdout = m.shellSync('node fixtures/noop foo');48 t.is(stdout, 'foo');49});50

initSindre Sorhusbefore adoptionbc16d6b

line 51
51test('stripEof option', async t => {

fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df

line 52why, one step back
52 const {stdout} = await m('noop', ['foo'], {stripEof: false});

initSindre Sorhusbefore adoptionbc16d6b

lines 53–55
53 t.is(stdout, 'foo\n');
54});55

Merge pull request #3 from sindresorhus/local-binsSindre Sorhusbefore adoptiona0c035c

line 56why, one step back
56test.serial('preferLocal option', async t => {

tweaksSindre Sorhusbefore adoptione3505a8

line 57why, one step back
57 t.true((await m('cat-names')).stdout.length > 2);

Merge pull request #3 from sindresorhus/local-binsSindre Sorhusbefore adoptiona0c035c

line 58why, one step back
58

fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df

lines 59–63why, one step back
59 if (process.platform === 'win32') {
60 // TODO: figure out how to make the below not hang on Windows61 return;62 }63

Merge pull request #3 from sindresorhus/local-binsSindre Sorhusbefore adoptiona0c035c

lines 64–66why, one step back
64 // account for npm adding local binaries to the PATH
65 const _path = process.env.PATH;66 process.env.PATH = '';

fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df

line 67why, one step back
67 await t.throws(m('cat-names', {preferLocal: false}), /spawn .* ENOENT/);

Merge pull request #3 from sindresorhus/local-binsSindre Sorhusbefore adoptiona0c035c

line 68why, one step back
68 process.env.PATH = _path;

add `input` optionJames Talmagebefore adoption605a674

lines 69–103why, one step back
69});
7071test('input option can be a String', async t => {72 const {stdout} = await m('stdin', [], {input: 'foobar'});73 t.is(stdout, 'foobar');74});7576test('input option can be a Buffer', async t => {77 const {stdout} = await m('stdin', [], {input: 'testing12'});78 t.is(stdout, 'testing12');79});8081test('input can be a Stream', async t => {82 var s = new stream.PassThrough();83 s.write('howdy');84 s.end();85 const {stdout} = await m('stdin', [], {input: s});86 t.is(stdout, 'howdy');87});8889test('input option can be a String - sync', async t => {90 const stdout = m.sync('stdin', [], {input: 'foobar'});91 t.is(stdout, 'foobar');92});9394test('input option can be a Buffer - sync', async t => {95 const stdout = m.sync('stdin', [], {input: new Buffer('testing12', 'utf8')});96 t.is(stdout, 'testing12');97});9899test('helpful error trying to provide an input stream in sync mode', t => {100 t.throws(101 () => m.sync('stdin', [], {input: new stream.PassThrough()}),102 /The `input` option cannot be a stream in sync mode/103 );

Attach pid and kill() to returned promise (#11)Luke Horvatbefore adoption9da5484

lines 104–106why, one step back
104});
105106test('execa() returns a promise with kill() and pid', t => {

fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df

line 107why, one step back
107 const promise = m('noop', ['foo']);

Attach pid and kill() to returned promise (#11)Luke Horvatbefore adoption9da5484

lines 108–109why, one step back
108 t.is(typeof promise.kill, 'function');
109 t.is(typeof promise.pid, 'number');

initSindre Sorhusbefore adoptionbc16d6b

line 110
110});