Skip to content
Myr

local.js

This file

Path

test/arguments/local.js

77 lines · 3.1 KiB · JavaScript

Last changed by

TweaksSindre Sorhusbefore adoption698a1b8

History of this file

Take it

The walk stopped after 200 commits: lines older than 9f65b86 point at it.

TweaksSindre Sorhusbefore adoption698a1b8

line 1why, one step back
1import assert from 'node:assert/strict';

Update test coverage for Node.js 26 (#1242)Sindre Sorhusbefore adoption68986b7

line 2why, one step back
2import {existsSync} from 'node:fs';

Upgrade dependencies (#1138)ehmickybefore adoptionabd9fd0

line 3why, one step back
3import path from 'node:path';

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 4–5why, one step back
4import process from 'node:process';
5import {pathToFileURL} from 'node:url';

TweaksSindre Sorhusbefore adoption698a1b8

lines 6–7why, one step back
6import test from 'node:test';
7import {assertRejects} from '../helpers/assert.js';

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 8–15why, one step back
8import {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 back
16// `c8` is used instead of a globally installed command since it is a devDependency, so `preferLocal` is the only way to find it
17const C8_BINARY_NAMES = isWindows ? ['c8.cmd', 'c8.exe', 'c8.bat', 'c8.ps1', 'c8'] : ['c8'];

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 18why, one step back
18

Update test coverage for Node.js 26 (#1242)Sindre Sorhusbefore adoption68986b7

line 19why, one step back
19const getPathWithoutCommand = commandNames => {

Upgrade dependencies (#1138)ehmickybefore adoptionabd9fd0

lines 20–21why, one step back
20 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 back
22 .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 back
24 return {[PATH_KEY]: newPath};
25};26

TweaksSindre Sorhusbefore adoption698a1b8

line 27why, one step back
27const pathWithoutC8 = getPathWithoutCommand(C8_BINARY_NAMES);

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 28why, one step back
28

TweaksSindre Sorhusbefore adoption698a1b8

lines 29–30why, one step back
29test('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 back
31});
32

TweaksSindre Sorhusbefore adoption698a1b8

lines 33–34why, one step back
33test('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 back
35});
36

TweaksSindre Sorhusbefore adoption698a1b8

lines 37–38why, one step back
37test('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 back
39});
40

TweaksSindre Sorhusbefore adoption698a1b8

lines 41–42why, one step back
41test('preferLocal: undefined with $', async () => {
42 await assert.doesNotReject($('c8', ['--version'], {env: pathWithoutC8}));

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 43–44why, one step back
43});
44

TweaksSindre Sorhusbefore adoption698a1b8

lines 45–46why, one step back
45test('preferLocal: undefined with $.sync', () => {
46 assert.doesNotThrow(() => $.sync('c8', ['--version'], {env: pathWithoutC8}));

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 47–48why, one step back
47});
48

TweaksSindre Sorhusbefore adoption698a1b8

lines 49–50why, one step back
49test('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 back
51});
52

TweaksSindre Sorhusbefore adoption698a1b8

lines 53–54why, one step back
53test('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 back
55});
56

TweaksSindre Sorhusbefore adoption698a1b8

lines 57–58why, one step back
57test('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 back
59});
60

TweaksSindre Sorhusbefore adoption698a1b8

lines 61–62why, one step back
61test('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 back
63});
64

TweaksSindre Sorhusbefore adoption698a1b8

line 65why, one step back
65test('localDir option', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 66–67why, one step back
66 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 back
68 const envPaths = stdout.split(path.delimiter);

TweaksSindre Sorhusbefore adoption698a1b8

line 69why, one step back
69 assert.ok(envPaths.some(envPath => envPath.endsWith('.bin')));

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 70–71why, one step back
70});
71

TweaksSindre Sorhusbefore adoption698a1b8

line 72why, one step back
72test('localDir option can be a URL', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 73–74why, one step back
73 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 back
75 const envPaths = stdout.split(path.delimiter);

TweaksSindre Sorhusbefore adoption698a1b8

line 76why, one step back
76 assert.ok(envPaths.some(envPath => envPath.endsWith('.bin')));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 77why, one step back
77});