Skip to content

Commit 34c1741

Browse files
LiviaMedeirosruyadorno
authored andcommitted
test: add test for urlstrings usage in node:fs
PR-URL: #49471 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 2b11910 commit 34c1741

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test/parallel/test-fs-whatwg-url.js

+24
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const common = require('../common');
44
const fixtures = require('../common/fixtures');
55
const assert = require('assert');
66
const fs = require('fs');
7+
const tmpdir = require('../common/tmpdir');
8+
tmpdir.refresh();
79

810
const url = fixtures.fileURL('a.js');
911

@@ -80,3 +82,25 @@ if (common.isWindows) {
8082
}
8183
);
8284
}
85+
86+
// Test that strings are interpreted as paths and not as URL
87+
// Can't use process.chdir in Workers
88+
// Please avoid testing fs.rmdir('file:') or using it as cleanup
89+
if (common.isMainThread && !common.isWindows) {
90+
const oldCwd = process.cwd();
91+
process.chdir(tmpdir.path);
92+
93+
for (let slashCount = 0; slashCount < 9; slashCount++) {
94+
const slashes = '/'.repeat(slashCount);
95+
96+
const dirname = `file:${slashes}thisDirectoryWasMadeByFailingNodeJSTestSorry/subdir`;
97+
fs.mkdirSync(dirname, { recursive: true });
98+
fs.writeFileSync(`${dirname}/file`, `test failed with ${slashCount} slashes`);
99+
100+
const expected = fs.readFileSync(tmpdir.resolve(dirname, 'file'));
101+
const actual = fs.readFileSync(`${dirname}/file`);
102+
assert.deepStrictEqual(actual, expected);
103+
}
104+
105+
process.chdir(oldCwd);
106+
}

0 commit comments

Comments
 (0)