From 2632152782d9743e68c8d2a1d9a09a9e1bd20330 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Tue, 7 Jul 2026 13:45:19 +0200 Subject: [PATCH] Update dev dependencies --- lib/arguments/command-file.js | 8 ++-- lib/arguments/encoding-option.js | 2 +- lib/ipc/graceful.js | 6 +-- lib/ipc/methods.js | 6 +-- lib/methods/template.js | 8 ++-- lib/resolve/exit-sync.js | 4 +- lib/transform/split.js | 20 +++++---- lib/verbose/output.js | 4 +- package.json | 2 +- test-d/return/result-stdio.test-d.ts | 6 +-- .../option/generator-boolean-full.test-d.ts | 1 + .../stdio/option/generator-boolean.test-d.ts | 1 + test-d/stdio/option/input-pipe.test-d.ts | 4 +- test-d/subprocess/stdio.test-d.ts | 6 +-- test-d/verbose.test-d.ts | 2 + test/arguments/escape.js | 2 +- test/convert/readable.js | 5 +-- test/fixtures/ipc-get-send-get.js | 4 +- test/fixtures/ipc-iterate-back-serial.js | 4 +- test/fixtures/ipc-iterate-back.js | 4 +- test/fixtures/ipc-print-many.js | 4 +- test/fixtures/ipc-process-error.js | 4 +- test/fixtures/ipc-send-pid.js | 8 ++-- test/helpers/ipc.js | 7 +--- test/ipc/forward.js | 6 +-- test/ipc/get-one.js | 14 +++---- test/ipc/incoming.js | 6 +-- test/ipc/outgoing.js | 10 ++--- test/methods/main-async.js | 1 + test/pipe/methods.js | 42 ++++++------------- test/return/early-error.js | 10 +---- test/stdio/node-stream-custom.js | 6 +-- test/stdio/web-stream.js | 6 +-- test/transform/encoding-multibyte.js | 2 +- test/verbose/output-progressive.js | 10 ++--- 35 files changed, 106 insertions(+), 129 deletions(-) diff --git a/lib/arguments/command-file.js b/lib/arguments/command-file.js index f50509d5ff..f3c1442ad6 100644 --- a/lib/arguments/command-file.js +++ b/lib/arguments/command-file.js @@ -43,10 +43,10 @@ const escapeWindowsCommand = parsed => { assertNoLineBreak(value); } - const doubleEscape = resolvedFile !== undefined && batchFileRegExp.test(resolvedFile); + const isDoubleEscape = resolvedFile !== undefined && batchFileRegExp.test(resolvedFile); // POSIX separators must become Windows ones (`foo/bar` -> `foo\bar`), otherwise resolution always fails with ENOENT const escapedFile = escapeMetaChars(path.normalize(parsed.file)); - const escapedArguments = parsed.commandArguments.map(argument => escapeArgument(argument, doubleEscape)); + const escapedArguments = parsed.commandArguments.map(argument => escapeArgument(argument, isDoubleEscape)); const commandLine = `"${[escapedFile, ...escapedArguments].join(' ')}"`; // Let `node:child_process` pass the already-escaped command line through untouched @@ -149,8 +149,8 @@ const escapeArgument = (rawArgument, doubleEscape) => { const argument = `${rawArgument}` .replaceAll(backslashRunRegExp, (backslashes, offset, string) => { const nextCharacter = string[offset + backslashes.length]; - const precedesDoubleQuote = nextCharacter === '"' || nextCharacter === undefined; - return precedesDoubleQuote ? backslashes.repeat(2) : backslashes; + const isPrecedesDoubleQuote = nextCharacter === '"' || nextCharacter === undefined; + return isPrecedesDoubleQuote ? backslashes.repeat(2) : backslashes; }) .replaceAll('"', '\\"'); diff --git a/lib/arguments/encoding-option.js b/lib/arguments/encoding-option.js index c3ec6b8c0d..5a7e264c9a 100644 --- a/lib/arguments/encoding-option.js +++ b/lib/arguments/encoding-option.js @@ -17,7 +17,7 @@ Please rename it to one of: ${correctEncodings}.`); const TEXT_ENCODINGS = new Set(['utf8', 'utf16le']); export const BINARY_ENCODINGS = new Set(['buffer', 'hex', 'base64', 'base64url', 'latin1', 'ascii']); -const ENCODINGS = new Set([...TEXT_ENCODINGS, ...BINARY_ENCODINGS]); +const ENCODINGS = TEXT_ENCODINGS.union(BINARY_ENCODINGS); const getCorrectEncoding = encoding => { if (encoding === null) { diff --git a/lib/ipc/graceful.js b/lib/ipc/graceful.js index 7931ecacaa..a27f51d5b1 100644 --- a/lib/ipc/graceful.js +++ b/lib/ipc/graceful.js @@ -29,11 +29,11 @@ export const getCancelSignal = async ({anyProcess, channel, isSubprocess, ipc}) }; const startIpc = async ({anyProcess, channel, isSubprocess, ipc}) => { - if (cancelListening) { + if (isCancelListening) { return; } - cancelListening = true; + isCancelListening = true; if (!ipc) { throwOnMissingParent(); @@ -49,7 +49,7 @@ const startIpc = async ({anyProcess, channel, isSubprocess, ipc}) => { await scheduler.yield(); }; -let cancelListening = false; +let isCancelListening = false; // Reception of IPC message to perform a graceful termination export const handleAbort = wrappedMessage => { diff --git a/lib/ipc/methods.js b/lib/ipc/methods.js index 284d85778f..42c91c775e 100644 --- a/lib/ipc/methods.js +++ b/lib/ipc/methods.js @@ -13,15 +13,15 @@ export const addIpcMethods = (target, subprocess, {ipc}) => { export const getIpcExport = () => { const anyProcess = process; const isSubprocess = true; - const ipc = process.channel !== undefined; + const isIpc = process.channel !== undefined; return { - ...getIpcMethods(anyProcess, isSubprocess, ipc), + ...getIpcMethods(anyProcess, isSubprocess, isIpc), getCancelSignal: getCancelSignal.bind(undefined, { anyProcess, channel: anyProcess.channel, isSubprocess, - ipc, + ipc: isIpc, }), }; }; diff --git a/lib/methods/template.js b/lib/methods/template.js index 6b7745ea3a..9cf24f18a5 100644 --- a/lib/methods/template.js +++ b/lib/methods/template.js @@ -59,7 +59,7 @@ const splitByWhitespaces = (template, rawTemplate) => { const nextTokens = []; let templateStart = 0; - const leadingWhitespaces = DELIMITERS.has(rawTemplate[0]); + const isLeadingWhitespaces = DELIMITERS.has(rawTemplate[0]); for ( let templateIndex = 0, rawIndex = 0; @@ -87,12 +87,12 @@ const splitByWhitespaces = (template, rawTemplate) => { } } - const trailingWhitespaces = templateStart === template.length; - if (!trailingWhitespaces) { + const isTrailingWhitespaces = templateStart === template.length; + if (!isTrailingWhitespaces) { nextTokens.push(template.slice(templateStart)); } - return {nextTokens, leadingWhitespaces, trailingWhitespaces}; + return {nextTokens, leadingWhitespaces: isLeadingWhitespaces, trailingWhitespaces: isTrailingWhitespaces}; }; const DELIMITERS = new Set([' ', '\t', '\r', '\n']); diff --git a/lib/resolve/exit-sync.js b/lib/resolve/exit-sync.js index 2ab0b37427..3bb4ce1262 100644 --- a/lib/resolve/exit-sync.js +++ b/lib/resolve/exit-sync.js @@ -5,13 +5,13 @@ import {isFailedExit} from './exit-async.js'; // Retrieve exit code, signal name and error information, with synchronous methods export const getExitResultSync = ({error, status: exitCode, signal, output}, {maxBuffer}) => { const resultError = getResultError(error, exitCode, signal); - const timedOut = resultError?.code === 'ETIMEDOUT'; + const isTimedOut = resultError?.code === 'ETIMEDOUT'; const isMaxBuffer = isMaxBufferSync(resultError, output, maxBuffer); return { resultError, exitCode, signal, - timedOut, + timedOut: isTimedOut, isMaxBuffer, }; }; diff --git a/lib/transform/split.js b/lib/transform/split.js index 47eb995b88..e36a13f0ca 100644 --- a/lib/transform/split.js +++ b/lib/transform/split.js @@ -32,18 +32,20 @@ const splitGenerator = function * (state, preserveNewlines, chunk) { let start = -1; for (let end = 0; end < chunk.length; end += 1) { - if (chunk[end] === '\n') { - const newlineLength = getNewlineLength(chunk, end, preserveNewlines, state); - let line = chunk.slice(start + 1, end + 1 - newlineLength); + if (chunk[end] !== '\n') { + continue; + } - if (previousChunks.length > 0) { - line = concatString(previousChunks, line); - previousChunks = ''; - } + const newlineLength = getNewlineLength(chunk, end, preserveNewlines, state); + let line = chunk.slice(start + 1, end + 1 - newlineLength); - yield line; - start = end; + if (previousChunks.length > 0) { + line = concatString(previousChunks, line); + previousChunks = ''; } + + yield line; + start = end; } if (start !== chunk.length - 1) { diff --git a/lib/verbose/output.js b/lib/verbose/output.js index 31cd900b63..846472edda 100644 --- a/lib/verbose/output.js +++ b/lib/verbose/output.js @@ -11,7 +11,7 @@ import {isFullVerbose} from './values.js'; export const shouldLogOutput = ({stdioItems, encoding, verboseInfo, fdNumber}) => fdNumber !== 'all' && isFullVerbose(verboseInfo, fdNumber) && !BINARY_ENCODINGS.has(encoding) - && fdUsesVerbose(fdNumber) + && isFdVerbose(fdNumber) && (stdioItems.some(({type, value}) => type === 'native' && PIPED_STDIO_VALUES.has(value)) || stdioItems.every(({type}) => TRANSFORM_TYPES.has(type))); @@ -19,7 +19,7 @@ export const shouldLogOutput = ({stdioItems, encoding, verboseInfo, fdNumber}) = // Files and streams can produce big outputs, which we don't want to print. // We could print `stdio[3+]` but it often is redirected to files and streams, with the same issue. // So we only print stdout and stderr. -const fdUsesVerbose = fdNumber => fdNumber === 1 || fdNumber === 2; +const isFdVerbose = fdNumber => fdNumber === 1 || fdNumber === 2; const PIPED_STDIO_VALUES = new Set(['pipe', 'overlapped']); diff --git a/package.json b/package.json index 449d0aae63..a5c518bb14 100644 --- a/package.json +++ b/package.json @@ -77,7 +77,7 @@ "tempfile": "^6.0.1", "tsd": "^0.33.0", "typescript": "^6.0.3", - "xo": "^3.0.2" + "xo": "^4.0.0" }, "c8": { "reporter": [ diff --git a/test-d/return/result-stdio.test-d.ts b/test-d/return/result-stdio.test-d.ts index bc03428d92..34b029120a 100644 --- a/test-d/return/result-stdio.test-d.ts +++ b/test-d/return/result-stdio.test-d.ts @@ -123,11 +123,11 @@ expectType(inputFdFd3Result.stdio[3]); const outputPipeFd3Result = await execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', {value: 'pipe'}]}); expectType(outputPipeFd3Result.stdio[3]); -const input = true as boolean; -const booleanInputPipeFd3Result = await execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', {value: 'pipe', input}]}); +const isInput = true as boolean; +const booleanInputPipeFd3Result = await execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', {value: 'pipe', input: isInput}]}); expectType(booleanInputPipeFd3Result.stdio[3]); -const optionalInputPipe: {readonly value: 'pipe'; readonly input?: boolean} = {value: 'pipe', input}; +const optionalInputPipe: {readonly value: 'pipe'; readonly input?: boolean} = {value: 'pipe', input: isInput}; const optionalInputPipeFd3Result = await execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', optionalInputPipe]}); expectType(optionalInputPipeFd3Result.stdio[3]); diff --git a/test-d/stdio/option/generator-boolean-full.test-d.ts b/test-d/stdio/option/generator-boolean-full.test-d.ts index fb9e88ed86..e1e95b27f6 100644 --- a/test-d/stdio/option/generator-boolean-full.test-d.ts +++ b/test-d/stdio/option/generator-boolean-full.test-d.ts @@ -9,6 +9,7 @@ import { } from '../../../index.js'; const booleanGeneratorFull = { + // eslint-disable-next-line unicorn/consistent-boolean-name -- `line` matches the naming convention used by every other generator test file, mistyped on purpose to test the type error. * transform(line: boolean) { yield line; }, diff --git a/test-d/stdio/option/generator-boolean.test-d.ts b/test-d/stdio/option/generator-boolean.test-d.ts index 6eb050fb3b..3dfd9c79d4 100644 --- a/test-d/stdio/option/generator-boolean.test-d.ts +++ b/test-d/stdio/option/generator-boolean.test-d.ts @@ -8,6 +8,7 @@ import { type StdoutStderrSyncOption, } from '../../../index.js'; +// eslint-disable-next-line unicorn/consistent-boolean-name -- `line` matches the naming convention used by every other generator test file, mistyped on purpose to test the type error. const booleanGenerator = function * (line: boolean) { yield line; }; diff --git a/test-d/stdio/option/input-pipe.test-d.ts b/test-d/stdio/option/input-pipe.test-d.ts index 4949f0e586..fc792785f0 100644 --- a/test-d/stdio/option/input-pipe.test-d.ts +++ b/test-d/stdio/option/input-pipe.test-d.ts @@ -10,8 +10,8 @@ import { } from '../../../index.js'; const inputPipe = {value: 'pipe', input: true} as const; -const input = true as boolean; -const booleanInputPipe = {value: 'pipe', input} as const; +const isInput = true as boolean; +const booleanInputPipe = {value: 'pipe', input: isInput} as const; const transform = function * (line: string) { yield line; }; diff --git a/test-d/subprocess/stdio.test-d.ts b/test-d/subprocess/stdio.test-d.ts index e94e2747c2..5318eb630a 100644 --- a/test-d/subprocess/stdio.test-d.ts +++ b/test-d/subprocess/stdio.test-d.ts @@ -55,11 +55,11 @@ expectType(inputFdSubprocess.stdio[3]); const inputFileSubprocess = execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', {value: {file: './example'}, input: true}]}); expectType(inputFileSubprocess.stdio[3]); -const input = true as boolean; -const booleanInputPipeSubprocess = execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', {value: 'pipe', input}]}); +const isInput = true as boolean; +const booleanInputPipeSubprocess = execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', {value: 'pipe', input: isInput}]}); expectType(booleanInputPipeSubprocess.stdio[3]); -const optionalInputPipe: {readonly value: 'pipe'; readonly input?: boolean} = {value: 'pipe', input}; +const optionalInputPipe: {readonly value: 'pipe'; readonly input?: boolean} = {value: 'pipe', input: isInput}; const optionalInputPipeSubprocess = execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', optionalInputPipe]}); expectType(optionalInputPipeSubprocess.stdio[3]); diff --git a/test-d/verbose.test-d.ts b/test-d/verbose.test-d.ts index 6f846660d5..47ac6c322d 100644 --- a/test-d/verbose.test-d.ts +++ b/test-d/verbose.test-d.ts @@ -46,7 +46,9 @@ await execa('unicorns', {verbose: (verboseLine: string) => ''}); execaSync('unicorns', {verbose: (verboseLine: string) => ''}); await execa('unicorns', {verbose: (verboseLine: unknown) => ''}); execaSync('unicorns', {verbose: (verboseLine: unknown) => ''}); +// eslint-disable-next-line unicorn/consistent-boolean-name -- `verboseLine` matches the real callback parameter name, mistyped on purpose to test the type error. expectError(await execa('unicorns', {verbose: (verboseLine: boolean) => ''})); +// eslint-disable-next-line unicorn/consistent-boolean-name -- `verboseLine` matches the real callback parameter name, mistyped on purpose to test the type error. expectError(execaSync('unicorns', {verbose: (verboseLine: boolean) => ''})); expectError(await execa('unicorns', {verbose: (verboseLine: never) => ''})); expectError(execaSync('unicorns', {verbose: (verboseLine: never) => ''})); diff --git a/test/arguments/escape.js b/test/arguments/escape.js index 62614a300e..69323e5962 100644 --- a/test/arguments/escape.js +++ b/test/arguments/escape.js @@ -23,7 +23,7 @@ test(testResultCommand, ''); // eslint-disable-next-line max-params const testEscapedCommand = async (t, commandArguments, expectedUnix, expectedWindows, expectedUnixNoIcu = expectedUnix, expectedWindowsNoIcu = expectedWindows) => { - // eslint-disable-next-line no-use-extend-native/no-use-extend-native -- `RegExp.isMocked` is a static property added by `escape-no-icu.js`, not a native extension + // eslint-disable-next-line no-use-extend-native/no-use-extend-native, unicorn/no-nonstandard-builtin-properties -- `RegExp.isMocked` is a static property added by `escape-no-icu.js`, not a native extension const expected = RegExp.isMocked ? (isWindows ? expectedWindowsNoIcu : expectedUnixNoIcu) : (isWindows ? expectedWindows : expectedUnix); diff --git a/test/convert/readable.js b/test/convert/readable.js index 504c749d67..3f2117db52 100644 --- a/test/convert/readable.js +++ b/test/convert/readable.js @@ -326,10 +326,7 @@ test('.readable() has the right highWaterMark', async t => { test('.readable() can iterate over lines', async t => { const subprocess = execa('noop-fd.js', ['1', simpleFull]); - const lines = []; - for await (const line of subprocess.readable({binary: false, preserveNewlines: false})) { - lines.push(line); - } + const lines = await Array.fromAsync(subprocess.readable({binary: false, preserveNewlines: false})); const expectedLines = ['aaa', 'bbb', 'ccc']; t.deepEqual(lines, expectedLines); diff --git a/test/fixtures/ipc-get-send-get.js b/test/fixtures/ipc-get-send-get.js index b5b9b895b8..b67de1cc55 100755 --- a/test/fixtures/ipc-get-send-get.js +++ b/test/fixtures/ipc-get-send-get.js @@ -1,9 +1,9 @@ #!/usr/bin/env node import {argv} from 'node:process'; import {sendMessage, getOneMessage} from '../../index.js'; -import {alwaysPass} from '../helpers/ipc.js'; +import {isAlwaysTrue} from '../helpers/ipc.js'; -const filter = argv[2] === 'true' ? alwaysPass : undefined; +const filter = argv[2] === 'true' ? isAlwaysTrue : undefined; const message = await getOneMessage({filter}); await Promise.all([ diff --git a/test/fixtures/ipc-iterate-back-serial.js b/test/fixtures/ipc-iterate-back-serial.js index e9e267e586..44fe634a4b 100755 --- a/test/fixtures/ipc-iterate-back-serial.js +++ b/test/fixtures/ipc-iterate-back-serial.js @@ -2,9 +2,9 @@ import process from 'node:process'; import {sendMessage, getOneMessage} from '../../index.js'; import {PARALLEL_COUNT} from '../helpers/parallel.js'; -import {alwaysPass, getFirst} from '../helpers/ipc.js'; +import {isAlwaysTrue, getFirst} from '../helpers/ipc.js'; -const filter = process.argv[2] === 'true' ? alwaysPass : undefined; +const filter = process.argv[2] === 'true' ? isAlwaysTrue : undefined; await sendMessage(await getOneMessage({filter})); diff --git a/test/fixtures/ipc-iterate-back.js b/test/fixtures/ipc-iterate-back.js index c42e930f3a..120b3574fe 100755 --- a/test/fixtures/ipc-iterate-back.js +++ b/test/fixtures/ipc-iterate-back.js @@ -2,9 +2,9 @@ import process from 'node:process'; import {sendMessage, getOneMessage} from '../../index.js'; import {PARALLEL_COUNT} from '../helpers/parallel.js'; -import {alwaysPass, getFirst} from '../helpers/ipc.js'; +import {isAlwaysTrue, getFirst} from '../helpers/ipc.js'; -const filter = process.argv[2] === 'true' ? alwaysPass : undefined; +const filter = process.argv[2] === 'true' ? isAlwaysTrue : undefined; await sendMessage(await getOneMessage({filter})); diff --git a/test/fixtures/ipc-print-many.js b/test/fixtures/ipc-print-many.js index 5dc9db1bff..757502ab99 100755 --- a/test/fixtures/ipc-print-many.js +++ b/test/fixtures/ipc-print-many.js @@ -1,10 +1,10 @@ #!/usr/bin/env node import {argv} from 'node:process'; import {getOneMessage} from '../../index.js'; -import {alwaysPass} from '../helpers/ipc.js'; +import {isAlwaysTrue} from '../helpers/ipc.js'; const count = Number(argv[2]); -const filter = argv[3] === 'true' ? alwaysPass : undefined; +const filter = argv[3] === 'true' ? isAlwaysTrue : undefined; for (let index = 0; index < count; index += 1) { // eslint-disable-next-line no-await-in-loop diff --git a/test/fixtures/ipc-process-error.js b/test/fixtures/ipc-process-error.js index eba01f04db..fa1f99c812 100755 --- a/test/fixtures/ipc-process-error.js +++ b/test/fixtures/ipc-process-error.js @@ -2,10 +2,10 @@ import process from 'node:process'; import {getOneMessage, sendMessage} from '../../index.js'; import {foobarString} from '../helpers/input.js'; -import {alwaysPass} from '../helpers/ipc.js'; +import {isAlwaysTrue} from '../helpers/ipc.js'; process.on('error', () => {}); -const filter = process.argv[2] === 'true' ? alwaysPass : undefined; +const filter = process.argv[2] === 'true' ? isAlwaysTrue : undefined; const promise = getOneMessage({filter}); process.emit('error', new Error(foobarString)); await sendMessage(await promise); diff --git a/test/fixtures/ipc-send-pid.js b/test/fixtures/ipc-send-pid.js index bb98b2a4ed..6fdb75e8e8 100755 --- a/test/fixtures/ipc-send-pid.js +++ b/test/fixtures/ipc-send-pid.js @@ -2,12 +2,12 @@ import process from 'node:process'; import {execa, sendMessage} from '../../index.js'; -const cleanup = process.argv[2] === 'true'; -const detached = process.argv[3] === 'true'; +const isCleanup = process.argv[2] === 'true'; +const isDetached = process.argv[3] === 'true'; const file = process.argv[4] === 'no-killable' ? 'no-killable.js' : 'forever.js'; const options = { - cleanup, - detached, + cleanup: isCleanup, + detached: isDetached, ...(file === 'no-killable.js' && { ipc: true, killSignal: 'SIGKILL', diff --git a/test/helpers/ipc.js b/test/helpers/ipc.js index 0d25000919..6d0d9d9370 100644 --- a/test/helpers/ipc.js +++ b/test/helpers/ipc.js @@ -3,10 +3,7 @@ import {foobarString} from './input.js'; // @todo: replace with Array.fromAsync(subprocess.getEachMessage()) after dropping support for Node <22.0.0 export const iterateAllMessages = async subprocess => { - const messages = []; - for await (const message of subprocess.getEachMessage()) { - messages.push(message); - } + const messages = await Array.fromAsync(subprocess.getEachMessage()); return messages; }; @@ -25,7 +22,7 @@ export const getFirst = async () => { export const subprocessGetOne = (subprocess, options) => subprocess.getOneMessage(options); -export const alwaysPass = () => true; +export const isAlwaysTrue = () => true; // `process.send()` can fail due to I/O errors. // However, I/O errors are seldom and hard to trigger predictably. diff --git a/test/ipc/forward.js b/test/ipc/forward.js index 559b6942df..5280ce83fb 100644 --- a/test/ipc/forward.js +++ b/test/ipc/forward.js @@ -2,7 +2,7 @@ import test from 'ava'; import {execa} from '../../index.js'; import {setFixtureDirectory} from '../helpers/fixtures-directory.js'; import {foobarString, foobarArray} from '../helpers/input.js'; -import {iterateAllMessages, alwaysPass} from '../helpers/ipc.js'; +import {iterateAllMessages, isAlwaysTrue} from '../helpers/ipc.js'; setFixtureDirectory(); @@ -25,8 +25,8 @@ const testParentErrorOne = async (t, filter, buffer) => { test('"error" event does not interrupt subprocess.getOneMessage(), buffer false', testParentErrorOne, undefined, false); test('"error" event does not interrupt subprocess.getOneMessage(), buffer true', testParentErrorOne, undefined, true); -test('"error" event does not interrupt subprocess.getOneMessage(), buffer false, filter', testParentErrorOne, alwaysPass, false); -test('"error" event does not interrupt subprocess.getOneMessage(), buffer true, filter', testParentErrorOne, alwaysPass, true); +test('"error" event does not interrupt subprocess.getOneMessage(), buffer false, filter', testParentErrorOne, isAlwaysTrue, false); +test('"error" event does not interrupt subprocess.getOneMessage(), buffer true, filter', testParentErrorOne, isAlwaysTrue, true); const testSubprocessErrorOne = async (t, filter, buffer) => { const subprocess = execa('ipc-process-error.js', [`${filter}`], {ipc: true, buffer}); diff --git a/test/ipc/get-one.js b/test/ipc/get-one.js index 89225467c0..1ebb706bb8 100644 --- a/test/ipc/get-one.js +++ b/test/ipc/get-one.js @@ -2,7 +2,7 @@ import test from 'ava'; import {execa} from '../../index.js'; import {setFixtureDirectory} from '../helpers/fixtures-directory.js'; import {foobarString, foobarArray} from '../helpers/input.js'; -import {alwaysPass} from '../helpers/ipc.js'; +import {isAlwaysTrue} from '../helpers/ipc.js'; import {PARALLEL_COUNT} from '../helpers/parallel.js'; setFixtureDirectory(); @@ -73,8 +73,8 @@ const testTwice = async (t, buffer, filter) => { test('subprocess.getOneMessage() can be called twice at the same time, buffer false', testTwice, false, undefined); test('subprocess.getOneMessage() can be called twice at the same time, buffer true', testTwice, true, undefined); -test('subprocess.getOneMessage() can be called twice at the same time, buffer false, filter', testTwice, false, alwaysPass); -test('subprocess.getOneMessage() can be called twice at the same time, buffer true, filter', testTwice, true, alwaysPass); +test('subprocess.getOneMessage() can be called twice at the same time, buffer false, filter', testTwice, false, isAlwaysTrue); +test('subprocess.getOneMessage() can be called twice at the same time, buffer true, filter', testTwice, true, isAlwaysTrue); const testCleanupListeners = async (t, buffer, filter) => { const subprocess = execa('ipc-send.js', {ipc: true, buffer}); @@ -95,8 +95,8 @@ const testCleanupListeners = async (t, buffer, filter) => { test('Cleans up subprocess.getOneMessage() listeners, buffer false', testCleanupListeners, false, undefined); test('Cleans up subprocess.getOneMessage() listeners, buffer true', testCleanupListeners, true, undefined); -test('Cleans up subprocess.getOneMessage() listeners, buffer false, filter', testCleanupListeners, false, alwaysPass); -test('Cleans up subprocess.getOneMessage() listeners, buffer true, filter', testCleanupListeners, true, alwaysPass); +test('Cleans up subprocess.getOneMessage() listeners, buffer false, filter', testCleanupListeners, false, isAlwaysTrue); +test('Cleans up subprocess.getOneMessage() listeners, buffer true, filter', testCleanupListeners, true, isAlwaysTrue); const testParentDisconnect = async (t, buffer, filter) => { const subprocess = execa('ipc-get-send-get.js', [`${filter}`], {ipc: true, buffer}); @@ -127,5 +127,5 @@ const testSubprocessDisconnect = async (t, buffer, filter) => { test('Subprocess exit interrupts subprocess.getOneMessage(), buffer false', testSubprocessDisconnect, false, undefined); test('Subprocess exit interrupts subprocess.getOneMessage(), buffer true', testSubprocessDisconnect, true, undefined); -test('Subprocess exit interrupts subprocess.getOneMessage(), buffer false, filter', testSubprocessDisconnect, false, alwaysPass); -test('Subprocess exit interrupts subprocess.getOneMessage(), buffer true, filter', testSubprocessDisconnect, true, alwaysPass); +test('Subprocess exit interrupts subprocess.getOneMessage(), buffer false, filter', testSubprocessDisconnect, false, isAlwaysTrue); +test('Subprocess exit interrupts subprocess.getOneMessage(), buffer true, filter', testSubprocessDisconnect, true, isAlwaysTrue); diff --git a/test/ipc/incoming.js b/test/ipc/incoming.js index a36e658e28..9eef04464d 100644 --- a/test/ipc/incoming.js +++ b/test/ipc/incoming.js @@ -2,7 +2,7 @@ import test from 'ava'; import {execa} from '../../index.js'; import {setFixtureDirectory} from '../helpers/fixtures-directory.js'; import {foobarString} from '../helpers/input.js'; -import {alwaysPass} from '../helpers/ipc.js'; +import {isAlwaysTrue} from '../helpers/ipc.js'; import {PARALLEL_COUNT} from '../helpers/parallel.js'; setFixtureDirectory(); @@ -23,8 +23,8 @@ const testSeriesParent = async (t, buffer, filter) => { test('subprocess.getOneMessage() can be called multiple times in a row, buffer false', testSeriesParent, false, undefined); test('subprocess.getOneMessage() can be called multiple times in a row, buffer true', testSeriesParent, true, undefined); -test('subprocess.getOneMessage() can be called multiple times in a row, buffer false, filter', testSeriesParent, false, alwaysPass); -test('subprocess.getOneMessage() can be called multiple times in a row, buffer true, filter', testSeriesParent, true, alwaysPass); +test('subprocess.getOneMessage() can be called multiple times in a row, buffer false, filter', testSeriesParent, false, isAlwaysTrue); +test('subprocess.getOneMessage() can be called multiple times in a row, buffer true, filter', testSeriesParent, true, isAlwaysTrue); const testSeriesSubprocess = async (t, filter) => { const subprocess = execa('ipc-print-many.js', [`${PARALLEL_COUNT}`, `${filter}`], {ipc: true}); diff --git a/test/ipc/outgoing.js b/test/ipc/outgoing.js index 0610d59aa0..1c0e7c2e21 100644 --- a/test/ipc/outgoing.js +++ b/test/ipc/outgoing.js @@ -2,7 +2,7 @@ import test from 'ava'; import {execa} from '../../index.js'; import {setFixtureDirectory} from '../helpers/fixtures-directory.js'; import {foobarString} from '../helpers/input.js'; -import {alwaysPass, subprocessGetOne, subprocessGetFirst} from '../helpers/ipc.js'; +import {isAlwaysTrue, subprocessGetOne, subprocessGetFirst} from '../helpers/ipc.js'; import {PARALLEL_COUNT} from '../helpers/parallel.js'; setFixtureDirectory(); @@ -30,8 +30,8 @@ const testSendHoldParent = async (t, getMessage, buffer, filter) => { test('Multiple parallel subprocess.sendMessage() + subprocess.getOneMessage(), buffer false', testSendHoldParent, subprocessGetOne, false, undefined); test('Multiple parallel subprocess.sendMessage() + subprocess.getOneMessage(), buffer true', testSendHoldParent, subprocessGetOne, true, undefined); -test('Multiple parallel subprocess.sendMessage() + subprocess.getOneMessage(), buffer false, filter', testSendHoldParent, subprocessGetOne, false, alwaysPass); -test('Multiple parallel subprocess.sendMessage() + subprocess.getOneMessage(), buffer true, filter', testSendHoldParent, subprocessGetOne, true, alwaysPass); +test('Multiple parallel subprocess.sendMessage() + subprocess.getOneMessage(), buffer false, filter', testSendHoldParent, subprocessGetOne, false, isAlwaysTrue); +test('Multiple parallel subprocess.sendMessage() + subprocess.getOneMessage(), buffer true, filter', testSendHoldParent, subprocessGetOne, true, isAlwaysTrue); test('Multiple parallel subprocess.sendMessage() + subprocess.getEachMessage(), buffer false', testSendHoldParent, subprocessGetFirst, false, undefined); test('Multiple parallel subprocess.sendMessage() + subprocess.getEachMessage(), buffer true', testSendHoldParent, subprocessGetFirst, true, undefined); @@ -72,8 +72,8 @@ const testSendHoldParentSerial = async (t, getMessage, buffer, filter) => { test('Multiple serial subprocess.sendMessage() + subprocess.getOneMessage(), buffer false', testSendHoldParentSerial, subprocessGetOne, false, undefined); test('Multiple serial subprocess.sendMessage() + subprocess.getOneMessage(), buffer true', testSendHoldParentSerial, subprocessGetOne, true, undefined); -test('Multiple serial subprocess.sendMessage() + subprocess.getOneMessage(), buffer false, filter', testSendHoldParentSerial, subprocessGetOne, false, alwaysPass); -test('Multiple serial subprocess.sendMessage() + subprocess.getOneMessage(), buffer true, filter', testSendHoldParentSerial, subprocessGetOne, true, alwaysPass); +test('Multiple serial subprocess.sendMessage() + subprocess.getOneMessage(), buffer false, filter', testSendHoldParentSerial, subprocessGetOne, false, isAlwaysTrue); +test('Multiple serial subprocess.sendMessage() + subprocess.getOneMessage(), buffer true, filter', testSendHoldParentSerial, subprocessGetOne, true, isAlwaysTrue); test('Multiple serial subprocess.sendMessage() + subprocess.getEachMessage(), buffer false', testSendHoldParentSerial, subprocessGetFirst, false, undefined); test('Multiple serial subprocess.sendMessage() + subprocess.getEachMessage(), buffer true', testSendHoldParentSerial, subprocessGetFirst, true, undefined); diff --git a/test/methods/main-async.js b/test/methods/main-async.js index 318d2b768c..7ec7b0269d 100644 --- a/test/methods/main-async.js +++ b/test/methods/main-async.js @@ -63,6 +63,7 @@ test('execa() returns a promise with nodeChildProcess', async t => { t.is(subprocess.killed, undefined); t.is(subprocess.spawnargs, undefined); t.is(subprocess.spawnfile, undefined); + // eslint-disable-next-line unicorn/no-nonstandard-builtin-properties -- `Symbol.dispose` is a standard well-known symbol, not yet recognized by this rule. t.is(subprocess[Symbol.dispose], undefined); await subprocess; }); diff --git a/test/pipe/methods.js b/test/pipe/methods.js index 1242abdd3c..69d3ee9d21 100644 --- a/test/pipe/methods.js +++ b/test/pipe/methods.js @@ -36,28 +36,19 @@ const cleanupSubprocesses = async (...subprocesses) => { }; const getPipeMessages = async piped => { - const messages = []; - for await (const message of piped.getEachMessage()) { - messages.push(message); - } + const messages = await Array.fromAsync(piped.getEachMessage()); return messages; }; test('The .pipe() return value can be iterated', async t => { - const lines = []; - for await (const line of pipeSimple()) { - lines.push(line); - } + const lines = await Array.fromAsync(pipeSimple()); t.deepEqual(lines, noNewlinesChunks); }); test('The .pipe() return value has an .iterable() method', async t => { - const lines = []; - for await (const line of pipeSimple().iterable()) { - lines.push(line); - } + const lines = await Array.fromAsync(pipeSimple().iterable()); t.deepEqual(lines, noNewlinesChunks); }); @@ -82,10 +73,7 @@ test('The .pipe() return value .readable() can be called multiple times', async }); test('The .pipe() return value .readable() keeps conversion options', async t => { - const chunks = []; - for await (const chunk of pipeSimple().readable({binary: false, preserveNewlines: false})) { - chunks.push(chunk); - } + const chunks = await Array.fromAsync(pipeSimple().readable({binary: false, preserveNewlines: false})); t.deepEqual(chunks, noNewlinesChunks); t.is(chunks.join(''), noNewlinesFull); @@ -139,10 +127,7 @@ test('The .pipe() return value .readable() can read destination stderr', async t test('The .pipe() return value .iterable() can read destination stderr', async t => { const piped = pipeDistinctBoth(); - const lines = []; - for await (const line of piped.iterable({from: 'stderr'})) { - lines.push(line); - } + const lines = await Array.fromAsync(piped.iterable({from: 'stderr'})); t.deepEqual(lines, ['aaa', 'bbb', 'ccc:stderr']); await piped; @@ -231,9 +216,9 @@ test('The .pipe() return value .getEachMessage() cancels every pending reader', await Promise.all(readerPromises.map(async readerPromise => assertSettles(t, readerPromise))); }); -const assertCanceledPipeMessageReader = async (t, getReader, abortBeforePipe = false) => { +const assertCanceledPipeMessageReader = async (t, getReader, shouldAbortBeforePipe = false) => { const abortController = new AbortController(); - if (abortBeforePipe) { + if (shouldAbortBeforePipe) { abortController.abort(); } @@ -246,7 +231,7 @@ const assertCanceledPipeMessageReader = async (t, getReader, abortBeforePipe = f const piped = source.pipe(destination, {unpipeSignal: abortController.signal}); const readerPromise = t.throwsAsync(getReader(piped), {message: /Pipe canceled/}); - if (!abortBeforePipe) { + if (!shouldAbortBeforePipe) { abortController.abort(); } @@ -353,10 +338,7 @@ test('The .pipe() return value can exchange IPC messages', async t => { }); test('A chained .pipe() return value can be iterated', async t => { - const lines = []; - for await (const line of execa('noop-fd.js', ['1', simpleFull]).pipe('stdin.js').pipe('stdin.js')) { - lines.push(line); - } + const lines = await Array.fromAsync(execa('noop-fd.js', ['1', simpleFull]).pipe('stdin.js').pipe('stdin.js')); t.deepEqual(lines, noNewlinesChunks); }); @@ -393,9 +375,9 @@ test('The .pipe() return value .all waits for source failure', async t => { await t.throwsAsync(text(piped.all), {message: /Command failed with exit code 2/}); }); -const assertCanceledPipeReader = async (t, getReader, abortBeforePipe = false) => { +const assertCanceledPipeReader = async (t, getReader, shouldAbortBeforePipe = false) => { const abortController = new AbortController(); - if (abortBeforePipe) { + if (shouldAbortBeforePipe) { abortController.abort(); } @@ -408,7 +390,7 @@ const assertCanceledPipeReader = async (t, getReader, abortBeforePipe = false) = const piped = source.pipe(destination, {unpipeSignal: abortController.signal}); const readerPromise = t.throwsAsync(getReader(piped), {message: /Pipe canceled/}); - if (!abortBeforePipe) { + if (!shouldAbortBeforePipe) { abortController.abort(); } diff --git a/test/return/early-error.js b/test/return/early-error.js index ec8e089869..7b70d36094 100644 --- a/test/return/early-error.js +++ b/test/return/early-error.js @@ -127,10 +127,7 @@ test('child_process.spawn() early errors can use .getEachMessage()', testEarlyEr test('child_process.spawn() early errors can use .iterable()', async t => { const subprocess = getEarlyErrorSubprocess(); - const lines = []; - for await (const line of subprocess.iterable()) { - lines.push(line); - } + const lines = await Array.fromAsync(subprocess.iterable()); t.deepEqual(lines, []); await t.throwsAsync(subprocess); @@ -138,10 +135,7 @@ test('child_process.spawn() early errors can use .iterable()', async t => { test('child_process.spawn() early errors can use Symbol.asyncIterator', async t => { const subprocess = getEarlyErrorSubprocess(); - const lines = []; - for await (const line of subprocess) { - lines.push(line); - } + const lines = await Array.fromAsync(subprocess); t.deepEqual(lines, []); await t.throwsAsync(subprocess); diff --git a/test/stdio/node-stream-custom.js b/test/stdio/node-stream-custom.js index 901b43e859..5945a1a84d 100644 --- a/test/stdio/node-stream-custom.js +++ b/test/stdio/node-stream-custom.js @@ -63,17 +63,17 @@ test('stderr cannot be [Writable, "pipe"] without a file descriptor, sync', test test('stdio[*] cannot be [Writable, "pipe"] without a file descriptor, sync', testLazyFileWritableSync, 3); test('Waits for custom streams destroy on subprocess errors', async t => { - let waitedForDestroy = false; + let isWaitedForDestroy = false; const stream = new Writable({ destroy: callbackify(async error => { await setImmediate(); - waitedForDestroy = true; + isWaitedForDestroy = true; return error; }), }); const {timedOut} = await t.throwsAsync(execa('forever.js', {stdout: [stream, 'pipe'], timeout: 1})); t.true(timedOut); - t.true(waitedForDestroy); + t.true(isWaitedForDestroy); }); test('Handles custom streams destroy errors on subprocess success', async t => { diff --git a/test/stdio/web-stream.js b/test/stdio/web-stream.js index 567e0ca8e3..47c320c00a 100644 --- a/test/stdio/web-stream.js +++ b/test/stdio/web-stream.js @@ -44,15 +44,15 @@ test('stderr cannot be a WritableStream - sync', testWebStreamSync, WritableStre test('stdio[*] cannot be a WritableStream - sync', testWebStreamSync, WritableStream, 3, 'stdio[3]'); const testLongWritableStream = async (t, fdNumber) => { - let result = false; + let isResult = false; const writableStream = new WritableStream({ async close() { await setImmediate(); - result = true; + isResult = true; }, }); await execa('empty.js', getStdio(fdNumber, writableStream)); - t.true(result); + t.true(isResult); }; test('stdout waits for WritableStream completion', testLongWritableStream, 1); diff --git a/test/transform/encoding-multibyte.js b/test/transform/encoding-multibyte.js index 02be2cff05..be56724d88 100644 --- a/test/transform/encoding-multibyte.js +++ b/test/transform/encoding-multibyte.js @@ -22,7 +22,7 @@ const testMultibyteCharacters = async (t, objectMode, addNoopTransform, execaMet if (objectMode) { t.deepEqual(stdout, foobarArray); } else { - // eslint-disable-next-line n/prefer-global/buffer, unicorn/prefer-uint8array-base64 -- `Uint8Array#toBase64()` is not available on the minimum supported Node.js version + // eslint-disable-next-line n/prefer-global/buffer -- `Uint8Array#toBase64()` is not available on the minimum supported Node.js version t.is(stdout, Buffer.from(foobarArray.join('')).toString('base64')); } }; diff --git a/test/verbose/output-progressive.js b/test/verbose/output-progressive.js index 03a585c238..f516d556f1 100644 --- a/test/verbose/output-progressive.js +++ b/test/verbose/output-progressive.js @@ -27,8 +27,8 @@ test('Prints stdout one line at a time', async t => { test.serial('Prints stdout progressively, interleaved', async t => { const subprocess = nestedInstance('noop-repeat.js', ['1', `${foobarString}\n`], {parentFixture: 'nested-double.js', verbose: 'full'}); - let firstSubprocessPrinted = false; - let secondSubprocessPrinted = false; + let isFirstSubprocessPrinted = false; + let isSecondSubprocessPrinted = false; for await (const chunk of on(subprocess.stderr, 'data')) { const outputLine = getOutputLine(chunk.toString().trim()); if (outputLine === undefined) { @@ -37,13 +37,13 @@ test.serial('Prints stdout progressively, interleaved', async t => { if (outputLine.includes(foobarString)) { t.is(outputLine, `${testTimestamp} [0] ${foobarString}`); - firstSubprocessPrinted ||= true; + isFirstSubprocessPrinted ||= true; } else { t.is(outputLine, `${testTimestamp} [1] ${foobarString.toUpperCase()}`); - secondSubprocessPrinted ||= true; + isSecondSubprocessPrinted ||= true; } - if (firstSubprocessPrinted && secondSubprocessPrinted) { + if (isFirstSubprocessPrinted && isSecondSubprocessPrinted) { break; } }