@@ -19,6 +19,29 @@ describe('ConfigLoader', () => {
1919 return path . join ( ...filePath . split ( '/' ) ) ;
2020 }
2121
22+ function mockFdir ( results : string [ ] | ( ( ) => string [ ] ) ) : any {
23+ return class {
24+ withPathSeparator ( ) {
25+ return this ;
26+ }
27+ exclude ( ) {
28+ return this ;
29+ }
30+ filter ( ) {
31+ return this ;
32+ }
33+ withRelativePaths ( ) {
34+ return this ;
35+ }
36+ crawl ( ) {
37+ return this ;
38+ }
39+ sync ( ) {
40+ return typeof results === 'function' ? results ( ) : results ;
41+ }
42+ } ;
43+ }
44+
2245 async function assertFindsConfig (
2346 configLoader : ConfigLoader ,
2447 filePath : string ,
@@ -32,7 +55,7 @@ describe('ConfigLoader', () => {
3255
3356 it ( 'should load all config files below and the one inside/above given directory' , async ( ) => {
3457 const configLoader = new ConfigLoader (
35- ( ( ) => [ 'svelte.config.js' , 'below/svelte.config.js' ] ) as any ,
58+ mockFdir ( [ 'svelte.config.js' , 'below/svelte.config.js' ] ) ,
3659 { existsSync : ( ) => true } ,
3760 path ,
3861 ( module : URL ) => Promise . resolve ( { default : { preprocess : module . toString ( ) } } )
@@ -63,7 +86,7 @@ describe('ConfigLoader', () => {
6386
6487 it ( 'finds first above if none found inside/below directory' , async ( ) => {
6588 const configLoader = new ConfigLoader (
66- ( ) => [ ] ,
89+ mockFdir ( [ ] ) ,
6790 {
6891 existsSync : ( p ) =>
6992 typeof p === 'string' && p . endsWith ( path . join ( 'some' , 'svelte.config.js' ) )
@@ -78,7 +101,7 @@ describe('ConfigLoader', () => {
78101
79102 it ( 'adds fallback if no config found' , async ( ) => {
80103 const configLoader = new ConfigLoader (
81- ( ) => [ ] ,
104+ mockFdir ( [ ] ) ,
82105 { existsSync : ( ) => false } ,
83106 path ,
84107 ( module : URL ) => Promise . resolve ( { default : { preprocess : module . toString ( ) } } )
@@ -98,14 +121,14 @@ describe('ConfigLoader', () => {
98121 let firstGlobCall = true ;
99122 let nrImportCalls = 0 ;
100123 const configLoader = new ConfigLoader (
101- ( ( ) => {
124+ mockFdir ( ( ) => {
102125 if ( firstGlobCall ) {
103126 firstGlobCall = false ;
104127 return [ 'svelte.config.js' ] ;
105128 } else {
106129 return [ ] ;
107130 }
108- } ) as any ,
131+ } ) ,
109132 {
110133 existsSync : ( p ) =>
111134 typeof p === 'string' &&
@@ -139,11 +162,8 @@ describe('ConfigLoader', () => {
139162 } ) ;
140163
141164 it ( 'can deal with missing config' , ( ) => {
142- const configLoader = new ConfigLoader (
143- ( ) => [ ] ,
144- { existsSync : ( ) => false } ,
145- path ,
146- ( ) => Promise . resolve ( 'unimportant' )
165+ const configLoader = new ConfigLoader ( mockFdir ( [ ] ) , { existsSync : ( ) => false } , path , ( ) =>
166+ Promise . resolve ( 'unimportant' )
147167 ) ;
148168 assert . deepStrictEqual (
149169 configLoader . getConfig ( normalizePath ( '/some/file.svelte' ) ) ,
@@ -153,7 +173,7 @@ describe('ConfigLoader', () => {
153173
154174 it ( 'should await config' , async ( ) => {
155175 const configLoader = new ConfigLoader (
156- ( ) => [ ] ,
176+ mockFdir ( [ ] ) ,
157177 { existsSync : ( ) => true } ,
158178 path ,
159179 ( module : URL ) => Promise . resolve ( { default : { preprocess : module . toString ( ) } } )
@@ -167,7 +187,7 @@ describe('ConfigLoader', () => {
167187 it ( 'should not load config when disabled' , async ( ) => {
168188 const moduleLoader = spy ( ) ;
169189 const configLoader = new ConfigLoader (
170- ( ) => [ ] ,
190+ mockFdir ( [ ] ) ,
171191 { existsSync : ( ) => true } ,
172192 path ,
173193 moduleLoader
0 commit comments