File tree Expand file tree Collapse file tree 4 files changed +17
-4
lines changed
Expand file tree Collapse file tree 4 files changed +17
-4
lines changed Original file line number Diff line number Diff line change 11import * as assert from 'node:assert' ;
2+ import { pathToFileURL } from 'node:url' ;
23
34import { describe , it } from 'mocha' ;
45
@@ -66,4 +67,12 @@ describe('Settings', () => {
6667
6768 assert . strictEqual ( settings . fs . readdirSync , customReaddirSync ) ;
6869 } ) ;
70+
71+ it ( 'should transform URL to string on cwd' , ( ) => {
72+ const settings = new Settings ( {
73+ cwd : new URL ( pathToFileURL ( process . cwd ( ) ) ) ,
74+ } ) ;
75+
76+ assert . ok ( typeof settings . cwd === 'string' ) ;
77+ } ) ;
6978} ) ;
Original file line number Diff line number Diff line change 11import * as fs from 'node:fs' ;
2+ import { fileURLToPath } from 'node:url' ;
23
34import type { FileSystemAdapter , Pattern } from './types' ;
45
@@ -42,7 +43,7 @@ export interface Options {
4243 *
4344 * @default process.cwd()
4445 */
45- cwd ?: string ;
46+ cwd ?: string | URL ;
4647 /**
4748 * Specifies the maximum depth of a read directory relative to the start
4849 * directory.
@@ -176,7 +177,7 @@ export default class Settings {
176177 this . baseNameMatch = options . baseNameMatch ?? false ;
177178 this . braceExpansion = options . braceExpansion ?? true ;
178179 this . caseSensitiveMatch = options . caseSensitiveMatch ?? true ;
179- this . cwd = options . cwd ?? process . cwd ( ) ;
180+ this . cwd = options . cwd instanceof URL ? fileURLToPath ( options . cwd ) : options . cwd ?? process . cwd ( ) ;
180181 this . deep = options . deep ?? Number . POSITIVE_INFINITY ;
181182 this . dot = options . dot ?? false ;
182183 this . extglob = options . extglob ?? true ;
Original file line number Diff line number Diff line change 11/* eslint-disable mocha/no-setup-in-describe */
22import * as assert from 'node:assert' ;
3+ import { fileURLToPath } from 'node:url' ;
34
4- import * as snapshotIt from 'snap-shot-it' ;
5+ import snapshotIt from 'snap-shot-it' ;
56import { describe , it } from 'mocha' ;
67
78import * as fg from '../..' ;
@@ -95,8 +96,9 @@ function getTestPatterns(test: Test): Pattern[] {
9596
9697function getTestTitle ( test : Test ) : string {
9798 // Replacing placeholders to hide absolute paths from snapshots.
99+ const cwd = test . options ?. cwd instanceof URL ? fileURLToPath ( test . options . cwd ) : test . options ?. cwd ;
98100 const replacements = {
99- cwd : test . options ?. cwd ?. replace ( CWD , '<root>' ) ,
101+ cwd : cwd ?. replace ( CWD , '<root>' ) ,
100102 ignore : test . options ?. ignore ?. map ( ( pattern ) => pattern . replace ( CWD , '<root>' ) ) ,
101103 } ;
102104
Original file line number Diff line number Diff line change 2020 "noFallthroughCasesInSwitch" : true ,
2121
2222 "forceConsistentCasingInFileNames" : true ,
23+ "esModuleInterop" : true ,
2324 "verbatimModuleSyntax" : false ,
2425
2526 "downlevelIteration" : true ,
You can’t perform that action at this time.
0 commit comments