Skip to content
Myr

template.js

This file

Path

test/pipe/template.js

272 lines · 9.1 KiB · JavaScript

Last changed by

Allow piping process to any file descriptor (#903)ehmickybefore adoption6642cd2

History of this file

Take it

Fix errors thrown by `.pipe()` (#854)ehmickybefore adoption46ba4b4

line 1why, one step back
1import {spawn} from 'node:child_process';

Add `.pipe(command, args, options)` shortcut (#864)ehmickybefore adoption08f8e5d

line 2why, one step back
2import {pathToFileURL} from 'node:url';

Fix errors thrown by `.pipe()` (#854)ehmickybefore adoption46ba4b4

line 3why, one step back
3import test from 'ava';

Improve `.pipe()` method (#859)ehmickybefore adoption2ef9e86

line 4why, one step back
4import {$, execa} from '../../index.js';

Add `.pipe(command, args, options)` shortcut (#864)ehmickybefore adoption08f8e5d

line 5why, one step back
5import {setFixtureDir, FIXTURES_DIR} from '../helpers/fixtures-dir.js';

Fix errors thrown by `.pipe()` (#854)ehmickybefore adoption46ba4b4

lines 6–9why, one step back
6import {foobarString} from '../helpers/input.js';
78setFixtureDir();9

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 10why, one step back
10test('$.pipe(subprocess)', async t => {

Fix errors thrown by `.pipe()` (#854)ehmickybefore adoption46ba4b4

lines 11–14why, one step back
11 const {stdout} = await $`noop.js ${foobarString}`.pipe($({stdin: 'pipe'})`stdin.js`);
12 t.is(stdout, foobarString);13});14

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 15why, one step back
15test('execa.$.pipe(subprocess)', async t => {

Improve `.pipe()` method (#859)ehmickybefore adoption2ef9e86

lines 16–19why, one step back
16 const {stdout} = await execa('noop.js', [foobarString]).pipe($({stdin: 'pipe'})`stdin.js`);
17 t.is(stdout, foobarString);18});19

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 20why, one step back
20test('$.pipe.pipe(subprocess)', async t => {

Fix errors thrown by `.pipe()` (#854)ehmickybefore adoption46ba4b4

lines 21–31why, one step back
21 const {stdout} = await $`noop.js ${foobarString}`
22 .pipe($({stdin: 'pipe'})`stdin.js`)23 .pipe($({stdin: 'pipe'})`stdin.js`);24 t.is(stdout, foobarString);25});2627test('$.pipe`command`', async t => {28 const {stdout} = await $`noop.js ${foobarString}`.pipe`stdin.js`;29 t.is(stdout, foobarString);30});31

Improve `.pipe()` method (#859)ehmickybefore adoption2ef9e86

lines 32–36why, one step back
32test('execa.$.pipe`command`', async t => {
33 const {stdout} = await execa('noop.js', [foobarString]).pipe`stdin.js`;34 t.is(stdout, foobarString);35});36

Fix errors thrown by `.pipe()` (#854)ehmickybefore adoption46ba4b4

lines 37–43why, one step back
37test('$.pipe.pipe`command`', async t => {
38 const {stdout} = await $`noop.js ${foobarString}`39 .pipe`stdin.js`40 .pipe`stdin.js`;41 t.is(stdout, foobarString);42});43

Add `.pipe(command, args, options)` shortcut (#864)ehmickybefore adoption08f8e5d

lines 44–82why, one step back
44test('$.pipe("file")', async t => {
45 const {stdout} = await $`noop.js ${foobarString}`.pipe('stdin.js');46 t.is(stdout, foobarString);47});4849test('execa.$.pipe("file")`', async t => {50 const {stdout} = await execa('noop.js', [foobarString]).pipe('stdin.js');51 t.is(stdout, foobarString);52});5354test('$.pipe.pipe("file")', async t => {55 const {stdout} = await $`noop.js ${foobarString}`56 .pipe`stdin.js`57 .pipe('stdin.js');58 t.is(stdout, foobarString);59});6061test('execa.$.pipe(fileUrl)`', async t => {62 const {stdout} = await execa('noop.js', [foobarString]).pipe(pathToFileURL(`${FIXTURES_DIR}/stdin.js`));63 t.is(stdout, foobarString);64});6566test('$.pipe("file", args, options)', async t => {67 const {stdout} = await $`noop.js ${foobarString}`.pipe('node', ['stdin.js'], {cwd: FIXTURES_DIR});68 t.is(stdout, foobarString);69});7071test('execa.$.pipe("file", args, options)`', async t => {72 const {stdout} = await execa('noop.js', [foobarString]).pipe('node', ['stdin.js'], {cwd: FIXTURES_DIR});73 t.is(stdout, foobarString);74});7576test('$.pipe.pipe("file", args, options)', async t => {77 const {stdout} = await $`noop.js ${foobarString}`78 .pipe`stdin.js`79 .pipe('node', ['stdin.js'], {cwd: FIXTURES_DIR});80 t.is(stdout, foobarString);81});82

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 83why, one step back
83test('$.pipe(subprocess, pipeOptions)', async t => {

Fix errors thrown by `.pipe()` (#854)ehmickybefore adoption46ba4b4

lines 84–87why, one step back
84 const {stdout} = await $`noop-fd.js 2 ${foobarString}`.pipe($({stdin: 'pipe'})`stdin.js`, {from: 'stderr'});
85 t.is(stdout, foobarString);86});87

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 88why, one step back
88test('execa.$.pipe(subprocess, pipeOptions)', async t => {

Improve `.pipe()` method (#859)ehmickybefore adoption2ef9e86

lines 89–92why, one step back
89 const {stdout} = await execa('noop-fd.js', ['2', foobarString]).pipe($({stdin: 'pipe'})`stdin.js`, {from: 'stderr'});
90 t.is(stdout, foobarString);91});92

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 93why, one step back
93test('$.pipe.pipe(subprocess, pipeOptions)', async t => {

Fix errors thrown by `.pipe()` (#854)ehmickybefore adoption46ba4b4

lines 94–104why, one step back
94 const {stdout} = await $`noop-fd.js 2 ${foobarString}`
95 .pipe($({stdin: 'pipe'})`noop-stdin-fd.js 2`, {from: 'stderr'})96 .pipe($({stdin: 'pipe'})`stdin.js`, {from: 'stderr'});97 t.is(stdout, foobarString);98});99100test('$.pipe(pipeOptions)`command`', async t => {101 const {stdout} = await $`noop-fd.js 2 ${foobarString}`.pipe({from: 'stderr'})`stdin.js`;102 t.is(stdout, foobarString);103});104

Improve `.pipe()` method (#859)ehmickybefore adoption2ef9e86

lines 105–109why, one step back
105test('execa.$.pipe(pipeOptions)`command`', async t => {
106 const {stdout} = await execa('noop-fd.js', ['2', foobarString]).pipe({from: 'stderr'})`stdin.js`;107 t.is(stdout, foobarString);108});109

Fix errors thrown by `.pipe()` (#854)ehmickybefore adoption46ba4b4

lines 110–116why, one step back
110test('$.pipe.pipe(pipeOptions)`command`', async t => {
111 const {stdout} = await $`noop-fd.js 2 ${foobarString}`112 .pipe({from: 'stderr'})`noop-stdin-fd.js 2`113 .pipe({from: 'stderr'})`stdin.js`;114 t.is(stdout, foobarString);115});116

Add `.pipe(command, args, options)` shortcut (#864)ehmickybefore adoption08f8e5d

lines 117–133why, one step back
117test('$.pipe("file", pipeOptions)', async t => {
118 const {stdout} = await $`noop-fd.js 2 ${foobarString}`.pipe('stdin.js', {from: 'stderr'});119 t.is(stdout, foobarString);120});121122test('execa.$.pipe("file", pipeOptions)', async t => {123 const {stdout} = await execa('noop-fd.js', ['2', foobarString]).pipe('stdin.js', {from: 'stderr'});124 t.is(stdout, foobarString);125});126127test('$.pipe.pipe("file", pipeOptions)', async t => {128 const {stdout} = await $`noop-fd.js 2 ${foobarString}`129 .pipe({from: 'stderr'})`noop-stdin-fd.js 2`130 .pipe('stdin.js', {from: 'stderr'});131 t.is(stdout, foobarString);132});133

Fix errors thrown by `.pipe()` (#854)ehmickybefore adoption46ba4b4

lines 134–138why, one step back
134test('$.pipe(options)`command`', async t => {
135 const {stdout} = await $`noop.js ${foobarString}`.pipe({stripFinalNewline: false})`stdin.js`;136 t.is(stdout, `${foobarString}\n`);137});138

Improve `.pipe()` method (#859)ehmickybefore adoption2ef9e86

lines 139–143why, one step back
139test('execa.$.pipe(options)`command`', async t => {
140 const {stdout} = await execa('noop.js', [foobarString]).pipe({stripFinalNewline: false})`stdin.js`;141 t.is(stdout, `${foobarString}\n`);142});143

Fix errors thrown by `.pipe()` (#854)ehmickybefore adoption46ba4b4

lines 144–150why, one step back
144test('$.pipe.pipe(options)`command`', async t => {
145 const {stdout} = await $`noop.js ${foobarString}`146 .pipe({})`stdin.js`147 .pipe({stripFinalNewline: false})`stdin.js`;148 t.is(stdout, `${foobarString}\n`);149});150

Add `.pipe(command, args, options)` shortcut (#864)ehmickybefore adoption08f8e5d

lines 151–167why, one step back
151test('$.pipe("file", options)', async t => {
152 const {stdout} = await $`noop.js ${foobarString}`.pipe('stdin.js', {stripFinalNewline: false});153 t.is(stdout, `${foobarString}\n`);154});155156test('execa.$.pipe("file", options)', async t => {157 const {stdout} = await execa('noop.js', [foobarString]).pipe('stdin.js', {stripFinalNewline: false});158 t.is(stdout, `${foobarString}\n`);159});160161test('$.pipe.pipe("file", options)', async t => {162 const {stdout} = await $`noop.js ${foobarString}`163 .pipe({})`stdin.js`164 .pipe('stdin.js', {stripFinalNewline: false});165 t.is(stdout, `${foobarString}\n`);166});167

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 168why, one step back
168test('$.pipe(pipeAndSubprocessOptions)`command`', async t => {

Fix errors thrown by `.pipe()` (#854)ehmickybefore adoption46ba4b4

lines 169–172why, one step back
169 const {stdout} = await $`noop-fd.js 2 ${foobarString}\n`.pipe({from: 'stderr', stripFinalNewline: false})`stdin.js`;
170 t.is(stdout, `${foobarString}\n`);171});172

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 173why, one step back
173test('execa.$.pipe(pipeAndSubprocessOptions)`command`', async t => {

Improve `.pipe()` method (#859)ehmickybefore adoption2ef9e86

lines 174–177why, one step back
174 const {stdout} = await execa('noop-fd.js', ['2', `${foobarString}\n`]).pipe({from: 'stderr', stripFinalNewline: false})`stdin.js`;
175 t.is(stdout, `${foobarString}\n`);176});177

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 178why, one step back
178test('$.pipe.pipe(pipeAndSubprocessOptions)`command`', async t => {

Fix errors thrown by `.pipe()` (#854)ehmickybefore adoption46ba4b4

lines 179–184why, one step back
179 const {stdout} = await $`noop-fd.js 2 ${foobarString}\n`
180 .pipe({from: 'stderr'})`noop-stdin-fd.js 2`181 .pipe({from: 'stderr', stripFinalNewline: false})`stdin.js`;182 t.is(stdout, `${foobarString}\n`);183});184

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 185why, one step back
185test('$.pipe("file", pipeAndSubprocessOptions)', async t => {

Add `.pipe(command, args, options)` shortcut (#864)ehmickybefore adoption08f8e5d

lines 186–189why, one step back
186 const {stdout} = await $`noop-fd.js 2 ${foobarString}\n`.pipe('stdin.js', {from: 'stderr', stripFinalNewline: false});
187 t.is(stdout, `${foobarString}\n`);188});189

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 190why, one step back
190test('execa.$.pipe("file", pipeAndSubprocessOptions)', async t => {

Add `.pipe(command, args, options)` shortcut (#864)ehmickybefore adoption08f8e5d

lines 191–194why, one step back
191 const {stdout} = await execa('noop-fd.js', ['2', `${foobarString}\n`]).pipe('stdin.js', {from: 'stderr', stripFinalNewline: false});
192 t.is(stdout, `${foobarString}\n`);193});194

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 195why, one step back
195test('$.pipe.pipe("file", pipeAndSubprocessOptions)', async t => {

Add `.pipe(command, args, options)` shortcut (#864)ehmickybefore adoption08f8e5d

lines 196–201why, one step back
196 const {stdout} = await $`noop-fd.js 2 ${foobarString}\n`
197 .pipe({from: 'stderr'})`noop-stdin-fd.js 2`198 .pipe('stdin.js', {from: 'stderr', stripFinalNewline: false});199 t.is(stdout, `${foobarString}\n`);200});201

Fix errors thrown by `.pipe()` (#854)ehmickybefore adoption46ba4b4

lines 202–206why, one step back
202test('$.pipe(options)(secondOptions)`command`', async t => {
203 const {stdout} = await $`noop.js ${foobarString}`.pipe({stripFinalNewline: false})({stripFinalNewline: true})`stdin.js`;204 t.is(stdout, foobarString);205});206

Improve `.pipe()` method (#859)ehmickybefore adoption2ef9e86

lines 207–211why, one step back
207test('execa.$.pipe(options)(secondOptions)`command`', async t => {
208 const {stdout} = await execa('noop.js', [foobarString]).pipe({stripFinalNewline: false})({stripFinalNewline: true})`stdin.js`;209 t.is(stdout, foobarString);210});211

Fix errors thrown by `.pipe()` (#854)ehmickybefore adoption46ba4b4

lines 212–218why, one step back
212test('$.pipe.pipe(options)(secondOptions)`command`', async t => {
213 const {stdout} = await $`noop.js ${foobarString}`214 .pipe({})({})`stdin.js`215 .pipe({stripFinalNewline: false})({stripFinalNewline: true})`stdin.js`;216 t.is(stdout, foobarString);217});218

Add `.pipe(command, args, options)` shortcut (#864)ehmickybefore adoption08f8e5d

lines 219–228why, one step back
219test('$.pipe`command` forces "stdin: pipe"', async t => {
220 const {stdout} = await $`noop.js ${foobarString}`.pipe({stdin: 'ignore'})`stdin.js`;221 t.is(stdout, foobarString);222});223224test('execa.pipe("file") forces "stdin: "pipe"', async t => {225 const {stdout} = await execa('noop.js', [foobarString]).pipe('stdin.js', {stdin: 'ignore'});226 t.is(stdout, foobarString);227});228

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 229why, one step back
229test('execa.pipe(subprocess) does not force "stdin: pipe"', async t => {

Add `.pipe(command, args, options)` shortcut (#864)ehmickybefore adoption08f8e5d

lines 230–231why, one step back
230 await t.throwsAsync(
231 execa('noop.js', [foobarString]).pipe(execa('stdin.js', {stdin: 'ignore'})),

Allow piping process to any file descriptor (#903)ehmickybefore adoption6642cd2

line 232why, one step back
232 {message: /"stdin: 'ignore'" option is incompatible/},

Add `.pipe(command, args, options)` shortcut (#864)ehmickybefore adoption08f8e5d

lines 233–235why, one step back
233 );
234});235

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 236why, one step back
236test('$.pipe(options)(subprocess) fails', async t => {

Improve `.pipe()` method (#859)ehmickybefore adoption2ef9e86

lines 237–240why, one step back
237 await t.throwsAsync(
238 $`empty.js`.pipe({stdout: 'pipe'})($`empty.js`),239 {message: /Please use \.pipe/},240 );

Fix errors thrown by `.pipe()` (#854)ehmickybefore adoption46ba4b4

lines 241–242why, one step back
241});
242

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 243why, one step back
243test('execa.$.pipe(options)(subprocess) fails', async t => {

Improve `.pipe()` method (#859)ehmickybefore adoption2ef9e86

lines 244–245why, one step back
244 await t.throwsAsync(
245 execa('empty.js').pipe({stdout: 'pipe'})($`empty.js`),

Add `.pipe(command, args, options)` shortcut (#864)ehmickybefore adoption08f8e5d

lines 246–259why, one step back
246 {message: /Please use \.pipe/},
247 );248});249250test('$.pipe(options)("file") fails', async t => {251 await t.throwsAsync(252 $`empty.js`.pipe({stdout: 'pipe'})('empty.js'),253 {message: /Please use \.pipe/},254 );255});256257test('execa.$.pipe(options)("file") fails', async t => {258 await t.throwsAsync(259 execa('empty.js').pipe({stdout: 'pipe'})('empty.js'),

Improve `.pipe()` method (#859)ehmickybefore adoption2ef9e86

lines 260–268why, one step back
260 {message: /Please use \.pipe/},
261 );262});263264const testInvalidPipe = async (t, ...args) => {265 await t.throwsAsync(266 $`empty.js`.pipe(...args),267 {message: /must be a template string/},268 );

Fix errors thrown by `.pipe()` (#854)ehmickybefore adoption46ba4b4

lines 269–270why, one step back
269};
270

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 271why, one step back
271test('$.pipe(nonExecaSubprocess) fails', testInvalidPipe, spawn('node', ['--version']));

Fix errors thrown by `.pipe()` (#854)ehmickybefore adoption46ba4b4

line 272why, one step back
272test('$.pipe(false) fails', testInvalidPipe, false);