Skip to content

Commit

Permalink
test(e2e): stabilize Amazon Q feature development tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chengoramazon committed Feb 7, 2025
1 parent ed87f5f commit 1129a44
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
42 changes: 23 additions & 19 deletions packages/amazonq/test/e2e/amazonq/featureDev.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@ import sinon from 'sinon'
import { registerAuthHook, using } from 'aws-core-vscode/test'
import { loginToIdC } from './utils/setup'
import { Messenger } from './framework/messenger'
import { examples } from 'aws-core-vscode/amazonqFeatureDev'
import { FollowUpTypes } from 'aws-core-vscode/amazonq'
import { sleep } from 'aws-core-vscode/shared'

describe('Amazon Q Feature Dev', function () {
let framework: qTestingFramework
let tab: Messenger

const prompt = 'Add blank.txt file with empty content'
const codegenApproachPrompt = `${prompt} and add a readme that describes the changes`
const fileLevelAcceptPrompt = `${prompt} and add a license, and a contributing file`
const prompt = 'Add current timestamp into blank.txt'
const iteratePrompt = `Add a new section in readme to explain your change`
const fileLevelAcceptPrompt = `${prompt} and ${iteratePrompt}`
const informationCard =
'After you provide a task, I will:\n1. Generate code based on your description and the code in your workspace\n2. Provide a list of suggestions for you to review and add to your workspace\n3. If needed, iterate based on your feedback\nTo learn more, visit the [user guide](https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/software-dev.html)'
const tooManyRequestsWaitTime = 100000

async function waitForText(text: string) {
Expand Down Expand Up @@ -144,34 +145,35 @@ describe('Amazon Q Feature Dev', function () {
})

describe('/dev entry', () => {
it('Clicks examples', async () => {
const q = framework.createTab()
q.addChatMessage({ command: '/dev' })
before(async () => {
tab = framework.createTab()
tab.addChatMessage({ command: '/dev' }) // This would create a new tab for feature dev.
tab = framework.getSelectedTab()
})

it('should display information card', async () => {
await retryIfRequired(
async () => {
await q.waitForChatFinishesLoading()
await tab.waitForChatFinishesLoading()
},
() => {
q.clickButton(FollowUpTypes.DevExamples)

const lastChatItems = q.getChatItems().pop()
assert.deepStrictEqual(lastChatItems?.body, examples)
const lastChatItems = tab.getChatItems().pop()
assert.deepStrictEqual(lastChatItems?.body, informationCard)
}
)
})
})

// Disable failing tests while investigation. The tests are only failing in CI environments.
describe.skip('/dev {msg} entry', async () => {
describe('/dev {msg} entry', async () => {
beforeEach(async function () {
tab = framework.createTab()
tab.addChatMessage({ command: '/dev', prompt })
tab = framework.getSelectedTab()
await retryIfRequired(
async () => {
await tab.waitForChatFinishesLoading()
},
() => {
tab.addChatMessage({ prompt })
}
() => {}
)
})

Expand Down Expand Up @@ -211,15 +213,17 @@ describe('Amazon Q Feature Dev', function () {
})
tab.clickButton(FollowUpTypes.ProvideFeedbackAndRegenerateCode)
await tab.waitForChatFinishesLoading()
await iterate(codegenApproachPrompt)
await iterate(iteratePrompt)
tab.clickButton(FollowUpTypes.InsertCode)
await tab.waitForButtons([FollowUpTypes.NewTask, FollowUpTypes.CloseSession])
})
})

describe.skip('file-level accepts', async () => {
describe('file-level accepts', async () => {
beforeEach(async function () {
tab = framework.createTab()
tab.addChatMessage({ command: '/dev', prompt: fileLevelAcceptPrompt })
tab = framework.getSelectedTab()
await retryIfRequired(
async () => {
await tab.waitForChatFinishesLoading()
Expand Down
10 changes: 10 additions & 0 deletions packages/amazonq/test/e2e/amazonq/framework/framework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ export class qTestingFramework {
return Object.entries(tabs).map(([tabId]) => new Messenger(tabId, this.mynahUIProps, this.mynahUI))
}

public getSelectedTab() {
const selectedTabId = this.mynahUI.getSelectedTabId()
const selectedTab = this.getTabs().find((tab) => tab.tabID === selectedTabId)

if (!selectedTab) {
assert.fail('Selected tab not found')
}
return selectedTab
}

public findTab(title: string) {
return Object.values(this.getTabs()).find((tab) => tab.getStore().tabTitle === title)
}
Expand Down

0 comments on commit 1129a44

Please sign in to comment.