1- import {
2- commands ,
3- languages ,
4- ViewColumn ,
5- window ,
6- Uri ,
7- Range ,
8- Position ,
9- CodeAction ,
10- workspace ,
11- TextEditor ,
12- } from 'vscode' ;
1+ import { commands , languages , ViewColumn , window , Uri , Range } from 'vscode' ;
132import * as path from 'path' ;
143import { describe , afterEach , test } from 'mocha' ;
154import { expect } from 'expect' ;
@@ -28,15 +17,28 @@ describe('Smoke test: Loose Mode + GTS with TS Plugin Mode', () => {
2817 describe ( 'loose mode aka ts + hbs two-file components' , ( ) => {
2918 describe ( 'diagnostics' , ( ) => {
3019 test ( 'reports errors and errors disappear when fixed' , async ( ) => {
31- let scriptURI = Uri . file ( `${ rootDir } /app/components/colocated-layout-with-errors.hbs` ) ;
20+ let tsScriptURI = Uri . file ( `${ rootDir } /app/components/colocated-layout-with-errors.ts` ) ;
21+
22+ // Open the backing TS component file. Currently this is required in order to activate the VSCode,
23+ // which is currently only configured to activate for .gts and .gjs files.
24+ await window . showTextDocument ( tsScriptURI , {
25+ viewColumn : ViewColumn . One ,
26+ } ) ;
27+
28+ let hbsScriptURI = Uri . file ( `${ rootDir } /app/components/colocated-layout-with-errors.hbs` ) ;
3229
3330 // Open the script and the template
34- let scriptEditor = await window . showTextDocument ( scriptURI , { viewColumn : ViewColumn . One } ) ;
31+ let scriptEditor = await window . showTextDocument ( hbsScriptURI , {
32+ viewColumn : ViewColumn . One ,
33+ } ) ;
3534
3635 // Wait for a diagnostic to appear in the template
37- await waitUntil ( ( ) => languages . getDiagnostics ( scriptURI ) . length , 'diagnostic to appear' ) ;
36+ await waitUntil (
37+ ( ) => languages . getDiagnostics ( hbsScriptURI ) . length ,
38+ 'diagnostic to appear' ,
39+ ) ;
3840
39- expect ( languages . getDiagnostics ( scriptURI ) ) . toMatchObject ( [
41+ expect ( languages . getDiagnostics ( hbsScriptURI ) ) . toMatchObject ( [
4042 {
4143 message :
4244 "Property 'messageeee' does not exist on type 'ColocatedLayoutComponent'. Did you mean 'message'?" ,
@@ -52,65 +54,10 @@ describe('Smoke test: Loose Mode + GTS with TS Plugin Mode', () => {
5254
5355 // Wait for the diagnostic to disappear
5456 await waitUntil (
55- ( ) => languages . getDiagnostics ( scriptURI ) . length == 0 ,
57+ ( ) => languages . getDiagnostics ( hbsScriptURI ) . length == 0 ,
5658 'diagnostic to disappear' ,
5759 ) ;
5860 } ) ;
5961 } ) ;
6062 } ) ;
6163} ) ;
62-
63- /**
64- * It takes a little while for the TS Plugin to fully activate, and unfortunately
65- * VSCode won't automatically re-trigger/re-calculate diagnostics for a file after
66- * a TS Plugin kicks in, so we need some way to know that the TS Plugin is activated
67- * before we edit the file.
68- *
69- * To accomplish this, this function inserts invalid TS into the .gts file and waits
70- * for diagnostics to show up.
71- */
72- async function hackishlyWaitForTypescriptPluginToActivate (
73- scriptEditor : TextEditor ,
74- scriptURI : Uri ,
75- ) : Promise < void > {
76- let invalidAssignment = 'let s: string = 123;' ;
77- await scriptEditor . edit ( ( edit ) => {
78- edit . insert ( new Position ( 0 , 0 ) , invalidAssignment ) ;
79- } ) ;
80-
81- let numSpacesAdded = 0 ;
82- const startTime = Date . now ( ) ;
83-
84- // eslint-disable-next-line no-constant-condition
85- while ( true ) {
86- await scriptEditor . edit ( ( edit ) => {
87- edit . insert ( new Position ( 0 , 0 ) , ' ' ) ;
88- } ) ;
89- numSpacesAdded ++ ;
90-
91- if ( languages . getDiagnostics ( scriptURI ) . length ) {
92- break ;
93- }
94-
95- if ( Date . now ( ) - startTime > 5000 ) {
96- throw new Error (
97- 'Timed out waiting for TS Plugin to activate (i.e. waiting for diagnostics to show up)' ,
98- ) ;
99- }
100-
101- // We'd love to wait for a smaller increment than 1000 but the editor
102- // debounces before triggering diagnostics so we need a large enough time.
103- await new Promise ( ( resolve ) => setTimeout ( resolve , 1000 ) ) ;
104- }
105-
106- // Remove our invalid assignment
107- await scriptEditor . edit ( ( edit ) => {
108- edit . replace ( new Range ( 0 , 0 , 0 , invalidAssignment . length + numSpacesAdded ) , '' ) ;
109- } ) ;
110-
111- await new Promise ( ( resolve ) => setTimeout ( resolve , 1000 ) ) ;
112-
113- if ( languages . getDiagnostics ( scriptURI ) . length ) {
114- throw new Error ( 'Diagnostics still showing up after removing invalid assignment' ) ;
115- }
116- }
0 commit comments