@@ -4,6 +4,7 @@ import { resolve, dirname, sep, relative, join, isAbsolute } from 'node:path';
44import { mkdir , writeFile , symlink , glob as asyncGlob } from 'node:fs/promises' ;
55import { glob , globSync , Dirent } from 'node:fs' ;
66import { test , describe } from 'node:test' ;
7+ import { pathToFileURL } from 'node:url' ;
78import { promisify } from 'node:util' ;
89import assert from 'node:assert' ;
910
@@ -338,6 +339,39 @@ describe('fsPromises glob', function() {
338339 }
339340} ) ;
340341
342+ describe ( 'glob - with file: URL as cwd' , function ( ) {
343+ const promisified = promisify ( glob ) ;
344+ for ( const [ pattern , expected ] of Object . entries ( patterns ) ) {
345+ test ( pattern , async ( ) => {
346+ const actual = ( await promisified ( pattern , { cwd : pathToFileURL ( fixtureDir ) } ) ) . sort ( ) ;
347+ const normalized = expected . filter ( Boolean ) . map ( ( item ) => item . replaceAll ( '/' , sep ) ) . sort ( ) ;
348+ assert . deepStrictEqual ( actual , normalized ) ;
349+ } ) ;
350+ }
351+ } ) ;
352+
353+ describe ( 'globSync - with file: URL as cwd' , function ( ) {
354+ for ( const [ pattern , expected ] of Object . entries ( patterns ) ) {
355+ test ( pattern , ( ) => {
356+ const actual = globSync ( pattern , { cwd : pathToFileURL ( fixtureDir ) } ) . sort ( ) ;
357+ const normalized = expected . filter ( Boolean ) . map ( ( item ) => item . replaceAll ( '/' , sep ) ) . sort ( ) ;
358+ assert . deepStrictEqual ( actual , normalized ) ;
359+ } ) ;
360+ }
361+ } ) ;
362+
363+ describe ( 'fsPromises - with file: URL as cwdglob' , function ( ) {
364+ for ( const [ pattern , expected ] of Object . entries ( patterns ) ) {
365+ test ( pattern , async ( ) => {
366+ const actual = [ ] ;
367+ for await ( const item of asyncGlob ( pattern , { cwd : pathToFileURL ( fixtureDir ) } ) ) actual . push ( item ) ;
368+ actual . sort ( ) ;
369+ const normalized = expected . filter ( Boolean ) . map ( ( item ) => item . replaceAll ( '/' , sep ) ) . sort ( ) ;
370+ assert . deepStrictEqual ( actual , normalized ) ;
371+ } ) ;
372+ }
373+ } ) ;
374+
341375const normalizeDirent = ( dirent ) => relative ( fixtureDir , join ( dirent . parentPath , dirent . name ) ) ;
342376// The call to `join()` with only one argument is important, as
343377// it ensures that the proper path seperators are applied.
0 commit comments