Apply the #109 re-review: crash assertion, artifact hook on launch failure, dropped redundant lines. (#109)
Tests / unit (pull_request) Successful in 17s
Tests / e2e (pull_request) Successful in 4m10s

tests/e2e/login.spec.mjs: assert the render process is alive with the `crash`
event instead of counting pageerrors; the failed-login test now accepts the
rate-limited message as well as the wrong-password one; the failure hook
attaches the console before the app guard so a launch failure still produces an
artifact, wraps `screenshot()` because it throws on a crashed page, and reaches
`fs.rmSync` on launch failure; dropped the duplicate login-form assertion.

playwright.config.mjs: pin `trace: 'off'` explicitly rather than relying on the
version default, since a trace captures the login POST body.

.gitea/workflows/tests.yml: dropped `--prefer-offline`; corrected the xvfb
comment (the guard is live for the host runner, which already has xvfb); dropped
an unresolvable CI run-number citation.

Checks: `node --check` on both JS files, `npm run test:unit` — 2 passed. E2E
cannot be run locally (no `E2E_PASSWORD` in this session); CI is the check.
This commit is contained in:
2026-11-03 13:22:39 +11:00
parent 347acd0ebd
commit 1ddca42473
3 changed files with 41 additions and 25 deletions
+31 -21
View File
@@ -11,6 +11,7 @@ let app;
let page;
let logs = [];
let profile;
let crashed = false;
// ServerPicker gives its input no name or test id, so position is the only handle on it;
// this breaks if the form ever gains a field before the ones below.
@@ -43,6 +44,7 @@ async function submitLogin(username, password) {
test.beforeEach(async () => {
logs = [];
crashed = false;
if (!PASSWORD) {
throw new Error('E2E_PASSWORD is not set. Export it, or add it as the CI secret.');
@@ -63,29 +65,37 @@ test.beforeEach(async () => {
}
page.on('console', (msg) => logs.push(`[renderer] ${msg.type()}: ${msg.text()}`));
page.on('pageerror', (err) => logs.push(`[renderer] pageerror: ${err}`));
// crash is render-process-gone, so it does not fire on the MatrixError or the ServiceWorker error.
page.on('crash', () => {
crashed = true;
});
await chooseServer(HOMESERVER);
});
// Config-based screenshots do not fire for a page taken from app.firstWindow(), and console
// capture is not covered by config at all, so this hook stays manual. Traces stay off because a
// trace captures the login POST body.
// capture is not covered by config at all, so this hook stays manual.
test.afterEach(async ({}, testInfo) => {
if (!app) return;
if (testInfo.status !== testInfo.expectedStatus) {
if (page && !page.isClosed()) {
await testInfo.attach('failure.png', { body: await page.screenshot(), contentType: 'image/png' });
}
// Console first: a failed launch has no app and no page, so this is the only artifact that
// path can produce.
await testInfo.attach('console.log', { body: logs.join('\n'), contentType: 'text/plain' });
if (page && !page.isClosed()) {
// screenshot() throws on a crashed page, which would mask the original failure.
const shot = await page.screenshot().catch(() => null);
if (shot) await testInfo.attach('failure.png', { body: shot, contentType: 'image/png' });
}
}
await app
.close()
// main.js preventDefault()s window close to minimise to tray, so close can hang.
.catch(() => app.process().kill('SIGTERM'));
if (app) {
await app
.close()
// main.js preventDefault()s window close to minimise to tray, so close can hang.
.catch(() => app.process().kill('SIGTERM'));
}
fs.rmSync(profile, { recursive: true, force: true });
// Reachable on launch failure, so the temp profile does not leak.
if (profile) fs.rmSync(profile, { recursive: true, force: true });
});
async function expectAuthenticated() {
@@ -108,9 +118,6 @@ async function expectAuthenticated() {
return res.status;
})
.toBe(200);
// The login form is gone, so the app is on the authenticated shell.
await expect(usernameInput()).toHaveCount(0);
}
test('test account can log in and reaches the authenticated app', async () => {
@@ -118,14 +125,17 @@ test('test account can log in and reaches the authenticated app', async () => {
await expectAuthenticated();
});
test('failed login reports an error without crashing the app', async () => {
test('failed login reports an error and keeps the renderer alive', async () => {
await submitLogin(USER, 'not-the-password');
await expect(page.getByText('Invalid Username or Password.')).toBeVisible();
// A rate-limited run renders LoginError.RateLimited instead of the wrong-password message,
// so accept both branches rather than asserting one exact string.
await expect(page.getByText(/Invalid Username or Password\.|rate-limited by server/)).toBeVisible();
// "Without crashing" is proven by the form still rendering: a dead renderer cannot render it.
// Pageerrors go into the artifact but are not asserted — the failed login itself produces
// MatrixError, and dev mode produces a ServiceWorker registration error. No second login
// here: every run costs Synapse rc_login budget, and the re-login was the main flake source.
// A dead renderer cannot render the form. Pageerrors go into the artifact but are not
// asserted — the failed login itself produces MatrixError, and dev mode produces a
// ServiceWorker registration error. No second login here: every run costs Synapse rc_login
// budget, and the re-login was the main flake source.
await expect(usernameInput()).toBeVisible();
await expect(crashed).toBe(false);
});