Skip to content

Commit b172d81

Browse files
committed
squash: change to fileURL()
1 parent 6339b2a commit b172d81

4 files changed

Lines changed: 17 additions & 13 deletions

File tree

test/common/tmpdir.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ const testRoot = process.env.NODE_TEST_DIR ?
2929
const tmpdirName = '.tmp.' +
3030
(process.env.TEST_SERIAL_ID || process.env.TEST_THREAD_ID || '0');
3131
const tmpPath = path.join(testRoot, tmpdirName);
32-
const tmpUrl = pathToFileURL(tmpPath + path.sep);
3332

3433
let firstRefresh = true;
3534
function refresh(useSpawn = false) {
@@ -76,9 +75,16 @@ function hasEnoughSpace(size) {
7675
return bavail >= Math.ceil(size / bsize);
7776
}
7877

78+
function fileURL(...paths) {
79+
// When called without arguments, add explicit trailing slash
80+
const fullPath = path.resolve(tmpPath + path.sep, ...paths);
81+
82+
return pathToFileURL(fullPath);
83+
}
84+
7985
module.exports = {
86+
fileURL,
87+
hasEnoughSpace,
8088
path: tmpPath,
81-
url: tmpUrl.href,
8289
refresh,
83-
hasEnoughSpace,
8490
};

test/parallel/test-child-process-cwd.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function testCwd(options, expectPidType, expectCode = 0, expectData) {
8787
testCwd({ cwd: tmpdir.path }, 'number', 0, tmpdir.path);
8888
const shouldExistDir = common.isWindows ? process.env.windir : '/dev';
8989
testCwd({ cwd: shouldExistDir }, 'number', 0, shouldExistDir);
90-
testCwd({ cwd: new URL(tmpdir.url) }, 'number', 0, tmpdir.path);
90+
testCwd({ cwd: tmpdir.fileURL() }, 'number', 0, tmpdir.path);
9191

9292
// Spawn() shouldn't try to chdir() to invalid arg, so this should just work
9393
testCwd({ cwd: '' }, 'number');

test/parallel/test-fs-mkdtemp.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,24 @@ function handler(err, folder) {
4040

4141
// Test with URL object
4242
{
43-
const urljoin = (base, path) => new URL(path, base);
44-
45-
const tmpFolder = fs.mkdtempSync(urljoin(tmpdir.url, 'foo.'));
43+
const tmpFolder = fs.mkdtempSync(tmpdir.fileURL('foo.'));
4644

4745
assert.strictEqual(path.basename(tmpFolder).length, 'foo.XXXXXX'.length);
4846
assert(fs.existsSync(tmpFolder));
4947

50-
const utf8 = fs.mkdtempSync(urljoin(tmpdir.url, '\u0222abc.'));
48+
const utf8 = fs.mkdtempSync(tmpdir.fileURL('\u0222abc.'));
5149
assert.strictEqual(Buffer.byteLength(path.basename(utf8)),
5250
Buffer.byteLength('\u0222abc.XXXXXX'));
5351
assert(fs.existsSync(utf8));
5452

55-
fs.mkdtemp(urljoin(tmpdir.url, 'bar.'), common.mustCall(handler));
53+
fs.mkdtemp(tmpdir.fileURL('bar.'), common.mustCall(handler));
5654

5755
// Same test as above, but making sure that passing an options object doesn't
5856
// affect the way the callback function is handled.
59-
fs.mkdtemp(urljoin(tmpdir.url, 'bar.'), {}, common.mustCall(handler));
57+
fs.mkdtemp(tmpdir.fileURL('bar.'), {}, common.mustCall(handler));
6058

6159
// Warning fires only once
62-
fs.mkdtemp(urljoin(tmpdir.url, 'bar.X'), common.mustCall(handler));
60+
fs.mkdtemp(tmpdir.fileURL('bar.X'), common.mustCall(handler));
6361
}
6462

6563
// Test with Buffer

test/parallel/test-fs-rm.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ if (isGitPresent) {
270270
}
271271

272272
// Should accept URL
273-
const fileURL = new URL('rm-file.txt', tmpdir.url);
273+
const fileURL = tmpdir.fileURL('rm-file.txt');
274274
fs.writeFileSync(fileURL, '');
275275

276276
try {
@@ -376,7 +376,7 @@ if (isGitPresent) {
376376
}
377377

378378
// Should accept URL
379-
const fileURL = new URL('rm-promises-file.txt', tmpdir.url);
379+
const fileURL = tmpdir.fileURL('rm-promises-file.txt');
380380
fs.writeFileSync(fileURL, '');
381381

382382
try {

0 commit comments

Comments
 (0)