@@ -288,4 +288,100 @@ describe('CLI: watched typechecking', () => {
288
288
289
289
await watch . terminate ( ) ;
290
290
} ) ;
291
+
292
+ test ( 'reporting watched diagnostics' , async ( ) => {
293
+ let code = 'let identifier: string = 123;' ;
294
+
295
+ project . setGlintConfig ( { environment : 'ember-template-imports' } ) ;
296
+ project . write ( 'index.gts' , code ) ;
297
+
298
+ let watch = project . checkWatch ( ) ;
299
+ let output = await watch . awaitOutput ( 'Watching for file changes.' ) ;
300
+
301
+ await watch . terminate ( ) ;
302
+
303
+ let stripped = stripAnsi ( output ) ;
304
+ let error = stripped . slice (
305
+ stripped . indexOf ( 'index.gts' ) ,
306
+ stripped . lastIndexOf ( `~~~${ os . EOL } ` ) + 3 ,
307
+ ) ;
308
+
309
+ expect ( output ) . toMatch ( 'Found 1 error.' ) ;
310
+ expect ( error . replace ( / \r / g, '' ) ) . toMatchInlineSnapshot ( `
311
+ "index.gts:1:5 - error TS2322: Type 'number' is not assignable to type 'string'.
312
+
313
+ 1 let identifier: string = 123;let identifier: string = 123;
314
+ ~~~~~~~~~~"
315
+ ` ) ;
316
+ } ) ;
317
+
318
+ // A number of issues with these tests:
319
+ //
320
+ // - `.gjs` (untyped) file not yet supported
321
+ // - extension-less imports are causing issues specifically with `--watch` even though they work in non-watch mode
322
+ // - Discussing/tracking here: https://discord.com/channels/1192759067815464990/1192759067815464993/1258084777618178159
323
+ // - (I noticed this after changing other.gjs to other.gts)
324
+ describe . skip ( 'external file changes' , ( ) => {
325
+ beforeEach ( ( ) => {
326
+ project . setGlintConfig ( { environment : 'ember-template-imports' } ) ;
327
+ project . write (
328
+ 'index.gts' ,
329
+ stripIndent `
330
+ import { foo } from "./other";
331
+ console.log(foo - 1);
332
+ ` ,
333
+ ) ;
334
+ } ) ;
335
+
336
+ test ( 'adding a missing module' , async ( ) => {
337
+ let watch = project . checkWatch ( ) ;
338
+ let output = await watch . awaitOutput ( 'Watching for file changes.' ) ;
339
+
340
+ expect ( output ) . toMatch ( 'Found 1 error.' ) ;
341
+ expect ( output ) . toMatch (
342
+ "Cannot find module './other' or its corresponding type declarations." ,
343
+ ) ;
344
+
345
+ project . write ( 'other.gjs' , 'export const foo = 123;' ) ;
346
+
347
+ await watch . awaitOutput ( 'Found 0 errors.' ) ;
348
+ await watch . terminate ( ) ;
349
+ } ) ;
350
+
351
+ test ( 'changing an imported module' , async ( ) => {
352
+ project . write ( 'other.gjs' , 'export const foo = 123;' ) ;
353
+
354
+ let watch = project . checkWatch ( ) ;
355
+ let output = await watch . awaitOutput ( 'Watching for file changes.' ) ;
356
+
357
+ expect ( output ) . toMatch ( 'Found 0 errors.' ) ;
358
+
359
+ project . write ( 'other.gjs' , 'export const foo = "hi";' ) ;
360
+ output = await watch . awaitOutput ( 'Watching for file changes.' ) ;
361
+
362
+ expect ( output ) . toMatch ( 'Found 1 error.' ) ;
363
+ expect ( output ) . toMatch ( 'TS2362' ) ;
364
+
365
+ await watch . terminate ( ) ;
366
+ } ) ;
367
+
368
+ test ( 'removing an imported module' , async ( ) => {
369
+ project . write ( 'other.gjs' , 'export const foo = 123;' ) ;
370
+
371
+ let watch = project . checkWatch ( ) ;
372
+ let output = await watch . awaitOutput ( 'Watching for file changes.' ) ;
373
+
374
+ expect ( output ) . toMatch ( 'Found 0 errors.' ) ;
375
+
376
+ project . remove ( 'other.gjs' ) ;
377
+ output = await watch . awaitOutput ( 'Watching for file changes.' ) ;
378
+
379
+ expect ( output ) . toMatch ( 'Found 1 error.' ) ;
380
+ expect ( output ) . toMatch (
381
+ "Cannot find module './other' or its corresponding type declarations." ,
382
+ ) ;
383
+
384
+ await watch . terminate ( ) ;
385
+ } ) ;
386
+ } ) ;
291
387
} ) ;
0 commit comments