|
1 | 1 | import path from 'node:path'; |
2 | 2 | import process from 'node:process'; |
3 | | -import {fileURLToPath} from 'node:url'; |
| 3 | +import {fileURLToPath, pathToFileURL} from 'node:url'; |
4 | 4 | import test from 'ava'; |
5 | 5 | import isRunning from 'is-running'; |
6 | 6 | import getNode from 'get-node'; |
| 7 | +import semver from 'semver'; |
7 | 8 | import {execa, execaSync} from '../index.js'; |
8 | 9 |
|
9 | 10 | process.env.PATH = fileURLToPath(new URL('./fixtures', import.meta.url)) + path.delimiter + process.env.PATH; |
@@ -198,6 +199,28 @@ test('do not extend environment with `extendEnv: false`', async t => { |
198 | 199 | t.deepEqual(stdout.split('\n'), ['undefined', 'bar']); |
199 | 200 | }); |
200 | 201 |
|
| 202 | +test('can use `options.cwd` as a string', async t => { |
| 203 | + const cwd = '/'; |
| 204 | + const {stdout} = await execa('node', ['-p', 'process.cwd()'], {cwd}); |
| 205 | + t.is(path.toNamespacedPath(stdout), path.toNamespacedPath(cwd)); |
| 206 | +}); |
| 207 | + |
| 208 | +if (semver.satisfies(process.version, '^14.18.0 || >=16.4.0')) { |
| 209 | + test('localDir option can be a URL', async t => { |
| 210 | + const command = process.platform === 'win32' ? 'echo %PATH%' : 'echo $PATH'; |
| 211 | + const {stdout} = await execa(command, {shell: true, preferLocal: true, localDir: pathToFileURL('/test')}); |
| 212 | + const envPaths = stdout.split(path.delimiter); |
| 213 | + t.true(envPaths.some(envPath => envPath.endsWith('.bin'))); |
| 214 | + }); |
| 215 | + |
| 216 | + test('can use `options.cwd` as a URL', async t => { |
| 217 | + const cwd = '/'; |
| 218 | + const cwdUrl = pathToFileURL(cwd); |
| 219 | + const {stdout} = await execa('node', ['-p', 'process.cwd()'], {cwd: cwdUrl}); |
| 220 | + t.is(path.toNamespacedPath(stdout), path.toNamespacedPath(cwd)); |
| 221 | + }); |
| 222 | +} |
| 223 | + |
201 | 224 | test('can use `options.shell: true`', async t => { |
202 | 225 | const {stdout} = await execa('node test/fixtures/noop.js foo', {shell: true}); |
203 | 226 | t.is(stdout, 'foo'); |
|
0 commit comments