| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [View Raw Code] [Original HTTPS Page] |
We have several types of tests:
The CLI integration tests require an instance of the CodeQL CLI to run so they will require some extra setup steps. When adding new tests to our test suite, please be mindful of whether they need to be in the cli-integration folder. If the tests don't depend on the CLI, they are better suited to being a VSCode integration test.
Any test data you're using (sample projects, config files, etc.) must go in a test/vscode-tests/*/data directory. When you run the tests, the test runner will copy the data directory to out/vscode-tests/*/data.
Pre-requisites:
Then, from the extensions/ql-vscode directory, use the appropriate command to run the tests:
The CLI integration tests require the CodeQL standard libraries in order to run so you will need to clone a local copy of the github/codeql repository.
Set the TEST_CODEQL_PATH environment variable: running from a terminal, you must set the TEST_CODEQL_PATH variable to point to a checkout of the github/codeql repository. The appropriate CLI version will be downloaded as part of the test.
Run your test command:
cd extensions/ql-vscode && npm run test:cli-integrationAlternatively, you can run the tests inside of VSCode. There are several VSCode launch configurations defined that run the unit and integration tests.
You will need to run tests using a task from inside of VS Code, under the "Run and Debug" view:
The CLI integration tests require the CodeQL standard libraries in order to run so you will need to clone a local copy of the github/codeql repository.
Set the TEST_CODEQL_PATH environment variable: running from a terminal, you must set the TEST_CODEQL_PATH variable to point to a checkout of the github/codeql repository. The appropriate CLI version will be downloaded as part of the test.
Set the codeql path in VSCode's launch configuration: open launch.json and under the Launch Integration Tests - With CLI section, uncomment the "${workspaceRoot}/../codeql" line. If you've cloned the github/codeql repo to a different path, replace the value with the correct path.
Run the VSCode task from the "Run and Debug" view called Launch Integration Tests - With CLI.
The easiest way to run a single test is to change the it of the test to it.only and then run the test command with some additional options to only run tests for this specific file. For example, to run the test test/vscode-tests/cli-integration/run-queries.test.ts:
npm run test:cli-integration -- --runTestsByPath test/vscode-tests/cli-integration/run-queries.test.tsYou can also use the --testNamePattern option to run a specific test within a file. For example, to run the test test/vscode-tests/cli-integration/run-queries.test.ts:
npm run test:cli-integration -- --runTestsByPath test/vscode-tests/cli-integration/run-queries.test.ts --testNamePattern "should create a QueryEvaluationInfo"Alternatively, you can run a single test inside VSCode. To do so, install the Jest Runner extension. Then, you will have quicklinks to run a single test from within test files. To run a single unit or integration test, click the "Run" button. Debugging a single test is currently only supported for unit tests by default. To debug integration tests, open the .vscode/settings.json file and uncomment the jestrunner.debugOptions lines. This will allow you to debug integration tests. Please make sure to revert this change before committing; with this setting enabled, it is not possible to debug unit tests.
Without the Jest Runner extension, you can also use the "Launch Selected Unit Test (vscode-codeql)" launch configuration to run a single unit test.
Multi-Repo Variant Analyses (MRVA) rely on the GitHub API. In order to make development and testing easy, we have functionality that allows us to intercept requests to the GitHub API and provide mock responses.
To run a mock MRVA scenario, follow these steps:
"codeQL.mockGitHubApiServer": {
"enabled": true
}If you want to replay the same scenario you should unload and reload it so requests are replayed from the start.
To record a new mock MRVA scenario, follow these steps:
"codeQL.mockGitHubApiServer": {
"enabled": true
}If you want to cancel recording, run the CodeQL: Mock GitHub API Server: Cancel Scenario Recording command.
Once the scenario has been recorded, it's often useful to remove some of the requests to speed up the replay, particularly ones that fetch the variant analysis status. Once some of the request files have manually been removed, the fix-scenario-file-numbering script can be used to update the number of the files. See the script file for details on how to use.
Pre-recorded scenarios are stored in ./src/common/mock-gh-api/scenarios. However, it's possible to configure the location, by setting the codeQL.mockGitHubApiServer.scenariosPath configuration property in the VS Code user settings.
| Back | FazBrowse Home | New Git URL |