Skip to content

Commit c93536c

Browse files
committed
Inline Test and Update to generalUtils
1 parent 92c3f61 commit c93536c

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

packages/amazonq/test/e2e_new/amazonq/tests/inline.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import '../utils/setup'
66
import { Workbench, EditorView, InputBox, TextEditor, WebviewView, Key } from 'vscode-extension-tester'
77
import { testContext } from '../utils/testContext'
8-
import { createNewTextFile, writeToTextEditor, sleep } from '../utils/generalUtils'
8+
import { createNewTextFile, writeToTextEditor, waitForEditorStabilization } from '../utils/generalUtils'
99
import assert from 'assert'
1010

1111
describe('Amazon Q Inline Completion / Chat Functionality', function () {
@@ -40,11 +40,11 @@ describe('Amazon Q Inline Completion / Chat Functionality', function () {
4040
const input = new InputBox()
4141
await input.sendKeys('Generate the fibonacci sequence through iteration')
4242
await input.sendKeys(Key.ENTER)
43-
// Must wait for response to be generated.
44-
await sleep(8000)
43+
// Wait for Amazon Q to finish generating code
44+
await waitForEditorStabilization(textEditor)
4545

4646
const textAfter = await textEditor.getText()
47-
assert(textAfter.length > textBefore.length, 'Amazon Q should have generated code')
47+
assert(textAfter.length > textBefore.length, 'Amazon Q generated code')
4848
await textEditor.clearText()
4949
})
5050
})

packages/amazonq/test/e2e_new/amazonq/utils/generalUtils.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,34 @@ export async function writeToTextEditor(textEditor: TextEditor, text: string): P
164164
await textEditor.typeTextAt(currentLines, 1, text)
165165
}
166166

167+
/**
168+
* Waits for editor content to stabilize by checking if line count stops changing
169+
* @param editor The TextEditor instance
170+
* @param timeout Maximum time to wait in milliseconds (default: 15000)
171+
* @returns Promise<void>
172+
*/
173+
export async function waitForEditorStabilization(editor: TextEditor, timeout = 15000): Promise<void> {
174+
const startTime = Date.now()
175+
let previousLines = await editor.getNumberOfLines()
176+
let stableCount = 0
177+
178+
while (Date.now() - startTime < timeout) {
179+
await sleep(1000)
180+
const currentLines = await editor.getNumberOfLines()
181+
182+
if (currentLines === previousLines) {
183+
stableCount++
184+
if (stableCount >= 2) {
185+
return
186+
}
187+
} else {
188+
stableCount = 0
189+
}
190+
191+
previousLines = currentLines
192+
}
193+
}
194+
167195
/**
168196
* Finds an item based on the text
169197
* @param items WebElement array to search

0 commit comments

Comments
 (0)