test.js
This file
Path
test.js
110 lines · 3.0 KiB · JavaScript
Last changed by
add `input` optionJames Talmagebefore adoption605a674
History of this fileTake it
fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df
line 1why, one step back1import path from 'path';add `input` optionJames Talmagebefore adoption605a674
line 2why, one step back2import stream from 'stream';3import test from 'ava';make `execa.spawn()` use the same argument normalization as `execa()`Sindre Sorhusbefore adoptiond6e3220
line 4why, one step back4import getStream from 'get-stream';tweaksSindre Sorhusbefore adoptione3505a8
line 5why, one step back5import m from './';6fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df
lines 7–8why, one step back7process.env.PATH = path.join(__dirname, 'fixtures') + path.delimiter + process.env.PATH;89test('execa()', async t => {fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df
line 10why, one step back10 const {stdout} = await m('noop', ['foo']);initSindre Sorhusbefore adoptionbc16d6b
lines 11–1411 t.is(stdout, 'foo');12});1314test('buffer', async t => {fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df
line 15why, one step back15 const {stdout} = await m('noop', ['foo'], {encoding: null});initSindre Sorhusbefore adoptionbc16d6b
lines 16–1916 t.true(Buffer.isBuffer(stdout));17 t.is(stdout.toString(), 'foo');18});19add `stdout`/`stderr` to errorsSindre Sorhusbefore adoption0ea8aaf
line 20why, one step back20test('stdout/stderr available on errors', async t => {meta tweaksSindre Sorhusbefore adoption858af26
lines 21–23why, one step back21 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 back24});25Attach pid and kill() to returned promise (#11)Luke Horvatbefore adoption9da5484
line 26why, one step back26test('include stdout in errors for improved debugging', async t => {meta tweaksSindre Sorhusbefore adoption858af26
lines 27–28why, one step back27 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 back29});30Merge pull request #3 from sindresorhus/local-binsSindre Sorhusbefore adoptiona0c035c
line 31why, one step back31test('execa.shell()', async t => {fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df
line 32why, one step back32 const {stdout} = await m.shell('node fixtures/noop foo');Merge pull request #3 from sindresorhus/local-binsSindre Sorhusbefore adoptiona0c035c
lines 33–35why, one step back33 t.is(stdout, 'foo');34});35make `execa.spawn()` use the same argument normalization as `execa()`Sindre Sorhusbefore adoptiond6e3220
line 36why, one step back36test('execa.spawn()', async t => {fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df
lines 37–38why, one step back37 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 back39});40add `execa.sync()` (#7)Sindre Sorhusbefore adoption9345d2c
line 41why, one step back41test('execa.sync()', t => {fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df
line 42why, one step back42 const stdout = m.sync('noop', ['foo']);add `execa.sync()` (#7)Sindre Sorhusbefore adoption9345d2c
lines 43–45why, one step back43 t.is(stdout, 'foo');44});45add `execa.shellSync()`Sindre Sorhusbefore adoption71a58ee
lines 46–50why, one step back46test('execa.shellSync()', t => {47 const stdout = m.shellSync('node fixtures/noop foo');48 t.is(stdout, 'foo');49});5051test('stripEof option', async t => {fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df
line 52why, one step back52 const {stdout} = await m('noop', ['foo'], {stripEof: false});initSindre Sorhusbefore adoptionbc16d6b
lines 53–5553 t.is(stdout, 'foo\n');54});55Merge pull request #3 from sindresorhus/local-binsSindre Sorhusbefore adoptiona0c035c
line 56why, one step back56test.serial('preferLocal option', async t => {tweaksSindre Sorhusbefore adoptione3505a8
line 57why, one step back57 t.true((await m('cat-names')).stdout.length > 2);Merge pull request #3 from sindresorhus/local-binsSindre Sorhusbefore adoptiona0c035c
line 58why, one step back58fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df
lines 59–63why, one step back59 if (process.platform === 'win32') {60 // TODO: figure out how to make the below not hang on Windows61 return;62 }63Merge pull request #3 from sindresorhus/local-binsSindre Sorhusbefore adoptiona0c035c
lines 64–66why, one step back64 // account for npm adding local binaries to the PATH65 const _path = process.env.PATH;66 process.env.PATH = '';fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df
line 67why, one step back67 await t.throws(m('cat-names', {preferLocal: false}), /spawn .* ENOENT/);Merge pull request #3 from sindresorhus/local-binsSindre Sorhusbefore adoptiona0c035c
line 68why, one step back68 process.env.PATH = _path;add `input` optionJames Talmagebefore adoption605a674
lines 69–103why, one step back69});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 back104});105106test('execa() returns a promise with kill() and pid', t => {fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df
line 107why, one step back107 const promise = m('noop', ['foo']);Attach pid and kill() to returned promise (#11)Luke Horvatbefore adoption9da5484
lines 108–109why, one step back108 t.is(typeof promise.kill, 'function');109 t.is(typeof promise.pid, 'number');110});