From 0ef46e36506a87abd274ca7d21dfe09120d9f44a Mon Sep 17 00:00:00 2001 From: RedYetiDev <38299977+RedYetiDev@users.noreply.github.com> Date: Sun, 22 Sep 2024 19:37:51 -0400 Subject: [PATCH 1/5] fs: pass correct path to `DirentFromStats` during `glob` --- lib/internal/fs/glob.js | 6 +++--- test/parallel/test-fs-glob.mjs | 20 +++++++++++++------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/internal/fs/glob.js b/lib/internal/fs/glob.js index d4b73a0ffca46d..0f4939f7e1ba0d 100644 --- a/lib/internal/fs/glob.js +++ b/lib/internal/fs/glob.js @@ -16,7 +16,7 @@ const { const { lstatSync, readdirSync } = require('fs'); const { lstat, readdir } = require('fs/promises'); -const { join, resolve, basename, isAbsolute } = require('path'); +const { join, resolve, basename, isAbsolute, dirname } = require('path'); const { kEmptyObject, @@ -48,7 +48,7 @@ async function getDirent(path) { } catch { return null; } - return new DirentFromStats(basename(path), stat, path); + return new DirentFromStats(basename(path), stat, dirname(path)); } /** @@ -60,7 +60,7 @@ function getDirentSync(path) { if (stat === undefined) { return null; } - return new DirentFromStats(basename(path), stat, path); + return new DirentFromStats(basename(path), stat, dirname(path)); } class Cache { diff --git a/test/parallel/test-fs-glob.mjs b/test/parallel/test-fs-glob.mjs index 4038c0e165eb69..818f192431196d 100644 --- a/test/parallel/test-fs-glob.mjs +++ b/test/parallel/test-fs-glob.mjs @@ -1,6 +1,6 @@ import * as common from '../common/index.mjs'; import tmpdir from '../common/tmpdir.js'; -import { resolve, dirname, sep, basename } from 'node:path'; +import { resolve, dirname, sep, basename, relative, join, isAbsolute } from 'node:path'; import { mkdir, writeFile, symlink, glob as asyncGlob } from 'node:fs/promises'; import { glob, globSync, Dirent } from 'node:fs'; import { test, describe } from 'node:test'; @@ -348,8 +348,10 @@ describe('glob - withFileTypes', function() { exclude: (dirent) => assert.ok(dirent instanceof Dirent), }); assertDirents(actual); - const normalized = expected.filter(Boolean).map((item) => basename(item)).sort(); - assert.deepStrictEqual(actual.map((dirent) => dirent.name).sort(), normalized.sort()); + assert.deepStrictEqual( + actual.map((dirent) => relative(fixtureDir, join(dirent.parentPath, dirent.name))).sort(), + expected.map(path => isAbsolute(path) ? relative(fixtureDir, path) : path).sort() + ); }); } }); @@ -363,8 +365,10 @@ describe('globSync - withFileTypes', function() { exclude: (dirent) => assert.ok(dirent instanceof Dirent), }); assertDirents(actual); - const normalized = expected.filter(Boolean).map((item) => basename(item)).sort(); - assert.deepStrictEqual(actual.map((dirent) => dirent.name).sort(), normalized.sort()); + assert.deepStrictEqual( + actual.map((dirent) => relative(fixtureDir, join(dirent.parentPath, dirent.name))).sort(), + expected.map(path => isAbsolute(path) ? relative(fixtureDir, path) : path).sort() + ); }); } }); @@ -379,8 +383,10 @@ describe('fsPromises glob - withFileTypes', function() { exclude: (dirent) => assert.ok(dirent instanceof Dirent), })) actual.push(item); assertDirents(actual); - const normalized = expected.filter(Boolean).map((item) => basename(item)).sort(); - assert.deepStrictEqual(actual.map((dirent) => dirent.name).sort(), normalized.sort()); + assert.deepStrictEqual( + actual.map((dirent) => relative(fixtureDir, join(dirent.parentPath, dirent.name))).sort(), + expected.map(path => isAbsolute(path) ? relative(fixtureDir, path) : path).sort() + ); }); } }); From c09392db4cdf6dd26190342c5e1e01a6c05ef244 Mon Sep 17 00:00:00 2001 From: RedYetiDev <38299977+RedYetiDev@users.noreply.github.com> Date: Sun, 22 Sep 2024 19:43:46 -0400 Subject: [PATCH 2/5] fixup! fs: pass correct path to `DirentFromStats` during `glob` --- test/parallel/test-fs-glob.mjs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/parallel/test-fs-glob.mjs b/test/parallel/test-fs-glob.mjs index 818f192431196d..77e6d9bae9c781 100644 --- a/test/parallel/test-fs-glob.mjs +++ b/test/parallel/test-fs-glob.mjs @@ -1,6 +1,6 @@ import * as common from '../common/index.mjs'; import tmpdir from '../common/tmpdir.js'; -import { resolve, dirname, sep, basename, relative, join, isAbsolute } from 'node:path'; +import { resolve, dirname, sep, relative, join, isAbsolute } from 'node:path'; import { mkdir, writeFile, symlink, glob as asyncGlob } from 'node:fs/promises'; import { glob, globSync, Dirent } from 'node:fs'; import { test, describe } from 'node:test'; @@ -350,7 +350,7 @@ describe('glob - withFileTypes', function() { assertDirents(actual); assert.deepStrictEqual( actual.map((dirent) => relative(fixtureDir, join(dirent.parentPath, dirent.name))).sort(), - expected.map(path => isAbsolute(path) ? relative(fixtureDir, path) : path).sort() + expected.map((path) => (isAbsolute(path) ? relative(fixtureDir, path) : path)).sort() ); }); } @@ -367,7 +367,7 @@ describe('globSync - withFileTypes', function() { assertDirents(actual); assert.deepStrictEqual( actual.map((dirent) => relative(fixtureDir, join(dirent.parentPath, dirent.name))).sort(), - expected.map(path => isAbsolute(path) ? relative(fixtureDir, path) : path).sort() + expected.map((path) => (isAbsolute(path) ? relative(fixtureDir, path) : path)).sort() ); }); } @@ -385,7 +385,7 @@ describe('fsPromises glob - withFileTypes', function() { assertDirents(actual); assert.deepStrictEqual( actual.map((dirent) => relative(fixtureDir, join(dirent.parentPath, dirent.name))).sort(), - expected.map(path => isAbsolute(path) ? relative(fixtureDir, path) : path).sort() + expected.map((path) => (isAbsolute(path) ? relative(fixtureDir, path) : path)).sort() ); }); } From 2d9e9ccf395d2be07daa28473b425c38b5d8c2d0 Mon Sep 17 00:00:00 2001 From: RedYetiDev <38299977+RedYetiDev@users.noreply.github.com> Date: Wed, 25 Sep 2024 14:48:04 -0400 Subject: [PATCH 3/5] fixup! fixup! fs: pass correct path to `DirentFromStats` during `glob` --- test/parallel/test-fs-glob.mjs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/test/parallel/test-fs-glob.mjs b/test/parallel/test-fs-glob.mjs index 77e6d9bae9c781..200b73b2304171 100644 --- a/test/parallel/test-fs-glob.mjs +++ b/test/parallel/test-fs-glob.mjs @@ -338,6 +338,9 @@ describe('fsPromises glob', function() { } }); +const normalizeDirent = (dirent) => relative(fixtureDir, join(dirent.parentPath, dirent.name)); +const normalizePath = (path) => (isAbsolute(path) ? relative(fixtureDir, path) : join(path)); + describe('glob - withFileTypes', function() { const promisified = promisify(glob); for (const [pattern, expected] of Object.entries(patterns)) { @@ -348,10 +351,7 @@ describe('glob - withFileTypes', function() { exclude: (dirent) => assert.ok(dirent instanceof Dirent), }); assertDirents(actual); - assert.deepStrictEqual( - actual.map((dirent) => relative(fixtureDir, join(dirent.parentPath, dirent.name))).sort(), - expected.map((path) => (isAbsolute(path) ? relative(fixtureDir, path) : path)).sort() - ); + assert.deepStrictEqual(actual.map(normalizeDirent).sort(), expected.map(normalizePath).sort()); }); } }); @@ -365,10 +365,7 @@ describe('globSync - withFileTypes', function() { exclude: (dirent) => assert.ok(dirent instanceof Dirent), }); assertDirents(actual); - assert.deepStrictEqual( - actual.map((dirent) => relative(fixtureDir, join(dirent.parentPath, dirent.name))).sort(), - expected.map((path) => (isAbsolute(path) ? relative(fixtureDir, path) : path)).sort() - ); + assert.deepStrictEqual(actual.map(normalizeDirent).sort(), expected.map(normalizePath).sort()); }); } }); @@ -383,10 +380,7 @@ describe('fsPromises glob - withFileTypes', function() { exclude: (dirent) => assert.ok(dirent instanceof Dirent), })) actual.push(item); assertDirents(actual); - assert.deepStrictEqual( - actual.map((dirent) => relative(fixtureDir, join(dirent.parentPath, dirent.name))).sort(), - expected.map((path) => (isAbsolute(path) ? relative(fixtureDir, path) : path)).sort() - ); + assert.deepStrictEqual(actual.map(normalizeDirent).sort(), expected.map(normalizePath).sort()); }); } }); From 187f483d6c903bb9f1ebdb8fa13d293ad3cebeb4 Mon Sep 17 00:00:00 2001 From: Aviv Keller Date: Thu, 26 Sep 2024 17:42:45 -0400 Subject: [PATCH 4/5] fixup! add comment --- test/parallel/test-fs-glob.mjs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/parallel/test-fs-glob.mjs b/test/parallel/test-fs-glob.mjs index 200b73b2304171..1e68dbf119e1b4 100644 --- a/test/parallel/test-fs-glob.mjs +++ b/test/parallel/test-fs-glob.mjs @@ -339,6 +339,8 @@ describe('fsPromises glob', function() { }); const normalizeDirent = (dirent) => relative(fixtureDir, join(dirent.parentPath, dirent.name)); +// The call to `join()` with only one argument is important, as +// it ensures that the proper path seperators are applied. const normalizePath = (path) => (isAbsolute(path) ? relative(fixtureDir, path) : join(path)); describe('glob - withFileTypes', function() { From 4528fd6ac0403fbde285541fed4123b45fffab96 Mon Sep 17 00:00:00 2001 From: RedYetiDev <38299977+RedYetiDev@users.noreply.github.com> Date: Mon, 30 Sep 2024 15:23:59 -0400 Subject: [PATCH 5/5] fixup! fixup! add comment --- test/parallel/test-fs-glob.mjs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/parallel/test-fs-glob.mjs b/test/parallel/test-fs-glob.mjs index 1e68dbf119e1b4..2321ceb87b8ba1 100644 --- a/test/parallel/test-fs-glob.mjs +++ b/test/parallel/test-fs-glob.mjs @@ -353,7 +353,7 @@ describe('glob - withFileTypes', function() { exclude: (dirent) => assert.ok(dirent instanceof Dirent), }); assertDirents(actual); - assert.deepStrictEqual(actual.map(normalizeDirent).sort(), expected.map(normalizePath).sort()); + assert.deepStrictEqual(actual.map(normalizeDirent).sort(), expected.filter(Boolean).map(normalizePath).sort()); }); } }); @@ -367,7 +367,7 @@ describe('globSync - withFileTypes', function() { exclude: (dirent) => assert.ok(dirent instanceof Dirent), }); assertDirents(actual); - assert.deepStrictEqual(actual.map(normalizeDirent).sort(), expected.map(normalizePath).sort()); + assert.deepStrictEqual(actual.map(normalizeDirent).sort(), expected.filter(Boolean).map(normalizePath).sort()); }); } }); @@ -382,7 +382,7 @@ describe('fsPromises glob - withFileTypes', function() { exclude: (dirent) => assert.ok(dirent instanceof Dirent), })) actual.push(item); assertDirents(actual); - assert.deepStrictEqual(actual.map(normalizeDirent).sort(), expected.map(normalizePath).sort()); + assert.deepStrictEqual(actual.map(normalizeDirent).sort(), expected.filter(Boolean).map(normalizePath).sort()); }); } });