Skip to content

Commit 18d320f

Browse files
authored
Refactor test helpers for the verbose option (#1128)
1 parent 37e0024 commit 18d320f

41 files changed

Lines changed: 720 additions & 717 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

test/fixtures/nested-double.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#!/usr/bin/env node
2-
import process from 'node:process';
3-
import {execa} from '../../index.js';
2+
import {execa, getOneMessage} from '../../index.js';
43

5-
const [options, file, ...commandArguments] = process.argv.slice(2);
4+
const {file, commandArguments, options} = await getOneMessage();
65
const firstArguments = commandArguments.slice(0, -1);
76
const lastArgument = commandArguments.at(-1);
87
await Promise.all([
9-
execa(file, [...firstArguments, lastArgument], JSON.parse(options)),
10-
execa(file, [...firstArguments, lastArgument.toUpperCase()], JSON.parse(options)),
8+
execa(file, [...firstArguments, lastArgument], options),
9+
execa(file, [...firstArguments, lastArgument.toUpperCase()], options),
1110
]);

test/fixtures/nested-fail.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#!/usr/bin/env node
2-
import process from 'node:process';
3-
import {execa} from '../../index.js';
2+
import {execa, getOneMessage} from '../../index.js';
43

5-
const [options, file, ...commandArguments] = process.argv.slice(2);
6-
const subprocess = execa(file, commandArguments, JSON.parse(options));
4+
const {file, commandArguments, options} = await getOneMessage();
5+
const subprocess = execa(file, commandArguments, options);
76
subprocess.kill(new Error(commandArguments[0]));
87
await subprocess;

test/fixtures/nested-file-url.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

test/fixtures/nested-input.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

test/fixtures/nested-pipe-file.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
#!/usr/bin/env node
2-
import process from 'node:process';
3-
import {execa} from '../../index.js';
2+
import {execa, getOneMessage} from '../../index.js';
43

5-
const [
6-
sourceOptions,
7-
sourceFile,
8-
sourceArgument,
9-
destinationOptions,
10-
destinationFile,
11-
destinationArgument,
12-
] = process.argv.slice(2);
13-
await execa(sourceFile, [sourceArgument], JSON.parse(sourceOptions))
14-
.pipe(destinationFile, destinationArgument === undefined ? [] : [destinationArgument], JSON.parse(destinationOptions));
4+
const {
5+
file,
6+
commandArguments = [],
7+
options: {
8+
sourceOptions = {},
9+
destinationFile,
10+
destinationArguments = [],
11+
destinationOptions = {},
12+
},
13+
} = await getOneMessage();
14+
await execa(file, commandArguments, sourceOptions)
15+
.pipe(destinationFile, destinationArguments, destinationOptions);
Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
#!/usr/bin/env node
2-
import process from 'node:process';
3-
import {$} from '../../index.js';
2+
import {$, getOneMessage} from '../../index.js';
43

5-
const [
6-
sourceOptions,
7-
sourceFile,
8-
sourceArgument,
9-
destinationOptions,
10-
destinationFile,
11-
destinationArgument,
12-
] = process.argv.slice(2);
13-
await $(JSON.parse(sourceOptions))`${sourceFile} ${sourceArgument}`
14-
.pipe(JSON.parse(destinationOptions))`${destinationFile} ${destinationArgument === undefined ? [] : [destinationArgument]}`;
4+
const {
5+
file,
6+
commandArguments = [],
7+
options: {
8+
sourceOptions = {},
9+
destinationFile,
10+
destinationArguments = [],
11+
destinationOptions = {},
12+
},
13+
} = await getOneMessage();
14+
await $(sourceOptions)`${file} ${commandArguments}`
15+
.pipe(destinationOptions)`${destinationFile} ${destinationArguments}`;

test/fixtures/nested-pipe-stream.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/usr/bin/env node
22
import process from 'node:process';
3-
import {execa} from '../../index.js';
3+
import {execa, getOneMessage} from '../../index.js';
44

5-
const [options, file, commandArgument, unpipe] = process.argv.slice(2);
6-
const subprocess = execa(file, [commandArgument], JSON.parse(options));
5+
const {file, commandArguments, options: {unpipe, ...options}} = await getOneMessage();
6+
const subprocess = execa(file, commandArguments, options);
77
subprocess.stdout.pipe(process.stdout);
8-
if (unpipe === 'true') {
8+
if (unpipe) {
99
subprocess.stdout.unpipe(process.stdout);
1010
}
1111

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
#!/usr/bin/env node
2-
import process from 'node:process';
3-
import {execa} from '../../index.js';
2+
import {execa, getOneMessage} from '../../index.js';
43

5-
const [options, file, commandArgument, unpipe] = process.argv.slice(2);
6-
const source = execa(file, [commandArgument], JSON.parse(options));
4+
const {file, commandArguments, options: {unpipe, ...options}} = await getOneMessage();
5+
const source = execa(file, commandArguments, options);
76
const destination = execa('stdin.js');
87
const controller = new AbortController();
9-
const pipePromise = source.pipe(destination, {unpipeSignal: controller.signal});
10-
if (unpipe === 'true') {
8+
const subprocess = source.pipe(destination, {unpipeSignal: controller.signal});
9+
if (unpipe) {
1110
controller.abort();
1211
destination.stdin.end();
1312
}
1413

15-
await Promise.allSettled([source, destination, pipePromise]);
14+
try {
15+
await subprocess;
16+
} catch {}
Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
#!/usr/bin/env node
2-
import process from 'node:process';
3-
import {execa} from '../../index.js';
2+
import {execa, getOneMessage} from '../../index.js';
43

5-
const [
6-
sourceOptions,
7-
sourceFile,
8-
sourceArgument,
9-
destinationOptions,
10-
destinationFile,
11-
destinationArgument,
12-
] = process.argv.slice(2);
13-
await execa(sourceFile, [sourceArgument], JSON.parse(sourceOptions))
14-
.pipe(execa(destinationFile, destinationArgument === undefined ? [] : [destinationArgument], JSON.parse(destinationOptions)));
4+
const {
5+
file,
6+
commandArguments = [],
7+
options: {
8+
sourceOptions = {},
9+
destinationFile,
10+
destinationArguments = [],
11+
destinationOptions = {},
12+
},
13+
} = await getOneMessage();
14+
await execa(file, commandArguments, sourceOptions)
15+
.pipe(execa(destinationFile, destinationArguments, destinationOptions));

test/fixtures/nested-sync.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)