Skip to content

Commit

Permalink
Rename internal variables
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Sep 1, 2024
1 parent 84a79b0 commit fa036ed
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 171 deletions.
10 changes: 5 additions & 5 deletions test/helpers/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ export const arrayFromAsync = async asyncIterable => {
return chunks;
};

export const destroySubprocessStream = async ({nodeChildProcess}, error, streamName) => {
const subprocess = await nodeChildProcess;
subprocess[streamName].destroy(error);
export const destroySubprocessStream = async (subprocess, error, streamName) => {
const nodeChildProcess = await subprocess.nodeChildProcess;
nodeChildProcess[streamName].destroy(error);
};

export const writeMultibyte = async promise => {
const {stdin} = await promise.nodeChildProcess;
export const writeMultibyte = async subprocess => {
const {stdin} = await subprocess.nodeChildProcess;
stdin.write(multibyteFirstHalf);
await setTimeout(1e2);
stdin.end(multibyteSecondHalf);
Expand Down
24 changes: 12 additions & 12 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ test('Can pass no arguments', async t => {
});

test('Can pass no arguments nor options', async t => {
const promise = nanoSpawn(...nodeHanging);
const nodeChildProcess = await promise.nodeChildProcess;
const subprocess = nanoSpawn(...nodeHanging);
const nodeChildProcess = await subprocess.nodeChildProcess;
nodeChildProcess.kill();
const error = await t.throwsAsync(promise);
const error = await t.throwsAsync(subprocess);
assertSigterm(t, error);
});

test('Returns a promise', async t => {
const promise = nanoSpawn(...nodePrintStdout);
t.false(Object.prototype.propertyIsEnumerable.call(promise, 'then'));
t.false(Object.hasOwn(promise, 'then'));
t.true(promise instanceof Promise);
await promise;
const subprocess = nanoSpawn(...nodePrintStdout);
t.false(Object.prototype.propertyIsEnumerable.call(subprocess, 'then'));
t.false(Object.hasOwn(subprocess, 'then'));
t.true(subprocess instanceof Promise);
await subprocess;
});

test('promise.nodeChildProcess is set', async t => {
const promise = nanoSpawn(...nodePrintStdout);
const nodeChildProcess = await promise.nodeChildProcess;
test('subprocess.nodeChildProcess is set', async t => {
const subprocess = nanoSpawn(...nodePrintStdout);
const nodeChildProcess = await subprocess.nodeChildProcess;
t.true(Number.isInteger(nodeChildProcess.pid));
await promise;
await subprocess;
});
209 changes: 105 additions & 104 deletions test/iterable.js

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions test/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,52 +54,52 @@ test('Can pass options.cwd string', testCwd, fixturesPath);
test('Can pass options.cwd URL', testCwd, FIXTURES_URL);

const testStdOption = async (t, optionName) => {
const promise = nanoSpawn(...nodePrintStdout, {[optionName]: 'ignore'});
const subprocess = await promise.nodeChildProcess;
t.is(subprocess[optionName], null);
await promise;
const subprocess = nanoSpawn(...nodePrintStdout, {[optionName]: 'ignore'});
const nodeChildProcess = await subprocess.nodeChildProcess;
t.is(nodeChildProcess[optionName], null);
await subprocess;
};

test('Can pass options.stdin', testStdOption, 'stdin');
test('Can pass options.stdout', testStdOption, 'stdout');
test('Can pass options.stderr', testStdOption, 'stderr');

const testStdOptionDefault = async (t, optionName) => {
const promise = nanoSpawn(...nodePrintStdout);
const subprocess = await promise.nodeChildProcess;
t.not(subprocess[optionName], null);
await promise;
const subprocess = nanoSpawn(...nodePrintStdout);
const nodeChildProcess = await subprocess.nodeChildProcess;
t.not(nodeChildProcess[optionName], null);
await subprocess;
};

test('options.stdin defaults to "pipe"', testStdOptionDefault, 'stdin');
test('options.stdout defaults to "pipe"', testStdOptionDefault, 'stdout');
test('options.stderr defaults to "pipe"', testStdOptionDefault, 'stderr');

test('Can pass options.stdio array', async t => {
const promise = nanoSpawn(...nodePrintStdout, {stdio: ['ignore', 'pipe', 'pipe', 'pipe']});
const {stdin, stdout, stderr, stdio} = await promise.nodeChildProcess;
const subprocess = nanoSpawn(...nodePrintStdout, {stdio: ['ignore', 'pipe', 'pipe', 'pipe']});
const {stdin, stdout, stderr, stdio} = await subprocess.nodeChildProcess;
t.is(stdin, null);
t.not(stdout, null);
t.not(stderr, null);
t.is(stdio.length, 4);
await promise;
await subprocess;
});

test('Can pass options.stdio string', async t => {
const promise = nanoSpawn(...nodePrintStdout, {stdio: 'ignore'});
const {stdin, stdout, stderr, stdio} = await promise.nodeChildProcess;
const subprocess = nanoSpawn(...nodePrintStdout, {stdio: 'ignore'});
const {stdin, stdout, stderr, stdio} = await subprocess.nodeChildProcess;
t.is(stdin, null);
t.is(stdout, null);
t.is(stderr, null);
t.is(stdio.length, 3);
await promise;
await subprocess;
});

const testStdioPriority = async (t, stdio) => {
const promise = nanoSpawn(...nodePrintStdout, {stdio, stdout: 'ignore'});
const {stdout} = await promise.nodeChildProcess;
const subprocess = nanoSpawn(...nodePrintStdout, {stdio, stdout: 'ignore'});
const {stdout} = await subprocess.nodeChildProcess;
t.not(stdout, null);
await promise;
await subprocess;
};

test('options.stdio array has priority over options.stdout', testStdioPriority, ['pipe', 'pipe', 'pipe']);
Expand Down
44 changes: 22 additions & 22 deletions test/pipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ test('.pipe() source fails due to stream error', async t => {
const first = nanoSpawn(...nodePrintStdout);
const second = first.pipe(...nodeToUpperCase);
const cause = new Error(testString);
const subprocess = await first.nodeChildProcess;
subprocess.stdout.destroy(cause);
const nodeChildProcess = await first.nodeChildProcess;
nodeChildProcess.stdout.destroy(cause);
const error = await t.throwsAsync(second);
assertErrorEvent(t, error, cause);
});
Expand All @@ -90,8 +90,8 @@ test('.pipe() destination fails due to stream error', async t => {
const first = nanoSpawn(...nodePrintStdout);
const second = first.pipe(...nodeToUpperCase);
const cause = new Error(testString);
const subprocess = await second.nodeChildProcess;
subprocess.stdin.destroy(cause);
const nodeChildProcess = await second.nodeChildProcess;
nodeChildProcess.stdin.destroy(cause);
const error = await t.throwsAsync(second);
assertErrorEvent(t, error, cause);
});
Expand Down Expand Up @@ -250,63 +250,63 @@ test('.pipe() with stdout stream in source', async t => {
});

test('.pipe() + stdout/stderr iteration', async t => {
const promise = nanoSpawn(...nodePrintStdout).pipe(...nodeToUpperCase);
const lines = await arrayFromAsync(promise);
const subprocess = nanoSpawn(...nodePrintStdout).pipe(...nodeToUpperCase);
const lines = await arrayFromAsync(subprocess);
t.deepEqual(lines, [testUpperCase]);
const {stdout, stderr, output} = await promise;
const {stdout, stderr, output} = await subprocess;
t.is(stdout, '');
t.is(stderr, '');
t.is(output, '');
});

test('.pipe() + stdout iteration', async t => {
const promise = nanoSpawn(...nodePrintStdout).pipe(...nodeToUpperCase);
const lines = await arrayFromAsync(promise.stdout);
const subprocess = nanoSpawn(...nodePrintStdout).pipe(...nodeToUpperCase);
const lines = await arrayFromAsync(subprocess.stdout);
t.deepEqual(lines, [testUpperCase]);
const {stdout, output} = await promise;
const {stdout, output} = await subprocess;
t.is(stdout, '');
t.is(output, '');
});

test('.pipe() + stderr iteration', async t => {
const promise = nanoSpawn(...nodePrintStdout).pipe(...nodeToUpperCaseStderr);
const lines = await arrayFromAsync(promise.stderr);
const subprocess = nanoSpawn(...nodePrintStdout).pipe(...nodeToUpperCaseStderr);
const lines = await arrayFromAsync(subprocess.stderr);
t.deepEqual(lines, [testUpperCase]);
const {stderr, output} = await promise;
const {stderr, output} = await subprocess;
t.is(stderr, '');
t.is(output, '');
});

test('.pipe() + stdout iteration, source fail', async t => {
const promise = nanoSpawn(...nodePrintFail).pipe(...nodeToUpperCase);
const error = await t.throwsAsync(arrayFromAsync(promise.stdout));
const subprocess = nanoSpawn(...nodePrintFail).pipe(...nodeToUpperCase);
const error = await t.throwsAsync(arrayFromAsync(subprocess.stdout));
assertFail(t, error);
t.is(error.stdout, testString);
const secondError = await t.throwsAsync(promise);
const secondError = await t.throwsAsync(subprocess);
t.is(secondError.stdout, testString);
t.is(secondError.output, secondError.stdout);
});

test('.pipe() + stdout iteration, destination fail', async t => {
const promise = nanoSpawn(...nodePrintStdout).pipe(...nodeToUpperCaseFail);
const error = await t.throwsAsync(arrayFromAsync(promise.stdout));
const subprocess = nanoSpawn(...nodePrintStdout).pipe(...nodeToUpperCaseFail);
const error = await t.throwsAsync(arrayFromAsync(subprocess.stdout));
assertFail(t, error);
t.is(error.stdout, '');
const secondError = await t.throwsAsync(promise);
const secondError = await t.throwsAsync(subprocess);
t.is(secondError.stdout, '');
t.is(secondError.output, '');
});

test('.pipe() with EPIPE', async t => {
const promise = nanoSpawn(...nodeEval(`setInterval(() => {
const subprocess = nanoSpawn(...nodeEval(`setInterval(() => {
console.log("${testString}");
}, 0);
process.stdout.on("error", () => {
process.exit();
});`)).pipe('head', ['-n', '2']);
const lines = await arrayFromAsync(promise);
const lines = await arrayFromAsync(subprocess);
t.deepEqual(lines, [testString, testString]);
const {stdout, output} = await promise;
const {stdout, output} = await subprocess;
t.is(stdout, '');
t.is(output, '');
});
16 changes: 8 additions & 8 deletions test/result.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ test('Error on "error" event during spawn', async t => {
});

test('Error on "error" event during spawn, with iteration', async t => {
const promise = nanoSpawn(...nodeHanging, {signal: AbortSignal.abort()});
const error = await t.throwsAsync(arrayFromAsync(promise.stdout));
const subprocess = nanoSpawn(...nodeHanging, {signal: AbortSignal.abort()});
const error = await t.throwsAsync(arrayFromAsync(subprocess.stdout));
assertSigterm(t, error);
});

Expand All @@ -75,10 +75,10 @@ if (isLinux) {
test('Error on "error" event after spawn', async t => {
const cause = new Error(testString);
const controller = new AbortController();
const promise = nanoSpawn(...nodeHanging, {signal: controller.signal});
await promise.nodeChildProcess;
const subprocess = nanoSpawn(...nodeHanging, {signal: controller.signal});
await subprocess.nodeChildProcess;
controller.abort(cause);
const error = await t.throwsAsync(promise);
const error = await t.throwsAsync(subprocess);
assertAbortError(t, error, cause);
});
}
Expand Down Expand Up @@ -135,10 +135,10 @@ setTimeout(() => {
});

const testStreamError = async (t, streamName) => {
const promise = nanoSpawn(...nodePrintStdout);
const subprocess = nanoSpawn(...nodePrintStdout);
const cause = new Error(testString);
destroySubprocessStream(promise, cause, streamName);
const error = await t.throwsAsync(promise);
destroySubprocessStream(subprocess, cause, streamName);
const error = await t.throwsAsync(subprocess);
assertErrorEvent(t, error, cause);
};

Expand Down
6 changes: 3 additions & 3 deletions test/spawn.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ test('result.output is an empty string if options.stdout and options.stderr "ign
});

test.serial('result.stdout works with multibyte sequences', async t => {
const promise = nanoSpawn(...nodePassThrough);
writeMultibyte(promise);
const {stdout, output} = await promise;
const subprocess = nanoSpawn(...nodePassThrough);
writeMultibyte(subprocess);
const {stdout, output} = await subprocess;
t.is(stdout, multibyteString);
t.is(output, stdout);
});

0 comments on commit fa036ed

Please sign in to comment.