diff options
author | XadillaX <i@2333.moe> | 2021-05-31 12:00:46 +0300 |
---|---|---|
committer | XadillaX <i@2333.moe> | 2021-06-04 09:33:59 +0300 |
commit | fc4b9c1d0752e750e21a4ee7703a17fa67bfd95b (patch) | |
tree | 292b110298457bf9407876bb087c521f97d36598 /test | |
parent | e7f941c1614ae0cc4c0022aefea130133afac612 (diff) |
child_process: allow `options.cwd` receive a URL
PR-URL: https://github.com/nodejs/node/pull/38862
Fixes: https://github.com/nodejs/node/issues/38861
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-child-process-cwd.js | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/test/parallel/test-child-process-cwd.js b/test/parallel/test-child-process-cwd.js index 232f1d0f3d5..869db83db39 100644 --- a/test/parallel/test-child-process-cwd.js +++ b/test/parallel/test-child-process-cwd.js @@ -20,12 +20,14 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; + const common = require('../common'); const tmpdir = require('../common/tmpdir'); tmpdir.refresh(); const assert = require('assert'); const { spawn } = require('child_process'); +const { pathToFileURL, URL } = require('url'); // Spawns 'pwd' with given options, then test // - whether the child pid is undefined or number, @@ -66,10 +68,27 @@ function testCwd(options, expectPidType, expectCode = 0, expectData) { })); } +{ + assert.throws(() => { + testCwd({ + cwd: new URL('http://example.com/'), + }, 'number', 0, tmpdir.path); + }, /The URL must be of scheme file/); + + if (process.platform !== 'win32') { + assert.throws(() => { + testCwd({ + cwd: new URL('file://host/dev/null'), + }, 'number', 0, tmpdir.path); + }, /File URL host must be "localhost" or empty on/); + } +} + // Assume these exist, and 'pwd' gives us the right directory back testCwd({ cwd: tmpdir.path }, 'number', 0, tmpdir.path); const shouldExistDir = common.isWindows ? process.env.windir : '/dev'; testCwd({ cwd: shouldExistDir }, 'number', 0, shouldExistDir); +testCwd({ cwd: pathToFileURL(tmpdir.path) }, 'number', 0, tmpdir.path); // Spawn() shouldn't try to chdir() to invalid arg, so this should just work testCwd({ cwd: '' }, 'number'); |