From 1df332c977a679027ca2541d2918427e5b8b92a8 Mon Sep 17 00:00:00 2001 From: ehmicky Date: Sun, 6 Feb 2022 15:50:53 +0100 Subject: [PATCH] Fix old Node.js version support --- package.json | 1 + test/test.js | 29 ++++++++++++++++------------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 3604397571..1871388793 100644 --- a/package.json +++ b/package.json @@ -58,6 +58,7 @@ "get-node": "^12.0.0", "is-running": "^2.1.0", "p-event": "^5.0.1", + "semver": "^7.3.5", "tempfile": "^4.0.0", "tsd": "^0.18.0", "xo": "^0.46.4" diff --git a/test/test.js b/test/test.js index 3924fab754..9d85888558 100644 --- a/test/test.js +++ b/test/test.js @@ -4,6 +4,7 @@ import {fileURLToPath, pathToFileURL} from 'node:url'; import test from 'ava'; import isRunning from 'is-running'; import getNode from 'get-node'; +import semver from 'semver' import {execa, execaSync} from '../index.js'; process.env.PATH = fileURLToPath(new URL('./fixtures', import.meta.url)) + path.delimiter + process.env.PATH; @@ -95,13 +96,6 @@ test('localDir option', async t => { t.true(envPaths.some(envPath => envPath.endsWith('.bin'))); }); -test('localDir option can be a URL', async t => { - const command = process.platform === 'win32' ? 'echo %PATH%' : 'echo $PATH'; - const {stdout} = await execa(command, {shell: true, preferLocal: true, localDir: pathToFileURL('/test')}); - const envPaths = stdout.split(path.delimiter); - t.true(envPaths.some(envPath => envPath.endsWith('.bin'))); -}); - test('execPath option', async t => { const {path: execPath} = await getNode('6.0.0'); const {stdout} = await execa('node', ['-p', 'process.env.Path || process.env.PATH'], {preferLocal: true, execPath}); @@ -211,12 +205,21 @@ test('can use `options.cwd` as a string', async t => { t.is(stdout, cwd); }); -test('can use `options.cwd` as a URL', async t => { - const cwd = '/'; - const cwdUrl = pathToFileURL(cwd); - const {stdout} = await execa('node', ['-p', 'process.cwd()'], {cwd: cwdUrl}); - t.is(stdout, cwd); -}); +if (semver.satisfies(process.version, '^14.18.0 || >=16.4.0')) { + test('localDir option can be a URL', async t => { + const command = process.platform === 'win32' ? 'echo %PATH%' : 'echo $PATH'; + const {stdout} = await execa(command, {shell: true, preferLocal: true, localDir: pathToFileURL('/test')}); + const envPaths = stdout.split(path.delimiter); + t.true(envPaths.some(envPath => envPath.endsWith('.bin'))); + }); + + test('can use `options.cwd` as a URL', async t => { + const cwd = '/'; + const cwdUrl = pathToFileURL(cwd); + const {stdout} = await execa('node', ['-p', 'process.cwd()'], {cwd: cwdUrl}); + t.is(stdout, cwd); + }); +} test('can use `options.shell: true`', async t => { const {stdout} = await execa('node test/fixtures/noop.js foo', {shell: true});