Skip to content
Myr

add `input` option

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fixes #12. None of the new tests are setup to run on Windows. Is there a cross platform command I can execute that will work well on Travis and AppVeyor? Closes #15

authored by James Talmage · committed by Sindre Sorhus · parent 71a58ee · Browse files · 5 files+68 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+68 added−0 removed

  • other:+68 added−0 removed

5 files+68 added−0 removed

added:fixtures/stdin+3 added
1#!/usr/bin/env node2'use strict';3process.stdin.pipe(process.stdout);
modified:index.js+21 added
modified:package.json+1 added
modified:readme.md+7 added
114 unmodified lines
115116Prefer locally installed binaries when looking for a binary to execute.<br>117If you `$ npm install foo`, you can then `execa('foo')`.118119#### input120121Type: `string` `Buffer` `ReadableStream`122123Write some input to the `stdin` of your binary.<br>124Streams are not allowed when using the synchronous methods.125126127## License128129MIT © [Sindre Sorhus](https://sindresorhus.com)
modified:test.js+36 added
1import path from 'path';2import stream from 'stream';3import test from 'ava';4import getStream from 'get-stream';5import m from './';6
60 unmodified lines
67 await t.throws(m('cat-names', {preferLocal: false}), /spawn .* ENOENT/);68 process.env.PATH = _path;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 );104});105106test('execa() returns a promise with kill() and pid', t => {107 const promise = m('noop', ['foo']);108 t.is(typeof promise.kill, 'function');109 t.is(typeof promise.pid, 'number');
1 unmodified line