Skip to content

Add back variant analysis tests#2162

Merged
aeisenberg merged 2 commits intomainfrom
aeisenberg/variant-analysis-tests
Mar 13, 2023
Merged

Add back variant analysis tests#2162
aeisenberg merged 2 commits intomainfrom
aeisenberg/variant-analysis-tests

Conversation

@aeisenberg
Copy link
Copy Markdown
Contributor

This commit adds back the variant analysis tests that were inadvertently deleted after this commit

it('should run a remote query that is part of a qlpack', async () => {

They are not identical to the removed tests. I refactored them so that there is a single test function invoked three times with different parameters.

Replace this with a description of the changes your pull request makes.

Checklist

  • CHANGELOG.md has been updated to incorporate all user visible changes made by this pull request.
  • Issues have been created for any UI or other user-facing changes made by this pull request.
  • [Maintainers only] If this pull request makes user-facing changes that require documentation changes, open a corresponding docs pull request in the github/codeql repo and add the ready-for-doc-review label there.

@aeisenberg aeisenberg requested a review from a team as a code owner March 9, 2023 23:49
@aeisenberg aeisenberg changed the base branch from main to aeisenberg/run-with-all-data-extensions March 9, 2023 23:52
This commit adds back the variant analysis tests that were inadvertently
deleted after this commit

https://github.com/github/vscode-codeql/blob/82ada54103f591228d9c61ac6b3c93c85d6ffd1c/extensions/ql-vscode/src/vscode-tests/cli-integration/remote-queries/run-remote-query.test.ts#L67

They are not identical to the removed tests. I refactored them so that
there is a single test function invoked three times with different
parameters.
@aeisenberg aeisenberg force-pushed the aeisenberg/variant-analysis-tests branch from e2b7e03 to baba68d Compare March 9, 2023 23:53
Copy link
Copy Markdown
Member

@koesie10 koesie10 left a comment

Choose a reason for hiding this comment

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

Thanks for working on this!

qlxFilesThatExist: string[];
filesThatDoNotExist: string[];
}) {
const fileUri = getFile(queryPath);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The getFile function only seems to be used here, so would this make it clearer?

Suggested change
const fileUri = getFile(queryPath);
const fileUri = Uri.file(join(baseDir, queryPath));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is used throughout the test file.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah, sorry, I only checked the diff, I missed that it's also used by the existing tests.

const packFileName = packFS.fileExists("qlpack.yml")
? "qlpack.yml"
: "codeql-pack.yml";
const qlpackContents: any = load(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need these any type annotations or is there a reason you've added them?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was from the previous tests. I can see if I can get rid of them.

});
});

async function doVariantAnalysisTest({
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

An alternative for creating a function for this would be to use it.each. That would avoid the need to create a function, which might make the tests easier to read (since all expectations are located within the it).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This might work, but I'll have to see since in a follow-up PR I'm adding a new test that requires a bit of work before running the assertions.

Actually...I think I can get this done by passing in a closure that can be invoked at the start of the .each function.

Copy link
Copy Markdown
Contributor Author

@aeisenberg aeisenberg Mar 10, 2023

Choose a reason for hiding this comment

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

Hmmmm...I don't think this is a great approach:

  1. it prevents you from adding custom names for each test
  2. it is more cumbersome to run individual tests since it doesn't play nicely with the jest extension for vscode

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's totally fine to not do it, it was just something we might be able to try. Both look like valid points, so let's just keep it like this for now.

}) {
const fileUri = getFile(queryPath);

await variantAnalysisManager.runVariantAnalysis(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since this is testing the query pack generation instead of specifically the variant analysis, would it make sense to make these tests of a new test suite for run-remote-query.ts which tests the prepareRemoteQueryRun function? I think that makes the test easier since you don't need to mock anything, although you'll lose some of the end-to-end testing that we're doing now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I started going down this path, but setting up the parameters for prepareRemoteQueryRun is no simpler than using the variantAnalysisManager already existing. Since the tests are already set up for this, we can keep things simpler by reusing existing test infrastructure.

Base automatically changed from aeisenberg/run-with-all-data-extensions to main March 10, 2023 16:09
@aeisenberg
Copy link
Copy Markdown
Contributor Author

Thanks for your review. It's ready for another look.

@aeisenberg aeisenberg requested a review from koesie10 March 10, 2023 19:12
@aeisenberg aeisenberg merged commit 205327d into main Mar 13, 2023
@aeisenberg aeisenberg deleted the aeisenberg/variant-analysis-tests branch March 13, 2023 14:37
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.

2 participants