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(amazonq): E2E tests for /test #6431

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

chungjac
Copy link
Contributor

Problem

  • There are currently no E2E tests for /test

Solution

  • Created E2E tests for /test: view diff, accept, reject, unsupported language, external file

  • 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.
  • License: I confirm that my contribution is made under the terms of the Apache 2.0 license.

@chungjac chungjac requested a review from a team as a code owner January 24, 2025 20:05
@justinmk3
Copy link
Contributor

/runintegrationtests

*
* @returns `TextDocument`, or undefined if the file could not be found.
*/
export async function openDocument(filePath: string): Promise<vscode.TextDocument | undefined> {
Copy link
Contributor

@justinmk3 justinmk3 Jan 24, 2025

Choose a reason for hiding this comment

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

i'm certain there are similar functions in one of the util modules, can they be used instead? if not, then this new function should live one of the shared modules, not deep in a test-only, q-only subfolder.

Copy link
Contributor

@tomcat323 tomcat323 Jan 24, 2025

Choose a reason for hiding this comment

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

We have functions that does the same with an uri, so maybe this can work:

const document = await vscode.workspace.openTextDocument(vscode.Uri.file(filePath))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I will look into this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've removed the helper since:

  • it was only being called twice
  • future language test additions will be handled within existing loop

After testing, I found that using vscode.workspace.findFiles() and its proceeding logic was the most reliable in opening the file for testing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I definitely wasn't suggesting to inline the retry logic into the tests. My suggestion was to lift the util function into /shared/.

I've removed the helper since:

it was only being called twice
future language test additions will be handled within existing loop

you mean for these particular tests. but if opening files is unreliable, then surely we need that logic in all tests that open files. again, we already have existing functions that do this:

export async function openTextDocument(filenameGlob: vscode.GlobPattern): Promise<vscode.TextDocument | undefined> {

You could update that existing function to (1) use findFiles() and (2) to use waitUntil, to make it (optionally) more reliable.

The point of adding tests is to improve system reliability. Sharing code also improves system reliability. Copy-pasting code everywhere means that some code will just have hidden bugs.

Copy link
Contributor Author

@chungjac chungjac Jan 28, 2025

Choose a reason for hiding this comment

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

Gotcha, I just updated to use the openTextDocument() function from the aws-core-vscode/shared module. At first, I didn't realize to use this, so I tried making my own helper. The pre-existing helper works well and is reliable. Let me know if I should clarify anything else

@chungjac chungjac requested a review from a team January 24, 2025 23:45
@chungjac chungjac enabled auto-merge January 25, 2025 00:22
@chungjac chungjac requested a review from justinmk3 January 25, 2025 00:26
})

describe('Unsupported language', () => {
const { language, filePath } = unsupportedLanguages[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

just curious why we are only checking the first element?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just want to check that for an unsupported language (no specific one in particular), it will redirect to the chat.

So whatever the first language in unsupportedLanguages array will be used

Comment on lines +217 to +218
tab.addChatMessage({ command: '/test' })
await tab.waitForChatFinishesLoading()
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: looks like all tests do this, can it be added to before()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It can definitely be added to beforeEach(). Although I feel that since the beforeEach() is already responsible for opening an active file, it might just become more bloated. If someone in the future looks at the test I feel it would be easier if it is called in each test individually. Let me know what you think

@chungjac chungjac requested a review from ctlai95 January 27, 2025 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants