Skip to content

Commit

Permalink
Add a few more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Sep 1, 2024
1 parent 6a888f9 commit f669c99
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions test/helpers/arguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export const secondTestString = 'secondTest';
export const thirdTestString = 'thirdTest';
export const fourthTestString = 'fourthTest';
export const testUpperCase = testString.toUpperCase();
export const testDouble = `${testString}${testString}`;
export const testDoubleUpperCase = `${testUpperCase}${testUpperCase}`;

export const multibyteString = '.\u{1F984}.';
Expand Down
10 changes: 6 additions & 4 deletions test/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,15 @@ const testStdioPriority = async (t, stdio) => {
test('options.stdio array has priority over options.stdout', testStdioPriority, ['pipe', 'pipe', 'pipe']);
test('options.stdio string has priority over options.stdout', testStdioPriority, 'pipe');

const testInput = async (t, options) => {
const testInput = async (t, options, expectedStdout) => {
const {stdout} = await nanoSpawn(...nodePassThrough, options);
t.is(stdout, testString);
t.is(stdout, expectedStdout);
};

test('options.stdin can be {string: string}', testInput, {stdin: {string: testString}});
test('options.stdio[0] can be {string: string}', testInput, {stdio: [{string: testString}, 'pipe', 'pipe']});
test('options.stdin can be {string: string}', testInput, {stdin: {string: testString}}, testString);
test('options.stdio[0] can be {string: string}', testInput, {stdio: [{string: testString}, 'pipe', 'pipe']}, testString);
test('options.stdin can be {string: ""}', testInput, {stdin: {string: ''}}, '');
test('options.stdio[0] can be {string: ""}', testInput, {stdio: [{string: ''}, 'pipe', 'pipe']}, '');

const testLocalBinaryExec = async (t, cwd) => {
const {stdout} = await nanoSpawn(...localBinary, {preferLocal: true, cwd});
Expand Down
18 changes: 18 additions & 0 deletions test/pipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
testString,
testUpperCase,
testDoubleUpperCase,
testDouble,
} from './helpers/arguments.js';
import {
assertDurationMs,
Expand Down Expand Up @@ -335,3 +336,20 @@ process.stdout.on("error", () => {
t.is(stdout, '');
t.is(output, '');
});

test('.pipe() one source to multiple destinations', async t => {
const first = nanoSpawn(...nodePrintStdout);
const [firstResult, secondResult, thirdResult] = await Promise.all([
first,
first.pipe(...nodeToUpperCase),
first.pipe(...nodeDouble),
]);
t.is(secondResult.pipedFrom, firstResult);
t.is(thirdResult.pipedFrom, firstResult);
t.is(firstResult.stdout, testString);
t.is(firstResult.output, firstResult.stdout);
t.is(secondResult.stdout, testUpperCase);
t.is(secondResult.output, secondResult.stdout);
t.is(thirdResult.stdout, testDouble);
t.is(thirdResult.output, thirdResult.stdout);
});

0 comments on commit f669c99

Please sign in to comment.