@@ -19,6 +19,29 @@ describe('ConfigLoader', () => {
19
19
return path . join ( ...filePath . split ( '/' ) ) ;
20
20
}
21
21
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
+
22
45
async function assertFindsConfig (
23
46
configLoader : ConfigLoader ,
24
47
filePath : string ,
@@ -32,7 +55,7 @@ describe('ConfigLoader', () => {
32
55
33
56
it ( 'should load all config files below and the one inside/above given directory' , async ( ) => {
34
57
const configLoader = new ConfigLoader (
35
- ( ( ) => [ 'svelte.config.js' , 'below/svelte.config.js' ] ) as any ,
58
+ mockFdir ( [ 'svelte.config.js' , 'below/svelte.config.js' ] ) ,
36
59
{ existsSync : ( ) => true } ,
37
60
path ,
38
61
( module : URL ) => Promise . resolve ( { default : { preprocess : module . toString ( ) } } )
@@ -63,7 +86,7 @@ describe('ConfigLoader', () => {
63
86
64
87
it ( 'finds first above if none found inside/below directory' , async ( ) => {
65
88
const configLoader = new ConfigLoader (
66
- ( ) => [ ] ,
89
+ mockFdir ( [ ] ) ,
67
90
{
68
91
existsSync : ( p ) =>
69
92
typeof p === 'string' && p . endsWith ( path . join ( 'some' , 'svelte.config.js' ) )
@@ -78,7 +101,7 @@ describe('ConfigLoader', () => {
78
101
79
102
it ( 'adds fallback if no config found' , async ( ) => {
80
103
const configLoader = new ConfigLoader (
81
- ( ) => [ ] ,
104
+ mockFdir ( [ ] ) ,
82
105
{ existsSync : ( ) => false } ,
83
106
path ,
84
107
( module : URL ) => Promise . resolve ( { default : { preprocess : module . toString ( ) } } )
@@ -98,14 +121,14 @@ describe('ConfigLoader', () => {
98
121
let firstGlobCall = true ;
99
122
let nrImportCalls = 0 ;
100
123
const configLoader = new ConfigLoader (
101
- ( ( ) => {
124
+ mockFdir ( ( ) => {
102
125
if ( firstGlobCall ) {
103
126
firstGlobCall = false ;
104
127
return [ 'svelte.config.js' ] ;
105
128
} else {
106
129
return [ ] ;
107
130
}
108
- } ) as any ,
131
+ } ) ,
109
132
{
110
133
existsSync : ( p ) =>
111
134
typeof p === 'string' &&
@@ -139,11 +162,8 @@ describe('ConfigLoader', () => {
139
162
} ) ;
140
163
141
164
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' )
147
167
) ;
148
168
assert . deepStrictEqual (
149
169
configLoader . getConfig ( normalizePath ( '/some/file.svelte' ) ) ,
@@ -153,7 +173,7 @@ describe('ConfigLoader', () => {
153
173
154
174
it ( 'should await config' , async ( ) => {
155
175
const configLoader = new ConfigLoader (
156
- ( ) => [ ] ,
176
+ mockFdir ( [ ] ) ,
157
177
{ existsSync : ( ) => true } ,
158
178
path ,
159
179
( module : URL ) => Promise . resolve ( { default : { preprocess : module . toString ( ) } } )
@@ -167,7 +187,7 @@ describe('ConfigLoader', () => {
167
187
it ( 'should not load config when disabled' , async ( ) => {
168
188
const moduleLoader = spy ( ) ;
169
189
const configLoader = new ConfigLoader (
170
- ( ) => [ ] ,
190
+ mockFdir ( [ ] ) ,
171
191
{ existsSync : ( ) => true } ,
172
192
path ,
173
193
moduleLoader
0 commit comments