Skip to content

Commit 4080c31

Browse files
authored
fix(amazonq): Inline test after function addition, writeToTextEditor fix, and package.json pathing fix (#7800)
## Problem The inline test cannot be run consecutively with other tests in our suite since it switches its focus to the editorView and textEditorView. Each time the inline test is run, a new driver was launched with caused a new VSCode instance to instantiate. The `package.json` should only target the `.test.js` files. Right now it targets all .js files in the directory. The `writeToTextEditor` function is faulty since it is wrongly indexed due to its element not being accessed before counting and referencing its indices within code. ## Solution Implemented an `after` function which correctly switches back to our webviewView (AmazonQ). Added the true inline test into the suite and fixed driver problem. Changed the path referenced in the `package.json` to `.test.js` files. Fixed the `writeToTextEditor` function such that it includes a "dummy" space input into the textEditor and then counts the number of indices of lines. This then writes the desired text within the correct line without problems. --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 5d8706e commit 4080c31

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"testE2E": "npm run testE2E -w packages/ --if-present",
3131
"test:ui:prepare": "./node_modules/.bin/extest get-vscode -s ~/.vscode-test-resources -n && extest get-chromedriver -s ~/.vscode-test-resources -n",
3232
"test:ui:install": "cd packages/amazonq && npm run package 2>&1 | grep -o 'VSIX Version: [^ ]*' | cut -d' ' -f3 | xargs -I{} bash -c 'cd ../../ && ./node_modules/.bin/extest install-vsix -f amazon-q-vscode-{}.vsix -e packages/amazonq/test/e2e_new/amazonq/resources -s ~/.vscode-test-resources'",
33-
"test:ui:run": "npm run testCompile && ./node_modules/.bin/extest run-tests -s ~/.vscode-test-resources -e packages/amazonq/test/e2e_new/amazonq/resources packages/amazonq/dist/test/e2e_new/amazonq/tests/*.js",
33+
"test:ui:run": "npm run testCompile && ./node_modules/.bin/extest run-tests -s ~/.vscode-test-resources -e packages/amazonq/test/e2e_new/amazonq/resources packages/amazonq/dist/test/e2e_new/amazonq/tests/*.test.js",
3434
"test:ui": "npm run test:ui:prepare && npm run test:ui:install && npm run test:ui:run",
3535
"testInteg": "npm run testInteg -w packages/ --if-present",
3636
"package": "npm run package -w packages/toolkit -w packages/amazonq",

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

Lines changed: 17 additions & 11 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 { pressKey, createNewTextFile, writeToTextEditor } from '../utils/generalUtils'
8+
import { createNewTextFile, writeToTextEditor, sleep } from '../utils/generalUtils'
99
import assert from 'assert'
1010

1111
describe('Amazon Q Inline Completion / Chat Functionality', function () {
@@ -20,25 +20,31 @@ describe('Amazon Q Inline Completion / Chat Functionality', function () {
2020
webviewView = testContext.webviewView
2121
await webviewView.switchBack()
2222
workbench = testContext.workbench
23-
2423
editorView = new EditorView()
2524
testContext.editorView = editorView
26-
2725
textEditor = await createNewTextFile(workbench, editorView)
2826
})
29-
30-
it('Inline Test', async () => {
31-
await writeToTextEditor(textEditor, 'Select Me')
27+
after(async function () {
28+
// Switch back to Webview Iframe when dealing with external webviews from Amazon Q.
29+
await editorView.closeAllEditors()
30+
await webviewView.switchToFrame()
31+
})
32+
it('Inline Test Shortcut', async () => {
33+
await writeToTextEditor(textEditor, 'def factorial(n):')
3234
const text = await textEditor.getText()
33-
assert.equal(text, 'Select Me')
35+
assert.equal(text, 'def factorial(n): ')
3436
await textEditor.clearText()
3537

38+
const textBefore = await textEditor.getText()
3639
await workbench.executeCommand('Amazon Q: Inline Chat')
3740
const input = new InputBox()
38-
await input.sendKeys('Write a simple sentece')
41+
await input.sendKeys('Generate the fibonacci sequence through iteration')
3942
await input.sendKeys(Key.ENTER)
40-
const driver = textEditor.getDriver()
41-
await pressKey(driver, 'ENTER')
42-
await pressKey(driver, 'TAB')
43+
// Must wait for response to be generated.
44+
await sleep(8000)
45+
46+
const textAfter = await textEditor.getText()
47+
assert(textAfter.length > textBefore.length, 'Amazon Q should have generated code')
48+
await textEditor.clearText()
4349
})
4450
})

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,11 @@ export async function createNewTextFile(workbench: Workbench, editorView: Editor
157157
* @returns Promise<void>
158158
*/
159159
export async function writeToTextEditor(textEditor: TextEditor, text: string): Promise<void> {
160+
// We require a "dummy" space to be written such that we can properly index the
161+
// number of lines to register the textEditor.
162+
await textEditor.typeTextAt(1, 1, ' ')
160163
const currentLines = await textEditor.getNumberOfLines()
161-
const nextLine = currentLines + 1
162-
await textEditor.typeTextAt(nextLine, 1, text)
164+
await textEditor.typeTextAt(currentLines, 1, text)
163165
}
164166

165167
/**

0 commit comments

Comments
 (0)