Skip to content

Commit

Permalink
test: add test for urlstrings usage in node:fs
Browse files Browse the repository at this point in the history
PR-URL: #49471
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
LiviaMedeiros authored and ruyadorno committed Sep 28, 2023
1 parent 2b11910 commit 34c1741
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/parallel/test-fs-whatwg-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -80,3 +82,25 @@ 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 && !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);
}

0 comments on commit 34c1741

Please sign in to comment.