@@ -289,6 +289,72 @@ query {id}
289
289
query {id}` ) ;
290
290
} ) ;
291
291
292
+ it ( 'no crash in Svelte files without <script>' , async ( ) => {
293
+ const text = `` ;
294
+
295
+ const consoleErrorSpy = jest
296
+ . spyOn ( process . stderr , 'write' )
297
+ . mockImplementation ( ( ) => true ) ;
298
+
299
+ const contents = baseFindGraphQLTags (
300
+ text ,
301
+ '.svelte' ,
302
+ '' ,
303
+ new Logger ( tmpdir ( ) , false ) ,
304
+ ) ;
305
+ // We should have no contents
306
+ expect ( contents ) . toMatchObject ( [ ] ) ;
307
+
308
+ // Nothing should be logged as it's a managed error
309
+ expect ( consoleErrorSpy . mock . calls . length ) . toBe ( 0 ) ;
310
+
311
+ consoleErrorSpy . mockRestore ( ) ;
312
+ } ) ;
313
+
314
+ it ( 'no crash in Svelte files with empty <script>' , async ( ) => {
315
+ const text = `<script></script>` ;
316
+
317
+ const consoleErrorSpy = jest
318
+ . spyOn ( process . stderr , 'write' )
319
+ . mockImplementation ( ( ) => true ) ;
320
+
321
+ const contents = baseFindGraphQLTags (
322
+ text ,
323
+ '.svelte' ,
324
+ '' ,
325
+ new Logger ( tmpdir ( ) , false ) ,
326
+ ) ;
327
+ // We should have no contents
328
+ expect ( contents ) . toMatchObject ( [ ] ) ;
329
+
330
+ // Nothing should be logged as it's a managed error
331
+ expect ( consoleErrorSpy . mock . calls . length ) . toBe ( 0 ) ;
332
+
333
+ consoleErrorSpy . mockRestore ( ) ;
334
+ } ) ;
335
+
336
+ it ( 'no crash in Svelte files with empty <script> (typescript)' , async ( ) => {
337
+ const text = `<script lang="ts"></script>` ;
338
+
339
+ const consoleErrorSpy = jest
340
+ . spyOn ( process . stderr , 'write' )
341
+ . mockImplementation ( ( ) => true ) ;
342
+
343
+ const contents = baseFindGraphQLTags (
344
+ text ,
345
+ '.svelte' ,
346
+ '' ,
347
+ new Logger ( tmpdir ( ) , false ) ,
348
+ ) ;
349
+ // We should have no contents
350
+ expect ( contents ) . toMatchObject ( [ ] ) ;
351
+
352
+ // Nothing should be logged as it's a managed error
353
+ expect ( consoleErrorSpy . mock . calls . length ) . toBe ( 0 ) ;
354
+
355
+ consoleErrorSpy . mockRestore ( ) ;
356
+ } ) ;
357
+
292
358
it ( 'finds multiple queries in a single file' , async ( ) => {
293
359
const text = `something({
294
360
else: () => gql\` query {} \`
0 commit comments