Add automated testing infrastructure (Vitest + Playwright E2E) #110
No files matched your search
@@ -5,6 +5,9 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
unit:
|
unit:
|
||||||
|
# act_runner mounts /var/run/docker.sock into every container job, so a fork PR reaches
|
||||||
|
# the Docker daemon on the runner host. Both jobs need the same guard.
|
||||||
|
if: github.event.pull_request.head.repo.full_name == github.repository
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
@@ -28,8 +31,9 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
# Needs the DOCKER-USER exception on the runner host: ruv.wtf is a macvlan interface on a
|
# Needs the DOCKER-USER exception on the runner host: ruv.wtf is a macvlan interface on a
|
||||||
# container there, so the reply to a bridge-networked job arrives on that container's bridge
|
# container there, so the reply to a bridge-networked job arrives on that container's bridge
|
||||||
# and Docker's inter-bridge isolation drops it. act_runner ignores --network in
|
# and Docker's inter-bridge isolation drops it. The exception is host-wide, so it also covers
|
||||||
# container.options, so the exception lives on the host.
|
# fork PR jobs, and the bridge name is Docker-generated: recreating the caddy container
|
||||||
|
# renames it and the test fails closed.
|
||||||
env:
|
env:
|
||||||
# Dedicated test account on the homeserver, not a personal one.
|
# Dedicated test account on the homeserver, not a personal one.
|
||||||
E2E_HOMESERVER: ruv.wtf
|
E2E_HOMESERVER: ruv.wtf
|
||||||
@@ -56,18 +60,20 @@ jobs:
|
|||||||
working-directory: ./cinny
|
working-directory: ./cinny
|
||||||
run: npm ci --prefer-offline
|
run: npm ci --prefer-offline
|
||||||
|
|
||||||
# Electron needs system libraries the runner image does not ship.
|
# Electron needs system libraries the runner image does not ship. Chromium only:
|
||||||
|
# Electron uses the Chromium codebase, so firefox and webkit deps are not needed.
|
||||||
- name: Install system libraries for Electron
|
- name: Install system libraries for Electron
|
||||||
run: npx playwright install-deps
|
run: npx playwright install-deps chromium
|
||||||
|
|
||||||
# The runner image has no xvfb and no fresh apt lists.
|
# The runner image has no xvfb and no fresh apt lists.
|
||||||
- name: Ensure a display for Electron
|
- name: Ensure a display for Electron
|
||||||
run: command -v xvfb-run >/dev/null || (sudo apt-get update && sudo apt-get install -y xvfb)
|
run: command -v xvfb-run >/dev/null || (sudo apt-get update && sudo apt-get install -y xvfb)
|
||||||
|
|
||||||
# The login form only renders after the auth-flows request succeeds, so an
|
# The login form only renders after the auth-flows request succeeds, so an
|
||||||
# unreachable homeserver shows up as a 30s locator timeout. Fail fast instead.
|
# unreachable homeserver shows up as a 30s locator timeout. Fail fast instead, on
|
||||||
|
# connect failure or a non-2xx status.
|
||||||
- name: Homeserver reachable from the runner
|
- name: Homeserver reachable from the runner
|
||||||
run: curl -sS --max-time 20 -o /dev/null -w '%{http_code}\n' "https://$E2E_HOMESERVER/.well-known/matrix/client"
|
run: curl -sSf --max-time 20 -o /dev/null -w '%{http_code}\n' "https://$E2E_HOMESERVER/.well-known/matrix/client"
|
||||||
|
|
||||||
- name: Run login E2E
|
- name: Run login E2E
|
||||||
run: xvfb-run -a npm run test:e2e
|
run: xvfb-run -a npm run test:e2e
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ const PASSWORD = process.env.E2E_PASSWORD;
|
|||||||
let app;
|
let app;
|
||||||
let page;
|
let page;
|
||||||
let logs = [];
|
let logs = [];
|
||||||
|
let pageErrors = [];
|
||||||
let profile;
|
let profile;
|
||||||
|
|
||||||
// ServerPicker gives its input no name or test id, so position is the only handle on it;
|
// ServerPicker gives its input no name or test id, so position is the only handle on it;
|
||||||
@@ -30,6 +31,8 @@ async function chooseServer(server) {
|
|||||||
await serverInput().fill(server);
|
await serverInput().fill(server);
|
||||||
// The server field commits on Enter, which re-runs discovery and reloads the auth flows.
|
// The server field commits on Enter, which re-runs discovery and reloads the auth flows.
|
||||||
await serverInput().press('Enter');
|
await serverInput().press('Enter');
|
||||||
|
// fill() does not prove the value stuck; a cancelled debounce would keep matrix.org.
|
||||||
|
await expect(serverInput()).toHaveValue(server);
|
||||||
await expectLoginForm();
|
await expectLoginForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,6 +44,7 @@ async function submitLogin(username, password) {
|
|||||||
|
|
||||||
test.beforeEach(async () => {
|
test.beforeEach(async () => {
|
||||||
logs = [];
|
logs = [];
|
||||||
|
pageErrors = [];
|
||||||
|
|
||||||
if (!PASSWORD) {
|
if (!PASSWORD) {
|
||||||
throw new Error('E2E_PASSWORD is not set. Export it, or add it as the CI secret.');
|
throw new Error('E2E_PASSWORD is not set. Export it, or add it as the CI secret.');
|
||||||
@@ -60,12 +64,17 @@ test.beforeEach(async () => {
|
|||||||
?? await new Promise((resolve) => app.once('window', resolve));
|
?? await new Promise((resolve) => app.once('window', resolve));
|
||||||
}
|
}
|
||||||
page.on('console', (msg) => logs.push(`[renderer] ${msg.type()}: ${msg.text()}`));
|
page.on('console', (msg) => logs.push(`[renderer] ${msg.type()}: ${msg.text()}`));
|
||||||
|
page.on('pageerror', (err) => {
|
||||||
|
pageErrors.push(String(err));
|
||||||
|
logs.push(`[renderer] pageerror: ${err}`);
|
||||||
|
});
|
||||||
|
|
||||||
await chooseServer(HOMESERVER);
|
await chooseServer(HOMESERVER);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Config-based screenshots and traces do not fire for a page taken from app.firstWindow(),
|
// Config-based screenshots do not fire for a page taken from app.firstWindow(), and console
|
||||||
// and console capture is not covered by config at all, so this hook stays manual.
|
// capture is not covered by config at all, so this hook stays manual. Traces stay off because a
|
||||||
|
// trace captures the login POST body.
|
||||||
test.afterEach(async ({}, testInfo) => {
|
test.afterEach(async ({}, testInfo) => {
|
||||||
if (!app) return;
|
if (!app) return;
|
||||||
|
|
||||||
@@ -119,8 +128,9 @@ test('failed login reports an error without crashing the app', async () => {
|
|||||||
|
|
||||||
await expect(page.getByText('Invalid Username or Password.')).toBeVisible();
|
await expect(page.getByText('Invalid Username or Password.')).toBeVisible();
|
||||||
|
|
||||||
// The renderer is still alive and the form is still usable. No second login here: every
|
// "Without crashing" needs a liveness signal: no uncaught renderer error, form still usable.
|
||||||
// run costs Synapse rc_login budget, and the re-login was the main source of flakes.
|
// No second login here: every run costs Synapse rc_login budget, and the re-login was the
|
||||||
await expect(page.evaluate(() => document.body.innerText.trim())).not.toBe('');
|
// main source of flakes.
|
||||||
|
await expect(pageErrors).toHaveLength(0);
|
||||||
await expect(usernameInput()).toBeVisible();
|
await expect(usernameInput()).toBeVisible();
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user