From 58cc52cc499827a9e807f0b1b5ef978195b5d7b0 Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Sun, 3 Sep 2023 23:48:12 +0800 Subject: [PATCH 1/3] test: add test for urlstrings usage in `node:fs` --- test/parallel/test-fs-whatwg-url.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/parallel/test-fs-whatwg-url.js b/test/parallel/test-fs-whatwg-url.js index fcd3b7e98a5dd4..354ddca0dc205f 100644 --- a/test/parallel/test-fs-whatwg-url.js +++ b/test/parallel/test-fs-whatwg-url.js @@ -4,6 +4,8 @@ const common = require('../common'); const fixtures = require('../common/fixtures'); const assert = require('assert'); const fs = require('fs'); +const tmpdir = require('../common/tmpdir'); +tmpdir.refresh(); const url = fixtures.fileURL('a.js'); @@ -80,3 +82,24 @@ if (common.isWindows) { } ); } + +// Test that strings are interpreted as paths and not as URL +// Please avoid testing fs.rmdir('file:') or using it as cleanup +if (!common.isWindows) { + const oldCwd = process.cwd(); + process.chdir(tmpdir.path); + + for (let slashCount = 0; slashCount < 9; slashCount++) { + const slashes = '/'.repeat(slashCount); + + const dirname = `file:${slashes}thisDirectoryWasMadeByFailingNodeJSTestSorry/subdir`; + fs.mkdirSync(dirname, { recursive: true }); + fs.writeFileSync(`${dirname}/file`, `test failed with ${slashCount} slashes`); + + const expected = fs.readFileSync(tmpdir.resolve(dirname, 'file')); + const actual = fs.readFileSync(`${dirname}/file`); + assert.deepStrictEqual(actual, expected); + } + + process.chdir(oldCwd); +} From b8e69d3f01d2e8588d85bd6b029f5b47610331f9 Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Tue, 5 Sep 2023 20:51:57 +0800 Subject: [PATCH 2/3] squash: skip in Workers, try to test in Windows --- test/parallel/test-fs-whatwg-url.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-fs-whatwg-url.js b/test/parallel/test-fs-whatwg-url.js index 354ddca0dc205f..d08763839b3a12 100644 --- a/test/parallel/test-fs-whatwg-url.js +++ b/test/parallel/test-fs-whatwg-url.js @@ -84,8 +84,9 @@ if (common.isWindows) { } // Test that strings are interpreted as paths and not as URL +// Can't use process.chdir in Workers // Please avoid testing fs.rmdir('file:') or using it as cleanup -if (!common.isWindows) { +if (common.isMainThread) { const oldCwd = process.cwd(); process.chdir(tmpdir.path); From 7ed6f64e26edfdbbf40c7a67da910a91d86e5351 Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Tue, 5 Sep 2023 21:51:03 +0800 Subject: [PATCH 3/3] squash: nvm --- test/parallel/test-fs-whatwg-url.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-fs-whatwg-url.js b/test/parallel/test-fs-whatwg-url.js index d08763839b3a12..7401ed7e76ecd1 100644 --- a/test/parallel/test-fs-whatwg-url.js +++ b/test/parallel/test-fs-whatwg-url.js @@ -86,7 +86,7 @@ if (common.isWindows) { // Test that strings are interpreted as paths and not as URL // Can't use process.chdir in Workers // Please avoid testing fs.rmdir('file:') or using it as cleanup -if (common.isMainThread) { +if (common.isMainThread && !common.isWindows) { const oldCwd = process.cwd(); process.chdir(tmpdir.path);