55
66import * as vscode from 'vscode'
77import assert from 'assert'
8- import {
9- closeAllEditors ,
10- getTestWindow ,
11- registerAuthHook ,
12- resetCodeWhispererGlobalVariables ,
13- TestFolder ,
14- toTextEditor ,
15- using ,
16- } from 'aws-core-vscode/test'
17- import { session } from 'aws-core-vscode/codewhisperer'
8+ import { closeAllEditors , registerAuthHook , TestFolder , toTextEditor , using } from 'aws-core-vscode/test'
189import { Commands , globals , sleep , waitUntil , collectionUtil } from 'aws-core-vscode/shared'
1910import { loginToIdC } from '../amazonq/utils/setup'
11+ import { vsCodeState } from 'aws-core-vscode/codewhisperer'
2012
2113describe ( 'Amazon Q Inline' , async function ( ) {
2214 const retries = 3
@@ -40,7 +32,6 @@ describe('Amazon Q Inline', async function () {
4032 const folder = await TestFolder . create ( )
4133 tempFolder = folder . path
4234 await closeAllEditors ( )
43- await resetCodeWhispererGlobalVariables ( )
4435 } )
4536
4637 afterEach ( async function ( ) {
@@ -70,17 +61,6 @@ describe('Amazon Q Inline', async function () {
7061 } )
7162 }
7263
73- async function waitForRecommendations ( ) {
74- const suggestionShown = await waitUntil ( async ( ) => session . getSuggestionState ( 0 ) === 'Showed' , waitOptions )
75- if ( ! suggestionShown ) {
76- throw new Error ( `Suggestion did not show. Suggestion States: ${ JSON . stringify ( session . suggestionStates ) } ` )
77- }
78- console . table ( {
79- 'suggestions states' : JSON . stringify ( session . suggestionStates ) ,
80- recommendations : session . recommendations ,
81- } )
82- }
83-
8464 /**
8565 * Waits for a specific telemetry event to be emitted with the expected suggestion state.
8666 * It looks like there might be a potential race condition in codewhisperer causing telemetry
@@ -134,8 +114,9 @@ describe('Amazon Q Inline', async function () {
134114 await invokeCompletion ( )
135115 originalEditorContents = vscode . window . activeTextEditor ?. document . getText ( )
136116
137- // wait until the ghost text appears
138- await waitForRecommendations ( )
117+ // wait until all the recommendations have finished
118+ await waitUntil ( ( ) => Promise . resolve ( vsCodeState . isRecommendationsActive === true ) , waitOptions )
119+ await waitUntil ( ( ) => Promise . resolve ( vsCodeState . isRecommendationsActive === false ) , waitOptions )
139120 }
140121
141122 beforeEach ( async ( ) => {
@@ -148,14 +129,12 @@ describe('Amazon Q Inline', async function () {
148129 try {
149130 await setup ( )
150131 console . log ( `test run ${ attempt } succeeded` )
151- logUserDecisionStatus ( )
152132 break
153133 } catch ( e ) {
154134 console . log ( `test run ${ attempt } failed` )
155135 console . log ( e )
156136 logUserDecisionStatus ( )
157137 attempt ++
158- await resetCodeWhispererGlobalVariables ( )
159138 }
160139 }
161140 if ( attempt === retries ) {
@@ -201,29 +180,6 @@ describe('Amazon Q Inline', async function () {
201180 assert . deepStrictEqual ( vscode . window . activeTextEditor ?. document . getText ( ) , originalEditorContents )
202181 } )
203182 } )
204-
205- it ( `${ name } invoke on unsupported filetype` , async function ( ) {
206- await setupEditor ( {
207- name : 'test.zig' ,
208- contents : `fn doSomething() void {
209-
210- }` ,
211- } )
212-
213- /**
214- * Add delay between editor loading and invoking completion
215- * @see beforeEach in supported filetypes for more information
216- */
217- await sleep ( 1000 )
218- await invokeCompletion ( )
219-
220- if ( name === 'automatic' ) {
221- // It should never get triggered since its not a supported file type
222- // assert.deepStrictEqual(RecommendationService.instance.isRunning, false)
223- } else {
224- await getTestWindow ( ) . waitForMessage ( 'currently not supported by Amazon Q inline suggestions' )
225- }
226- } )
227183 } )
228184 }
229185} )
0 commit comments