@@ -14,13 +14,17 @@ describe('ConfigLoader', () => {
14
14
} ;
15
15
}
16
16
17
+ function normalizePath ( filePath : string ) : string {
18
+ return path . join ( ...filePath . split ( '/' ) ) ;
19
+ }
20
+
17
21
async function assertFindsConfig (
18
22
configLoader : ConfigLoader ,
19
23
filePath : string ,
20
24
configPath : string
21
25
) {
22
- filePath = path . join ( ... filePath . split ( '/' ) ) ;
23
- configPath = path . join ( ... configPath . split ( '/' ) ) ;
26
+ filePath = normalizePath ( filePath ) ;
27
+ configPath = normalizePath ( configPath ) ;
24
28
assert . deepStrictEqual ( configLoader . getConfig ( filePath ) , configFrom ( configPath ) ) ;
25
29
assert . deepStrictEqual ( await configLoader . awaitConfig ( filePath ) , configFrom ( configPath ) ) ;
26
30
}
@@ -32,20 +36,24 @@ describe('ConfigLoader', () => {
32
36
path ,
33
37
( module : URL ) => Promise . resolve ( { default : { preprocess : module . toString ( ) } } )
34
38
) ;
35
- await configLoader . loadConfigs ( '/some/path' ) ;
39
+ await configLoader . loadConfigs ( normalizePath ( '/some/path' ) ) ;
36
40
37
- assertFindsConfig ( configLoader , '/some/path/comp.svelte' , '/some/path/svelte.config.js' ) ;
38
- assertFindsConfig (
41
+ await assertFindsConfig (
42
+ configLoader ,
43
+ '/some/path/comp.svelte' ,
44
+ '/some/path/svelte.config.js'
45
+ ) ;
46
+ await assertFindsConfig (
39
47
configLoader ,
40
48
'/some/path/aside/comp.svelte' ,
41
49
'/some/path/svelte.config.js'
42
50
) ;
43
- assertFindsConfig (
51
+ await assertFindsConfig (
44
52
configLoader ,
45
53
'/some/path/below/comp.svelte' ,
46
54
'/some/path/below/svelte.config.js'
47
55
) ;
48
- assertFindsConfig (
56
+ await assertFindsConfig (
49
57
configLoader ,
50
58
'/some/path/below/further/comp.svelte' ,
51
59
'/some/path/below/svelte.config.js'
@@ -62,9 +70,9 @@ describe('ConfigLoader', () => {
62
70
path ,
63
71
( module : URL ) => Promise . resolve ( { default : { preprocess : module . toString ( ) } } )
64
72
) ;
65
- await configLoader . loadConfigs ( '/some/path' ) ;
73
+ await configLoader . loadConfigs ( normalizePath ( '/some/path' ) ) ;
66
74
67
- assertFindsConfig ( configLoader , '/some/path/comp.svelte' , '/some/svelte.config.js' ) ;
75
+ await assertFindsConfig ( configLoader , '/some/path/comp.svelte' , '/some/svelte.config.js' ) ;
68
76
} ) ;
69
77
70
78
it ( 'adds fallback if no config found' , async ( ) => {
@@ -74,12 +82,14 @@ describe('ConfigLoader', () => {
74
82
path ,
75
83
( module : URL ) => Promise . resolve ( { default : { preprocess : module . toString ( ) } } )
76
84
) ;
77
- await configLoader . loadConfigs ( '/some/path' ) ;
85
+ await configLoader . loadConfigs ( normalizePath ( '/some/path' ) ) ;
78
86
79
87
assert . deepStrictEqual (
80
88
// Can't do the equal-check directly, instead check if it's the expected object props
81
89
// of svelte-preprocess
82
- Object . keys ( configLoader . getConfig ( '/some/path/comp.svelte' ) ?. preprocess || { } ) . sort ( ) ,
90
+ Object . keys (
91
+ configLoader . getConfig ( normalizePath ( '/some/path/comp.svelte' ) ) ?. preprocess || { }
92
+ ) . sort ( ) ,
83
93
[ 'defaultLanguages' , 'markup' , 'script' , 'style' ] . sort ( )
84
94
) ;
85
95
} ) ;
@@ -110,13 +120,17 @@ describe('ConfigLoader', () => {
110
120
}
111
121
) ;
112
122
await Promise . all ( [
113
- configLoader . loadConfigs ( '/some/path' ) ,
114
- configLoader . loadConfigs ( '/some/path/sub' ) ,
115
- configLoader . awaitConfig ( '/some/path/file.svelte' )
123
+ configLoader . loadConfigs ( normalizePath ( '/some/path' ) ) ,
124
+ configLoader . loadConfigs ( normalizePath ( '/some/path/sub' ) ) ,
125
+ configLoader . awaitConfig ( normalizePath ( '/some/path/file.svelte' ) )
116
126
] ) ;
117
127
118
- assertFindsConfig ( configLoader , '/some/path/comp.svelte' , '/some/path/svelte.config.js' ) ;
119
- assertFindsConfig (
128
+ await assertFindsConfig (
129
+ configLoader ,
130
+ '/some/path/comp.svelte' ,
131
+ '/some/path/svelte.config.js'
132
+ ) ;
133
+ await assertFindsConfig (
120
134
configLoader ,
121
135
'/some/path/sub/comp.svelte' ,
122
136
'/some/path/svelte.config.js'
@@ -131,7 +145,10 @@ describe('ConfigLoader', () => {
131
145
path ,
132
146
( ) => Promise . resolve ( 'unimportant' )
133
147
) ;
134
- assert . deepStrictEqual ( configLoader . getConfig ( '/some/file.svelte' ) , undefined ) ;
148
+ assert . deepStrictEqual (
149
+ configLoader . getConfig ( normalizePath ( '/some/file.svelte' ) ) ,
150
+ undefined
151
+ ) ;
135
152
} ) ;
136
153
137
154
it ( 'should await config' , async ( ) => {
@@ -142,8 +159,8 @@ describe('ConfigLoader', () => {
142
159
( module : URL ) => Promise . resolve ( { default : { preprocess : module . toString ( ) } } )
143
160
) ;
144
161
assert . deepStrictEqual (
145
- await configLoader . awaitConfig ( path . join ( 'some' , ' file.svelte') ) ,
146
- configFrom ( path . join ( 'some' , ' svelte.config.js') )
162
+ await configLoader . awaitConfig ( normalizePath ( 'some/ file.svelte' ) ) ,
163
+ configFrom ( normalizePath ( 'some/ svelte.config.js' ) )
147
164
) ;
148
165
} ) ;
149
166
} ) ;
0 commit comments