Update test coverage for Node.js 26 (#1242)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Sindre Sorhus · committed by GitHub · parent 3ed0544 · Browse files · 11 files·+33 added−34 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
11 files+33 added−34 removed
- tests:+31 added−33 removed
- other:+2 added−1 removed
Provenance
- Commit
68986b7- Tree
db4c4c3- Author
Sindre Sorhus <sindresorhus@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
3ed0544
11 files changed+33 added−34 removed
modified:.github/workflows/main.yml+2 added-1 removed
8 unmodified lines9101112131415161713 unmodified lines313233343435363738395 unmodified lines8 unmodified lines strategy: fail-fast: false matrix: node-version: - 26 - 24 - 18 os: - ubuntu13 unmodified lines - uses: lycheeverse/lychee-action@v1 with: args: --cache --verbose --no-progress --include-fragments --exclude packagephobia --exclude /pull/ --exclude linkedin --exclude stackoverflow --exclude stackexchange --exclude github.com/nodejs/node --exclude file:///test --exclude invalid.com '*.md' 'docs/*.md' '.github/**/*.md' '*.json' '*.js' 'lib/**/*.js' 'test/**/*.js' '*.ts' 'test-d/**/*.ts' fail: true if: ${{ matrix.os == 'ubuntu' && matrix.node-version == 24 }} if: ${{ matrix.os == 'ubuntu' && matrix.node-version == 26 }} - run: npm run lint - run: npm run type - run: npm run unit - uses: codecov/codecov-action@v45 unmodified linesmodified:test/arguments/local.js+15 added-14 removed
123454 unmodified lines101112131415141617181719202122232124252324262627282930303132333434353637383839404142424344454646474849505051525354545556575858596061626311 unmodified linesimport {existsSync} from 'node:fs';import path from 'node:path';import process from 'node:process';import {pathToFileURL} from 'node:url';import test from 'ava';4 unmodified linesprocess.env.FOO = 'foo';
const isWindows = process.platform === 'win32';const ENOENT_REGEXP = isWindows ? /failed with exit code 1/ : /spawn.* ENOENT/;const AVA_BINARY_NAMES = isWindows ? ['ava.cmd', 'ava.exe', 'ava.bat', 'ava.ps1', 'ava'] : ['ava'];
const getPathWithoutLocalDirectory = () => {const getPathWithoutCommand = commandNames => { const newPath = process.env[PATH_KEY] .split(path.delimiter) .filter(pathDirectory => !BIN_DIR_REGEXP.test(pathDirectory)).join(path.delimiter); .filter(pathDirectory => commandNames.every(commandName => !existsSync(path.join(pathDirectory, commandName)))) .join(path.delimiter); return {[PATH_KEY]: newPath};};
const BIN_DIR_REGEXP = /node_modules[\\/]\.bin/;const pathWithoutAva = getPathWithoutCommand(AVA_BINARY_NAMES);
const pathWitoutLocalDirectory = getPathWithoutLocalDirectory();
test('preferLocal: true', async t => { await t.notThrowsAsync(execa('ava', ['--version'], {preferLocal: true, env: pathWitoutLocalDirectory})); await t.notThrowsAsync(execa('ava', ['--version'], {preferLocal: true, env: pathWithoutAva}));});
test('preferLocal: false', async t => { await t.throwsAsync(execa('ava', ['--version'], {preferLocal: false, env: pathWitoutLocalDirectory}), {message: ENOENT_REGEXP}); await t.throwsAsync(execa('ava', ['--version'], {preferLocal: false, env: pathWithoutAva}), {message: ENOENT_REGEXP});});
test('preferLocal: undefined', async t => { await t.throwsAsync(execa('ava', ['--version'], {env: pathWitoutLocalDirectory}), {message: ENOENT_REGEXP}); await t.throwsAsync(execa('ava', ['--version'], {env: pathWithoutAva}), {message: ENOENT_REGEXP});});
test('preferLocal: undefined with $', async t => { await t.notThrowsAsync($('ava', ['--version'], {env: pathWitoutLocalDirectory})); await t.notThrowsAsync($('ava', ['--version'], {env: pathWithoutAva}));});
test('preferLocal: undefined with $.sync', t => { t.notThrows(() => $.sync('ava', ['--version'], {env: pathWitoutLocalDirectory})); t.notThrows(() => $.sync('ava', ['--version'], {env: pathWithoutAva}));});
test('preferLocal: undefined with execa.pipe`...`', async t => { await t.throwsAsync(() => execa('node', ['--version']).pipe({env: pathWitoutLocalDirectory})`ava --version`); await t.throwsAsync(() => execa('node', ['--version']).pipe({env: pathWithoutAva})`ava --version`);});
test('preferLocal: undefined with $.pipe`...`', async t => { await t.notThrows(() => $('node', ['--version']).pipe({env: pathWitoutLocalDirectory})`ava --version`); await t.notThrows(() => $('node', ['--version']).pipe({env: pathWithoutAva})`ava --version`);});
test('preferLocal: undefined with execa.pipe()', async t => { await t.throwsAsync(() => execa('node', ['--version']).pipe('ava', ['--version'], {env: pathWitoutLocalDirectory})); await t.throwsAsync(() => execa('node', ['--version']).pipe('ava', ['--version'], {env: pathWithoutAva}));});
test('preferLocal: undefined with $.pipe()', async t => { await t.notThrows(() => $('node', ['--version']).pipe('ava', ['--version'], {env: pathWitoutLocalDirectory})); await t.notThrows(() => $('node', ['--version']).pipe('ava', ['--version'], {env: pathWithoutAva}));});
test('localDir option', async t => { const command = isWindows ? 'echo %PATH%' : 'echo $PATH';11 unmodified linesmodified:test/helpers/early-error.js+2 added-2 removed
12345567899import {execa, execaSync} from '../../index.js';
export const earlyErrorOptions = {detached: 'true'};export const getEarlyErrorSubprocess = options => execa('empty.js', {...earlyErrorOptions, ...options});export const earlyErrorOptionsSync = {maxBuffer: false};export const earlyErrorOptionsSync = {windowsHide: 'true'};export const getEarlyErrorSubprocessSync = options => execaSync('empty.js', {...earlyErrorOptionsSync, ...options});
export const expectedEarlyError = {code: 'ERR_INVALID_ARG_TYPE'};export const expectedEarlyErrorSync = {code: 'ERR_OUT_OF_RANGE'};export const expectedEarlyErrorSync = {code: 'ERR_INVALID_ARG_TYPE'};modified:test/helpers/input.js+1 added
2 unmodified lines3456789101111 unmodified lines2 unmodified lines
const textEncoder = new TextEncoder();
export const foobarString = 'foobar';export const foobarRed = `\u001B[31m${foobarString}\u001B[39m`;export const foobarArray = ['foo', 'bar'];export const foobarUint8Array = textEncoder.encode(foobarString);export const foobarArrayBuffer = foobarUint8Array.buffer;export const foobarUint16Array = new Uint16Array(foobarArrayBuffer);11 unmodified linesmodified:test/return/message.js+2 added-2 removed
89 unmodified lines90 test('error.message newlines are consistent - no newline', testErrorMessageConsistent, 'stdout');91 test('error.message newlines are consistent - newline', testErrorMessageConsistent, 'stdout\n');92 93 test('Original error.message is kept', async t => {94- const {originalMessage} = await t.throwsAsync(execa('noop.js', {uid: true}));95- t.is(originalMessage, 'The "options.uid" property must be int32. Received type boolean (true)');94+ const {originalMessage} = await t.throwsAsync(execa('noop.js', {windowsHide: 'true'}));95+ t.is(originalMessage, 'The "options.windowsHide" property must be of type boolean. Received type string (\'true\')');96 });97 98 const testIpcOutput = async (t, doubles, ipcInput, returnedMessage) => {99 const fixtureName = doubles ? 'ipc-echo-twice-fail.js' : 'ipc-echo-fail.js';19 unmodified linesmodified:test/verbose/error.js+2 added-3 removed
1 import test from 'ava';2-import {red} from 'yoctocolors';2 import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4-import {foobarString} from '../helpers/input.js';3+import {foobarString, foobarRed} from '../helpers/input.js';4 import {nestedSubprocess} from '../helpers/nested.js';5 import {6 QUOTE,7 runErrorSubprocess,140 unmodified lines148 ]);149 });150 151 test('Escapes and strips color sequences from error', async t => {153- const {stderr} = await t.throwsAsync(nestedSubprocess('noop-forever.js', [red(foobarString)], {parentFixture: 'nested-fail.js', verbose: 'short'}, {env: {FORCE_COLOR: '1'}}));152+ const {stderr} = await t.throwsAsync(nestedSubprocess('noop-forever.js', [foobarRed], {parentFixture: 'nested-fail.js', verbose: 'short'}));153 t.deepEqual(getErrorLines(stderr), [154 `${testTimestamp} [0] × Command was killed with SIGTERM (Termination): noop-forever.js ${QUOTE}\\u001b[31m${foobarString}\\u001b[39m${QUOTE}`,155 `${testTimestamp} [0] × ${foobarString}`,156 ]);9 unmodified linesmodified:test/verbose/info.js+2 added-2 removed
83 unmodified lines84 test('Prints early spawn errors, sync', async t => {85 const {stderr} = await nestedSubprocess('empty.js', {...earlyErrorOptionsSync, verbose: 'full', isSync: true});86 t.deepEqual(getNormalizedLines(stderr), [87 `${testTimestamp} [0] $ empty.js`,88- `${testTimestamp} [0] × Command failed with ERR_OUT_OF_RANGE: empty.js`,89- `${testTimestamp} [0] × The value of "options.maxBuffer" is out of range. It must be a positive number. Received false`,88+ `${testTimestamp} [0] × Command failed with ERR_INVALID_ARG_TYPE: empty.js`,89+ `${testTimestamp} [0] × The "options.windowsHide" property must be of type boolean. Received type string ('true')`,90 `${testTimestamp} [0] × (done in 0ms)`,91 ]);92 });modified:test/verbose/ipc.js+2 added-3 removed
1 import {on} from 'node:events';2 import {inspect} from 'node:util';3 import test from 'ava';4-import {red} from 'yoctocolors';4 import {setFixtureDirectory} from '../helpers/fixtures-directory.js';6-import {foobarString, foobarObject} from '../helpers/input.js';5+import {foobarString, foobarRed, foobarObject} from '../helpers/input.js';6 import {nestedSubprocess, nestedInstance} from '../helpers/nested.js';7 import {8 getIpcLine,9 getIpcLines,72 unmodified lines82 t.is(getIpcLine(stderr), `${testTimestamp} [0] * ã`);83 });84 85 test('Strips color sequences from IPC', async t => {87- const {stderr} = await nestedSubprocess('ipc-send.js', [red(foobarString)], {ipc: true, verbose: 'full'}, {env: {FORCE_COLOR: '1'}});86+ const {stderr} = await nestedSubprocess('ipc-send.js', [foobarRed], {ipc: true, verbose: 'full'});87 t.is(getIpcLine(stderr), `${testTimestamp} [0] * ${foobarString}`);88 });89 90 test('Escapes control characters from IPC', async t => {17 unmodified linesmodified:test/verbose/log.js+1 added-1 removed
19 unmodified lines20 test('Logs on stderr not stdout, verbose "short", sync', testNoStdout, 'short', true);21 test('Logs on stderr not stdout, verbose "full", sync', testNoStdout, 'full', true);22 23 const testColor = async (t, expectedResult, forceColor) => {24- const {stderr} = await nestedSubprocess('noop.js', [foobarString], {verbose: 'short'}, {env: {FORCE_COLOR: forceColor}});24+ const {stderr} = await nestedSubprocess('noop.js', [foobarString], {verbose: 'short'}, {env: {FORCE_COLOR: forceColor, NO_COLOR: undefined}});25 t.is(stderr !== stripVTControlCharacters(stderr), expectedResult);26 };27 28 test('Prints with colors if supported', testColor, true, '1');13 unmodified linesmodified:test/verbose/output-enable.js+2 added-3 removed
1 import test from 'ava';2-import {red} from 'yoctocolors';2 import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4-import {foobarString, foobarUtf16Uint8Array} from '../helpers/input.js';3+import {foobarString, foobarRed, foobarUtf16Uint8Array} from '../helpers/input.js';4 import {fullStdio} from '../helpers/stdio.js';5 import {nestedSubprocess} from '../helpers/nested.js';6 import {7 runErrorSubprocess,96 unmodified lines104 t.is(getOutputLine(stderr), `${testTimestamp} [0] ã`);105 });106 107 test('Strips color sequences from stdout', async t => {109- const {stderr} = await nestedSubprocess('noop.js', [red(foobarString)], {verbose: 'full'}, {env: {FORCE_COLOR: '1'}});108+ const {stderr} = await nestedSubprocess('noop.js', [foobarRed], {verbose: 'full'});109 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);110 });111 112 test('Escapes control characters from stdout', async t => {32 unmodified linesmodified:test/verbose/start.js+2 added-3 removed
1 import test from 'ava';2-import {red} from 'yoctocolors';2 import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4-import {foobarString} from '../helpers/input.js';3+import {foobarString, foobarRed} from '../helpers/input.js';4 import {nestedSubprocess} from '../helpers/nested.js';5 import {6 QUOTE,7 runErrorSubprocess,142 unmodified lines150 t.is(getCommandLine(stderr), `${testTimestamp} [0] $ noop.js ${QUOTE}ã${QUOTE}`);151 });152 153 test('Escapes color sequences from command', async t => {155- const {stderr} = await nestedSubprocess('noop.js', [red(foobarString)], {verbose: 'short'}, {env: {FORCE_COLOR: '1'}});154+ const {stderr} = await nestedSubprocess('noop.js', [foobarRed], {verbose: 'short'});155 t.true(getCommandLine(stderr).includes(`${QUOTE}\\u001b[31m${foobarString}\\u001b[39m${QUOTE}`));156 });157 158 test('Escapes control characters from command', async t => {3 unmodified lines