Skip to content

Commit 68a4075

Browse files
committed
remove redundant logic and add more waituntil
1 parent e94d658 commit 68a4075

File tree

1 file changed

+32
-26
lines changed

1 file changed

+32
-26
lines changed

packages/amazonq/test/e2e/amazonq/review.test.ts

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,7 @@ import { ScanAction, scanProgressMessage } from '../../../src/app/amazonqScan/mo
2424
import { CodeScanIssue } from 'aws-core-vscode/codewhisperer'
2525
import { SecurityIssueProvider } from 'aws-core-vscode/codewhisperer'
2626

27-
async function pollForResult<T>(
28-
conditionFn: () => T | undefined,
29-
timeoutMs: number = 60000,
30-
intervalMs: number = 500
31-
): Promise<T | undefined> {
32-
const startTime = Date.now()
33-
34-
while (Date.now() - startTime < timeoutMs) {
35-
const result = conditionFn()
36-
if (result !== undefined) {
37-
return result
38-
}
39-
await new Promise((resolve) => setTimeout(resolve, intervalMs))
40-
}
41-
42-
return undefined
43-
}
27+
import { waitUntil } from 'aws-core-vscode/shared'
4428

4529
function getWorkspaceFolder(): string {
4630
return vscode.workspace.workspaceFolders![0].uri.fsPath
@@ -259,8 +243,8 @@ describe('Amazon Q Code Review', function () {
259243
}
260244

261245
// Wait for the webview panel to open with polling
262-
const webviewPanel = await pollForResult<vscode.WebviewPanel>(
263-
() => {
246+
const webviewPanel = await waitUntil(
247+
async () => {
264248
const panels = vscode.window.tabGroups.all
265249
.flatMap((group) => group.tabs)
266250
.filter((tab) => tab.label === amazonqCodeIssueDetailsTabTitle)
@@ -269,19 +253,38 @@ describe('Amazon Q Code Review', function () {
269253

270254
return panels.length > 0 ? panels[0] : undefined
271255
},
272-
20_000,
273-
1000
256+
{
257+
timeout: 20_000,
258+
interval: 1000,
259+
truthy: false,
260+
}
274261
)
275262

276263
assert.ok(webviewPanel, 'Security issue webview panel did not open after waiting')
277264

278-
const issue = viewDetailsAction.command?.arguments?.[0] as CodeScanIssue
265+
// Wait until viewDetailsAction.command is defined
266+
const viewDetailsActionDefined = await waitUntil(
267+
async () => {
268+
return viewDetailsAction.command?.arguments !== undefined
269+
? viewDetailsAction.command
270+
: undefined
271+
},
272+
{
273+
timeout: 10_000,
274+
interval: 500,
275+
truthy: false,
276+
}
277+
)
278+
279+
assert.ok(viewDetailsActionDefined, 'viewDetailsAction.command was not defined after waiting')
280+
281+
const issue = viewDetailsActionDefined.arguments?.[0] as CodeScanIssue
279282
console.log('command', viewDetailsAction.command)
280283
console.log('arguments', viewDetailsAction.command?.arguments)
281284

282285
// Wait for the fix to be generated with polling
283-
const updatedIssue = await pollForResult<CodeScanIssue>(
284-
() => {
286+
const updatedIssue = await waitUntil(
287+
async () => {
285288
const foundIssue = SecurityIssueProvider.instance.issues
286289
.flatMap(({ issues }) => issues)
287290
.find((i) => i.findingId === issue.findingId)
@@ -293,8 +296,11 @@ describe('Amazon Q Code Review', function () {
293296
? foundIssue
294297
: undefined
295298
},
296-
CodeWhispererConstants.codeFixJobTimeoutMs,
297-
CodeWhispererConstants.codeFixJobPollingIntervalMs
299+
{
300+
timeout: CodeWhispererConstants.codeFixJobTimeoutMs,
301+
interval: CodeWhispererConstants.codeFixJobPollingIntervalMs,
302+
truthy: false,
303+
}
298304
)
299305

300306
// Verify the fix was generated by checking if the issue has suggestedFixes

0 commit comments

Comments
 (0)