Skip to content

Commit 3daefcd

Browse files
authored
Merge pull request #3215 from github/nora/add-e2e-tests
E2E test prototype
2 parents 0265bef + a6f7ee3 commit 3daefcd

13 files changed

Lines changed: 332 additions & 2 deletions

File tree

.github/workflows/e2e-tests.yml

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

.gitignore

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

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
@@ -1971,6 +1971,7 @@
19711971
"@faker-js/faker": "^8.0.2",
19721972
"@github/markdownlint-github": "^0.6.0",
19731973
"@octokit/plugin-throttling": "^8.0.0",
1974+
"@playwright/test": "^1.40.1",
19741975
"@storybook/addon-a11y": "^7.6.9",
19751976
"@storybook/addon-actions": "^7.1.0",
19761977
"@storybook/addon-essentials": "^7.1.0",

extensions/ql-vscode/scripts/find-deadcode.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ function ignoreFile(file: string): boolean {
1414
) ||
1515
basename(file) === "jest.config.ts" ||
1616
basename(file) === "index.tsx" ||
17-
basename(file) === "index.ts"
17+
basename(file) === "index.ts" ||
18+
basename(file) === "playwright.config.ts"
1819
);
1920
}
2021

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## VS Code CodeQL E2E Tests
2+
3+
When running the tests locally on a mac a different processor has to be emulated, which makes everythign VERY slow. Therefore we need to add higher timeouts in the test, so that they pass locally.
4+
5+
### How to use locally
6+
7+
Setup
8+
9+
- install playwright if you haven't yet (`npx playwright install`)
10+
- go to the e2e test folder on your terminal
11+
- make sure docker is running
12+
- run `docker-compose build`
13+
- run `docker-compose up`
14+
15+
Run tests
16+
17+
- run `npx playwright test --ui` from the e2e test folder to follow the test while it's running. This UI has a 'locator' tool with which elements on the test screen can be found
18+
- use `npx playwright test --debug` to follow the test in real time and interact with the interface, e.g. press enter or input into fields, stop and start
19+
20+
During the test elements are created in the docker volume, e.g. the downloaded database or query data. This might interfer with other tests or when running a test twice. If that happens restart your docker volume by using `docker-compose down -v` and `docker-compose up`. Sometimes already existing queries from former runs change the input the extension needs.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
version: "3.8"
2+
3+
services:
4+
code-server:
5+
build:
6+
context: docker
7+
dockerfile: Dockerfile
8+
platform: linux/amd64
9+
container_name: code-server
10+
user: "1000"
11+
volumes:
12+
- local-data:/home/coder/.local/share/code-server
13+
- local-user-data:/home/coder/.local/share/code-server/User
14+
- ./docker/config/config.yaml:/home/coder/.config/code-server/config.yaml
15+
- ./docker/User/settings.json:/home/coder/.local/share/code-server/User/settings.json
16+
- project-data:/home/coder/project
17+
ports:
18+
- 8080:8080
19+
restart: unless-stopped
20+
depends_on:
21+
code-server-init:
22+
condition: service_completed_successfully
23+
code-server-init:
24+
build:
25+
context: docker
26+
dockerfile: Dockerfile
27+
platform: linux/amd64
28+
user: "1000"
29+
volumes:
30+
- local-data:/home/coder/.local/share/code-server
31+
- local-user-data:/home/coder/.local/share/code-server/User
32+
- ./docker/config/config.yaml:/home/coder/.config/code-server/config.yaml
33+
- ./docker/User/settings.json:/home/coder/.local/share/code-server/User/settings.json
34+
- project-data:/home/coder/project
35+
entrypoint: |
36+
/usr/bin/entrypoint.sh --install-extension GitHub.vscode-codeql
37+
restart: "no"
38+
depends_on:
39+
- files-init
40+
files-init:
41+
image: alpine:3.19.0
42+
restart: "no"
43+
# Since we're not running the code-server container using the same user as our host user,
44+
# we need to set the permissions on the mounted volumes to match the user inside the container.
45+
entrypoint: |
46+
/bin/sh -c "chown 1000:1000 /home/coder/.local/share/code-server /home/coder/.local/share/code-server/User /home/coder/project"
47+
volumes:
48+
- local-data:/home/coder/.local/share/code-server
49+
- local-user-data:/home/coder/.local/share/code-server/User
50+
- project-data:/home/coder/project
51+
52+
volumes:
53+
local-data:
54+
local-user-data:
55+
project-data:
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM codercom/code-server:4.20.0
2+
3+
USER root
4+
5+
RUN apt-get update \
6+
&& apt-get install -y \
7+
unzip \
8+
&& rm -rf /var/lib/apt/lists/*
9+
10+
RUN wget -q -O /tmp/codeql.zip https://github.com/github/codeql-cli-binaries/releases/download/v2.15.5/codeql-linux64.zip \
11+
&& unzip -q /tmp/codeql.zip -d /opt \
12+
&& rm -rf /tmp/codeql.zip
13+
14+
ENV PATH="/opt/codeql:${PATH}"
15+
16+
USER 1000
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"workbench.startupEditor": "none",
3+
"security.workspace.trust.enabled": false,
4+
"codeQL.cli.executablePath": "/opt/codeql/codeql",
5+
"codeQL.telemetry.enableTelemetry": false
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
bind-addr: 127.0.0.1:8080
2+
auth: none
3+
cert: false
4+
disable-workspace-trust: true
5+
disable-telemetry: true
6+
disable-update-check: true

0 commit comments

Comments
 (0)