Skip to content

Commit c7a1cf7

Browse files
committed
Add test, config and action
1 parent 38743c6 commit c7a1cf7

8 files changed

Lines changed: 270 additions & 1 deletion

File tree

.github/workflows/e2e-tests.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Run E2E Playwright tests
2+
on:
3+
push:
4+
5+
jobs:
6+
e2e-test:
7+
name: E2E Test
8+
runs-on: ubuntu-latest
9+
timeout-minutes: 30
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v4
13+
14+
- uses: actions/setup-node@v4
15+
with:
16+
node-version-file: extensions/ql-vscode/.nvmrc
17+
cache: 'npm'
18+
cache-dependency-path: extensions/ql-vscode/package-lock.json
19+
20+
- name: Install dependencies
21+
working-directory: extensions/ql-vscode
22+
run: npm ci
23+
24+
- name: Start containers
25+
working-directory: extensions/ql-vscode/test/e2e
26+
run: docker-compose -f "docker-compose.yml" up -d --build
27+
28+
- name: Install Playwright Browsers
29+
working-directory: extensions/ql-vscode
30+
run: npx playwright install --with-deps
31+
- name: Run Playwright tests
32+
working-directory: extensions/ql-vscode
33+
run: npx playwright test
34+
- uses: actions/upload-artifact@v4
35+
if: always()
36+
with:
37+
name: playwright-report
38+
path: extension/ql-vscode/playwright-report/
39+
retention-days: 30
40+
- name: Stop containers
41+
working-directory: extensions/ql-vscode/test/e2e
42+
if: always()
43+
run: docker-compose -f "docker-compose.yml" down -v

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ artifacts/
1919
# CodeQL metadata
2020
.cache/
2121
.codeql/
22+
23+
# E2E Reports
24+
**/playwright-report/**

extensions/ql-vscode/package-lock.json

Lines changed: 60 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extensions/ql-vscode/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,6 +1952,7 @@
19521952
"@faker-js/faker": "^8.0.2",
19531953
"@github/markdownlint-github": "^0.6.0",
19541954
"@octokit/plugin-throttling": "^8.0.0",
1955+
"@playwright/test": "^1.40.1",
19551956
"@storybook/addon-a11y": "^7.4.6",
19561957
"@storybook/addon-actions": "^7.1.0",
19571958
"@storybook/addon-essentials": "^7.1.0",
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import { defineConfig, devices } from "@playwright/test";
2+
3+
/**
4+
* Read environment variables from file.
5+
* https://github.com/motdotla/dotenv
6+
*/
7+
// require('dotenv').config();
8+
9+
/**
10+
* See https://playwright.dev/docs/test-configuration.
11+
*/
12+
export default defineConfig({
13+
testDir: "./test/e2e",
14+
15+
timeout: 5 * 60 * 1000,
16+
/* Run tests in files in parallel */
17+
fullyParallel: true,
18+
/* Fail the build on CI if you accidentally left test.only in the source code. */
19+
forbidOnly: !!process.env.CI,
20+
/* Retry on CI only */
21+
retries: process.env.CI ? 2 : 0,
22+
/* Opt out of parallel tests on CI. */
23+
workers: process.env.CI ? 1 : undefined,
24+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
25+
reporter: "html",
26+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
27+
use: {
28+
/* Base URL to use in actions like `await page.goto('/')`. */
29+
// baseURL: 'http://127.0.0.1:3000',
30+
31+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
32+
trace: "on-first-retry",
33+
},
34+
35+
/* Configure projects for major browsers */
36+
projects: [
37+
{
38+
name: "chromium",
39+
use: { ...devices["Desktop Chrome"] },
40+
},
41+
42+
// {
43+
// name: "firefox",
44+
// use: { ...devices["Desktop Firefox"] },
45+
// },
46+
47+
// {
48+
// name: "webkit",
49+
// use: { ...devices["Desktop Safari"] },
50+
// },
51+
52+
/* Test against mobile viewports. */
53+
// {
54+
// name: 'Mobile Chrome',
55+
// use: { ...devices['Pixel 5'] },
56+
// },
57+
// {
58+
// name: 'Mobile Safari',
59+
// use: { ...devices['iPhone 12'] },
60+
// },
61+
62+
/* Test against branded browsers. */
63+
// {
64+
// name: 'Microsoft Edge',
65+
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
66+
// },
67+
// {
68+
// name: 'Google Chrome',
69+
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
70+
// },
71+
],
72+
73+
/* Run your local dev server before starting the tests */
74+
// webServer: {
75+
// command: 'npm run start',
76+
// url: 'http://127.0.0.1:3000',
77+
// reuseExistingServer: !process.env.CI,
78+
// },
79+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## VS Code CodeQL E2E Tests
2+
3+
### Set up
4+
5+
- run `docker-compose build` from the e2e test folder `vscode-codeql/extensions/ql-vscode/test/e2e`
6+
- run `docker-compose up` from the e2e test folder `vscode-codeql/extensions/ql-vscode/test/e2e`
7+
- run `npx playwright test --ui` from the vscode-codeql folder `vscode-codeql/extensions/ql-vscode`
8+
9+
When you've run the test once! remove the volume data, e.g. by running `docker-compose down -v`
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"workbench.startupEditor": "none",
33
"security.workspace.trust.enabled": false,
4-
"codeQL.cli.executablePath": "/opt/codeql/codeql"
4+
"codeQL.cli.executablePath": "/opt/codeql/codeql",
5+
"codeQL.telemetry.enableTelemetry": false
56
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { test, expect } from "@playwright/test";
2+
3+
test("run query and open it from history", async ({ page }) => {
4+
await page.goto("http://localhost:8080/?folder=/home/coder/project");
5+
6+
await page.getByRole("tab", { name: "CodeQL" }).locator("a").click();
7+
8+
// decline extension telemetry
9+
await page.getByRole("button", { name: "No", exact: true }).click({
10+
timeout: 60000,
11+
});
12+
13+
await page.keyboard.press("Control+Shift+P");
14+
await page.keyboard.type("Create Query");
15+
await page.keyboard.press("Enter");
16+
17+
await page.getByLabel("JavaScript, javascript").locator("a").click({
18+
timeout: 60000,
19+
});
20+
21+
// select folder for first query
22+
await page
23+
.getByText(
24+
"Results0 SelectedPress 'Enter' to confirm your input or 'Escape' to cancelOK",
25+
)
26+
.press("Enter");
27+
28+
// Download database
29+
await page
30+
.getByRole("button", { name: "Download database" })
31+
.click({ timeout: 60000 });
32+
await page.getByPlaceholder("https://github.com/<owner>/<").press("Enter");
33+
await page
34+
.locator("#list_id_3_0")
35+
.getByText("javascript")
36+
.click({ timeout: 60000 });
37+
38+
await page.keyboard.press("Control+Shift+P");
39+
await page.keyboard.type("Run Query on selected");
40+
await page.keyboard.press("Enter");
41+
42+
// select folder for first query run
43+
// await page.getByRole("button", { name: "OK" }).click();
44+
45+
// check that query was run successfully and results page opens
46+
await page.getByText("Hello world on d3/d3").click({ timeout: 800000 });
47+
48+
// close results page and open query from history
49+
await page
50+
.getByLabel("CodeQL Query Results, Editor Group")
51+
.getByLabel("Close (Ctrl+F4)")
52+
.click();
53+
await expect(
54+
page
55+
.frameLocator(".webview")
56+
.frameLocator('iframe[title="CodeQL Query Results"]')
57+
.getByText("#selectalerts32 resultsShow"),
58+
).not.toBeVisible();
59+
60+
await page
61+
.locator("#list_id_6_0")
62+
.getByLabel("Hello world on d3/d3 -")
63+
.locator("div")
64+
.first()
65+
.click();
66+
67+
await expect(
68+
page
69+
.frameLocator('iframe[name="\\34 884429a-d667-4121-932e-99abaa20b599"]')
70+
.frameLocator('iframe[title="CodeQL Query Results"]')
71+
.getByText("#selectalerts32 resultsShow"),
72+
).not.toBeVisible();
73+
});

0 commit comments

Comments
 (0)