Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(e2e): stabilize Amazon Q feature development tests #6520

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 () => {
chengoramazon marked this conversation as resolved.
Show resolved Hide resolved
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()
},
() => {
chengoramazon marked this conversation as resolved.
Show resolved Hide resolved
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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are the two tabs here and line 226 different? are they always different?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a new tab created when a /dev quick action triggered. The getSelectedTab can help get the current selected tab;

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
}
Comment on lines +108 to +116
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate more on why this is needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See reply above


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