@@ -8,7 +8,11 @@ async function run(input: string) {
8
8
process . cwd ( ) ,
9
9
( id ) => id
10
10
)
11
- return items . map ( ( i ) => ( { globs : i . globs , options : i . options } ) )
11
+ return items . map ( ( i ) => ( {
12
+ globs : i . globs ,
13
+ options : i . options ,
14
+ start : i . start
15
+ } ) )
12
16
}
13
17
14
18
async function runError ( input : string ) {
@@ -23,31 +27,66 @@ describe('parse positives', async () => {
23
27
it ( 'basic' , async ( ) => {
24
28
expect (
25
29
await run ( `
26
- import.meta.importGlob(\'./modules/*.ts\')
30
+ import.meta.glob(\'./modules/*.ts\')
31
+ ` )
32
+ ) . toMatchInlineSnapshot ( `
33
+ [
34
+ {
35
+ "globs": [
36
+ "./modules/*.ts",
37
+ ],
38
+ "options": {},
39
+ "start": 5,
40
+ },
41
+ ]
27
42
` )
28
- ) . toMatchInlineSnapshot ( '[]' )
29
43
} )
30
44
31
45
it ( 'array' , async ( ) => {
32
46
expect (
33
47
await run ( `
34
- import.meta.importGlob([\'./modules/*.ts\', './dir/*.{js,ts}\'])
48
+ import.meta.glob([\'./modules/*.ts\', './dir/*.{js,ts}\'])
49
+ ` )
50
+ ) . toMatchInlineSnapshot ( `
51
+ [
52
+ {
53
+ "globs": [
54
+ "./modules/*.ts",
55
+ "./dir/*.{js,ts}",
56
+ ],
57
+ "options": {},
58
+ "start": 5,
59
+ },
60
+ ]
35
61
` )
36
- ) . toMatchInlineSnapshot ( '[]' )
37
62
} )
38
63
39
64
it ( 'options with multilines' , async ( ) => {
40
65
expect (
41
66
await run ( `
42
- import.meta.importGlob ([
67
+ import.meta.glob ([
43
68
\'./modules/*.ts\',
44
69
"!./dir/*.{js,ts}"
45
70
], {
46
71
eager: true,
47
72
import: 'named'
48
73
})
49
74
` )
50
- ) . toMatchInlineSnapshot ( '[]' )
75
+ ) . toMatchInlineSnapshot ( `
76
+ [
77
+ {
78
+ "globs": [
79
+ "./modules/*.ts",
80
+ "!./dir/*.{js,ts}",
81
+ ],
82
+ "options": {
83
+ "eager": true,
84
+ "import": "named",
85
+ },
86
+ "start": 5,
87
+ },
88
+ ]
89
+ ` )
51
90
} )
52
91
53
92
it ( 'options with multilines' , async ( ) => {
@@ -68,6 +107,7 @@ describe('parse positives', async () => {
68
107
"/dir/**",
69
108
],
70
109
"options": {},
110
+ "start": 21,
71
111
},
72
112
]
73
113
` )
@@ -98,6 +138,99 @@ describe('parse positives', async () => {
98
138
"raw": true,
99
139
},
100
140
},
141
+ "start": 21,
142
+ },
143
+ ]
144
+ ` )
145
+ } )
146
+
147
+ it ( 'object properties - 1' , async ( ) => {
148
+ expect (
149
+ await run ( `
150
+ export const pageFiles = {
151
+ '.page': import.meta.glob('/**/*.page.*([a-zA-Z0-9])')
152
+ };` )
153
+ ) . toMatchInlineSnapshot ( `
154
+ [
155
+ {
156
+ "globs": [
157
+ "/**/*.page.*([a-zA-Z0-9])",
158
+ ],
159
+ "options": {},
160
+ "start": 47,
161
+ },
162
+ ]
163
+ ` )
164
+ } )
165
+
166
+ it ( 'object properties - 2' , async ( ) => {
167
+ expect (
168
+ await run ( `
169
+ export const pageFiles = {
170
+ '.page': import.meta.glob('/**/*.page.*([a-zA-Z0-9])'),
171
+ };` )
172
+ ) . toMatchInlineSnapshot ( `
173
+ [
174
+ {
175
+ "globs": [
176
+ "/**/*.page.*([a-zA-Z0-9])",
177
+ ],
178
+ "options": {},
179
+ "start": 47,
180
+ },
181
+ ]
182
+ ` )
183
+ } )
184
+
185
+ it ( 'object properties - 3' , async ( ) => {
186
+ expect (
187
+ await run ( `
188
+ export const pageFiles = {
189
+ '.page.client': import.meta.glob('/**/*.page.client.*([a-zA-Z0-9])'),
190
+ '.page.server': import.meta.glob('/**/*.page.server.*([a-zA-Z0-9])'),
191
+ };` )
192
+ ) . toMatchInlineSnapshot ( `
193
+ [
194
+ {
195
+ "globs": [
196
+ "/**/*.page.client.*([a-zA-Z0-9])",
197
+ ],
198
+ "options": {},
199
+ "start": 54,
200
+ },
201
+ {
202
+ "globs": [
203
+ "/**/*.page.server.*([a-zA-Z0-9])",
204
+ ],
205
+ "options": {},
206
+ "start": 130,
207
+ },
208
+ ]
209
+ ` )
210
+ } )
211
+
212
+ it ( 'array item' , async ( ) => {
213
+ expect (
214
+ await run ( `
215
+ export const pageFiles = [
216
+ import.meta.glob('/**/*.page.client.*([a-zA-Z0-9])'),
217
+ import.meta.glob('/**/*.page.server.*([a-zA-Z0-9])'),
218
+ ]` )
219
+ ) . toMatchInlineSnapshot ( `
220
+ [
221
+ {
222
+ "globs": [
223
+ "/**/*.page.client.*([a-zA-Z0-9])",
224
+ ],
225
+ "options": {},
226
+ "start": 38,
227
+ },
228
+ {
229
+ "globs": [
230
+ "/**/*.page.server.*([a-zA-Z0-9])",
231
+ ],
232
+ "options": {},
233
+ "start": 98,
101
234
},
102
235
]
103
236
` )
@@ -106,97 +239,117 @@ describe('parse positives', async () => {
106
239
107
240
describe ( 'parse negatives' , async ( ) => {
108
241
it ( 'syntax error' , async ( ) => {
109
- expect ( await runError ( 'import.meta.importGlob (' ) ) . toMatchInlineSnapshot (
110
- 'undefined '
242
+ expect ( await runError ( 'import.meta.glob (' ) ) . toMatchInlineSnapshot (
243
+ '[SyntaxError: Unexpected token (1:17)] '
111
244
)
112
245
} )
113
246
114
247
it ( 'empty' , async ( ) => {
115
- expect ( await runError ( 'import.meta.importGlob ()' ) ) . toMatchInlineSnapshot (
116
- 'undefined '
248
+ expect ( await runError ( 'import.meta.glob ()' ) ) . toMatchInlineSnapshot (
249
+ '[Error: Invalid glob import syntax: Expected 1-2 arguments, but got 0] '
117
250
)
118
251
} )
119
252
120
253
it ( '3 args' , async ( ) => {
121
254
expect (
122
- await runError ( 'import.meta.importGlob("", {}, {})' )
123
- ) . toMatchInlineSnapshot ( 'undefined' )
255
+ await runError ( 'import.meta.glob("", {}, {})' )
256
+ ) . toMatchInlineSnapshot (
257
+ '[Error: Invalid glob import syntax: Expected 1-2 arguments, but got 3]'
258
+ )
124
259
} )
125
260
126
261
it ( 'in string' , async ( ) => {
127
- expect ( await runError ( '"import.meta.importGlob ()"' ) ) . toBeUndefined ( )
262
+ expect ( await runError ( '"import.meta.glob ()"' ) ) . toBeUndefined ( )
128
263
} )
129
264
130
265
it ( 'variable' , async ( ) => {
131
- expect ( await runError ( 'import.meta.importGlob (hey)' ) ) . toMatchInlineSnapshot (
132
- 'undefined '
266
+ expect ( await runError ( 'import.meta.glob (hey)' ) ) . toMatchInlineSnapshot (
267
+ '[Error: Invalid glob import syntax: Could only use literals] '
133
268
)
134
269
} )
135
270
136
271
it ( 'template' , async ( ) => {
137
272
// eslint-disable-next-line no-template-curly-in-string
138
273
expect (
139
- await runError ( 'import.meta.importGlob(`hi ${hey}`)' )
140
- ) . toMatchInlineSnapshot ( 'undefined' )
274
+ await runError ( 'import.meta.glob(`hi ${hey}`)' )
275
+ ) . toMatchInlineSnapshot (
276
+ '[Error: Invalid glob import syntax: Could only use literals]'
277
+ )
141
278
} )
142
279
143
280
it ( 'be string' , async ( ) => {
144
- expect ( await runError ( 'import.meta.importGlob (1)' ) ) . toMatchInlineSnapshot (
145
- 'undefined '
281
+ expect ( await runError ( 'import.meta.glob (1)' ) ) . toMatchInlineSnapshot (
282
+ '[Error: Invalid glob import syntax: Expected glob to be a string, but got "number"] '
146
283
)
147
284
} )
148
285
149
286
it ( 'be array variable' , async ( ) => {
287
+ expect ( await runError ( 'import.meta.glob([hey])' ) ) . toMatchInlineSnapshot (
288
+ '[Error: Invalid glob import syntax: Could only use literals]'
289
+ )
150
290
expect (
151
- await runError ( 'import.meta.importGlob([hey])' )
152
- ) . toMatchInlineSnapshot ( 'undefined' )
153
- expect (
154
- await runError ( 'import.meta.importGlob(["1", hey])' )
155
- ) . toMatchInlineSnapshot ( 'undefined' )
291
+ await runError ( 'import.meta.glob(["1", hey])' )
292
+ ) . toMatchInlineSnapshot (
293
+ '[Error: Invalid glob import syntax: Could only use literals]'
294
+ )
156
295
} )
157
296
158
297
it ( 'options' , async ( ) => {
159
298
expect (
160
- await runError ( 'import.meta.importGlob("hey", hey)' )
161
- ) . toMatchInlineSnapshot ( 'undefined' )
162
- expect (
163
- await runError ( 'import.meta.importGlob("hey", [])' )
164
- ) . toMatchInlineSnapshot ( 'undefined' )
299
+ await runError ( 'import.meta.glob("hey", hey)' )
300
+ ) . toMatchInlineSnapshot (
301
+ '[Error: Invalid glob import syntax: Expected the second argument o to be a object literal, but got "Identifier"]'
302
+ )
303
+ expect ( await runError ( 'import.meta.glob("hey", [])' ) ) . toMatchInlineSnapshot (
304
+ '[Error: Invalid glob import syntax: Expected the second argument o to be a object literal, but got "ArrayExpression"]'
305
+ )
165
306
} )
166
307
167
308
it ( 'options props' , async ( ) => {
168
309
expect (
169
- await runError ( 'import.meta.importGlob("hey", { hey: 1 })' )
170
- ) . toMatchInlineSnapshot ( 'undefined' )
310
+ await runError ( 'import.meta.glob("hey", { hey: 1 })' )
311
+ ) . toMatchInlineSnapshot (
312
+ '[Error: Invalid glob import syntax: Unknown options hey]'
313
+ )
171
314
expect (
172
- await runError ( 'import.meta.importGlob("hey", { import: hey })' )
173
- ) . toMatchInlineSnapshot ( 'undefined' )
315
+ await runError ( 'import.meta.glob("hey", { import: hey })' )
316
+ ) . toMatchInlineSnapshot (
317
+ '[Error: Invalid glob import syntax: Could only use literals]'
318
+ )
174
319
expect (
175
- await runError ( 'import.meta.importGlob("hey", { eager: 123 })' )
176
- ) . toMatchInlineSnapshot ( 'undefined' )
320
+ await runError ( 'import.meta.glob("hey", { eager: 123 })' )
321
+ ) . toMatchInlineSnapshot (
322
+ '[Error: Invalid glob import syntax: Expected the type of option "eager" to be "boolean", but got "number"]'
323
+ )
177
324
} )
178
325
179
326
it ( 'options query' , async ( ) => {
180
327
expect (
181
- await runError (
182
- 'import.meta.importGlob("./*.js", { as: "raw", query: "hi" })'
183
- )
184
- ) . toMatchInlineSnapshot ( 'undefined' )
328
+ await runError ( 'import.meta.glob("./*.js", { as: "raw", query: "hi" })' )
329
+ ) . toMatchInlineSnapshot (
330
+ '[Error: Invalid glob import syntax: Options "as" and "query" cannot be used together]'
331
+ )
185
332
expect (
186
- await runError ( 'import.meta.importGlob("./*.js", { query: 123 })' )
187
- ) . toMatchInlineSnapshot ( 'undefined' )
333
+ await runError ( 'import.meta.glob("./*.js", { query: 123 })' )
334
+ ) . toMatchInlineSnapshot (
335
+ '[Error: Invalid glob import syntax: Expected query to be a string, but got "number"]'
336
+ )
188
337
expect (
189
- await runError ( 'import.meta.importGlob("./*.js", { query: { foo: {} } })' )
190
- ) . toMatchInlineSnapshot ( 'undefined' )
338
+ await runError ( 'import.meta.glob("./*.js", { query: { foo: {} } })' )
339
+ ) . toMatchInlineSnapshot (
340
+ '[Error: Invalid glob import syntax: Could only use literals]'
341
+ )
191
342
expect (
192
- await runError (
193
- 'import.meta.importGlob("./*.js", { query: { foo: hey } })'
194
- )
195
- ) . toMatchInlineSnapshot ( 'undefined' )
343
+ await runError ( 'import.meta.glob("./*.js", { query: { foo: hey } })' )
344
+ ) . toMatchInlineSnapshot (
345
+ '[Error: Invalid glob import syntax: Could only use literals]'
346
+ )
196
347
expect (
197
348
await runError (
198
- 'import.meta.importGlob ("./*.js", { query: { foo: 123, ...a } })'
349
+ 'import.meta.glob ("./*.js", { query: { foo: 123, ...a } })'
199
350
)
200
- ) . toMatchInlineSnapshot ( 'undefined' )
351
+ ) . toMatchInlineSnapshot (
352
+ '[Error: Invalid glob import syntax: Could only use literals]'
353
+ )
201
354
} )
202
355
} )
0 commit comments