local.js
This file
Path
test/arguments/local.js
77 lines · 3.1 KiB · JavaScript
Last changed by
TweaksSindre Sorhusbefore adoption698a1b8
History of this fileTake it
The walk stopped after 200 commits: lines older than 9f65b86 point at it.
TweaksSindre Sorhusbefore adoption698a1b8
line 1why, one step back1import assert from 'node:assert/strict';Update test coverage for Node.js 26 (#1242)Sindre Sorhusbefore adoption68986b7
line 2why, one step back2import {existsSync} from 'node:fs';Upgrade dependencies (#1138)ehmickybefore adoptionabd9fd0
line 3why, one step back3import path from 'node:path';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 4–5why, one step back4import process from 'node:process';5import {pathToFileURL} from 'node:url';TweaksSindre Sorhusbefore adoption698a1b8
lines 6–7why, one step back6import test from 'node:test';7import {assertRejects} from '../helpers/assert.js';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 8–15why, one step back8import {execa, $} from '../../index.js';9import {setFixtureDirectory, PATH_KEY} from '../helpers/fixtures-directory.js';1011setFixtureDirectory();12process.env.FOO = 'foo';1314const isWindows = process.platform === 'win32';15const ENOENT_REGEXP = isWindows ? /failed with exit code 1/ : /spawn.* ENOENT/;TweaksSindre Sorhusbefore adoption698a1b8
lines 16–17why, one step back16// `c8` is used instead of a globally installed command since it is a devDependency, so `preferLocal` is the only way to find it17const C8_BINARY_NAMES = isWindows ? ['c8.cmd', 'c8.exe', 'c8.bat', 'c8.ps1', 'c8'] : ['c8'];100% test coverage (#1018)ehmickybefore adoption9f65b86
line 18why, one step back18Update test coverage for Node.js 26 (#1242)Sindre Sorhusbefore adoption68986b7
line 19why, one step back19const getPathWithoutCommand = commandNames => {Upgrade dependencies (#1138)ehmickybefore adoptionabd9fd0
lines 20–21why, one step back20 const newPath = process.env[PATH_KEY]21 .split(path.delimiter)Update test coverage for Node.js 26 (#1242)Sindre Sorhusbefore adoption68986b7
lines 22–23why, one step back22 .filter(pathDirectory => commandNames.every(commandName => !existsSync(path.join(pathDirectory, commandName))))23 .join(path.delimiter);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 24–26why, one step back24 return {[PATH_KEY]: newPath};25};26TweaksSindre Sorhusbefore adoption698a1b8
line 27why, one step back27const pathWithoutC8 = getPathWithoutCommand(C8_BINARY_NAMES);100% test coverage (#1018)ehmickybefore adoption9f65b86
line 28why, one step back28TweaksSindre Sorhusbefore adoption698a1b8
lines 29–30why, one step back29test('preferLocal: true', async () => {30 await assert.doesNotReject(execa('c8', ['--version'], {preferLocal: true, env: pathWithoutC8}));100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 31–32why, one step back31});32TweaksSindre Sorhusbefore adoption698a1b8
lines 33–34why, one step back33test('preferLocal: false', async () => {34 await assertRejects(execa('c8', ['--version'], {preferLocal: false, env: pathWithoutC8}), {message: ENOENT_REGEXP});100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 35–36why, one step back35});36TweaksSindre Sorhusbefore adoption698a1b8
lines 37–38why, one step back37test('preferLocal: undefined', async () => {38 await assertRejects(execa('c8', ['--version'], {env: pathWithoutC8}), {message: ENOENT_REGEXP});100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 39–40why, one step back39});40TweaksSindre Sorhusbefore adoption698a1b8
lines 41–42why, one step back41test('preferLocal: undefined with $', async () => {42 await assert.doesNotReject($('c8', ['--version'], {env: pathWithoutC8}));100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 43–44why, one step back43});44TweaksSindre Sorhusbefore adoption698a1b8
lines 45–46why, one step back45test('preferLocal: undefined with $.sync', () => {46 assert.doesNotThrow(() => $.sync('c8', ['--version'], {env: pathWithoutC8}));100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 47–48why, one step back47});48TweaksSindre Sorhusbefore adoption698a1b8
lines 49–50why, one step back49test('preferLocal: undefined with execa.pipe`...`', async () => {50 await assertRejects(() => execa('node', ['--version']).pipe({env: pathWithoutC8})`c8 --version`);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 51–52why, one step back51});52TweaksSindre Sorhusbefore adoption698a1b8
lines 53–54why, one step back53test('preferLocal: undefined with $.pipe`...`', async () => {54 await assert.doesNotThrow(() => $('node', ['--version']).pipe({env: pathWithoutC8})`c8 --version`);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 55–56why, one step back55});56TweaksSindre Sorhusbefore adoption698a1b8
lines 57–58why, one step back57test('preferLocal: undefined with execa.pipe()', async () => {58 await assertRejects(() => execa('node', ['--version']).pipe('c8', ['--version'], {env: pathWithoutC8}));100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 59–60why, one step back59});60TweaksSindre Sorhusbefore adoption698a1b8
lines 61–62why, one step back61test('preferLocal: undefined with $.pipe()', async () => {62 await assert.doesNotThrow(() => $('node', ['--version']).pipe('c8', ['--version'], {env: pathWithoutC8}));100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 63–64why, one step back63});64TweaksSindre Sorhusbefore adoption698a1b8
line 65why, one step back65test('localDir option', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 66–67why, one step back66 const command = isWindows ? 'echo %PATH%' : 'echo $PATH';67 const {stdout} = await execa(command, {shell: true, preferLocal: true, localDir: '/test'});Upgrade dependencies (#1138)ehmickybefore adoptionabd9fd0
line 68why, one step back68 const envPaths = stdout.split(path.delimiter);TweaksSindre Sorhusbefore adoption698a1b8
line 69why, one step back69 assert.ok(envPaths.some(envPath => envPath.endsWith('.bin')));100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 70–71why, one step back70});71TweaksSindre Sorhusbefore adoption698a1b8
line 72why, one step back72test('localDir option can be a URL', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 73–74why, one step back73 const command = isWindows ? 'echo %PATH%' : 'echo $PATH';74 const {stdout} = await execa(command, {shell: true, preferLocal: true, localDir: pathToFileURL('/test')});Upgrade dependencies (#1138)ehmickybefore adoptionabd9fd0
line 75why, one step back75 const envPaths = stdout.split(path.delimiter);TweaksSindre Sorhusbefore adoption698a1b8
line 76why, one step back76 assert.ok(envPaths.some(envPath => envPath.endsWith('.bin')));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 77why, one step back77});