mirror of
https://github.com/go-gitea/gitea.git
synced 2026-02-21 17:58:48 +01:00
- Replace the e2e tests initialization with a simple bash script, removing the previous Go harness. - `make test-e2e` is the single entry point. It always starts a fully isolated ephemeral Gitea instance with its own temp directory, SQLite database, and config — no interference with the developer's running instance. - A separate `gitea-e2e` binary is built via `EXECUTABLE_E2E` using `TEST_TAGS` (auto-includes sqlite with `CGO_ENABLED=1`), keeping the developer's regular `gitea` binary untouched. - No more split into database-specific e2e tests. Test timeouts are strict, can be relaxed later if needed. - Simplified and streamlined the playwright config and test files. - Remove all output generation of playwright and all references to visual testing. - Tests run on Chrome locally, Chrome + Firefox on CI. - Simplified CI workflow — visible separate steps for frontend, backend, and test execution. - All exported env vars use `GITEA_TEST_E2E_*` prefix. - Use `GITEA_TEST_E2E_FLAGS` to pass flags to playwright, e.g. `GITEA_TEST_E2E_FLAGS="--ui" make test-e2e` for UI mode or `GITEA_TEST_E2E_FLAGS="--headed" make test-e2e` for headed mode. - Use `GITEA_TEST_E2E_DEBUG=1 make test-e2e` to show Gitea server output. --------- Signed-off-by: silverwind <me@silverwind.io> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
64 lines
2.5 KiB
TypeScript
64 lines
2.5 KiB
TypeScript
import {env} from 'node:process';
|
|
import {expect} from '@playwright/test';
|
|
import type {APIRequestContext, Locator, Page} from '@playwright/test';
|
|
|
|
export function apiBaseUrl() {
|
|
return env.GITEA_TEST_E2E_URL?.replace(/\/$/g, '');
|
|
}
|
|
|
|
export function apiHeaders() {
|
|
return {Authorization: `Basic ${globalThis.btoa(`${env.GITEA_TEST_E2E_USER}:${env.GITEA_TEST_E2E_PASSWORD}`)}`};
|
|
}
|
|
|
|
async function apiRetry(fn: () => Promise<{ok: () => boolean; status: () => number; text: () => Promise<string>}>, label: string) {
|
|
const maxAttempts = 5;
|
|
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
const response = await fn();
|
|
if (response.ok()) return;
|
|
if ([500, 502, 503].includes(response.status()) && attempt < maxAttempts - 1) {
|
|
const jitter = Math.random() * 500;
|
|
await new Promise((resolve) => globalThis.setTimeout(resolve, 1000 * (attempt + 1) + jitter));
|
|
continue;
|
|
}
|
|
throw new Error(`${label} failed: ${response.status()} ${await response.text()}`);
|
|
}
|
|
}
|
|
|
|
export async function apiCreateRepo(requestContext: APIRequestContext, {name, autoInit = true}: {name: string; autoInit?: boolean}) {
|
|
await apiRetry(() => requestContext.post(`${apiBaseUrl()}/api/v1/user/repos`, {
|
|
headers: apiHeaders(),
|
|
data: {name, auto_init: autoInit},
|
|
}), 'apiCreateRepo');
|
|
}
|
|
|
|
export async function apiDeleteRepo(requestContext: APIRequestContext, owner: string, name: string) {
|
|
await apiRetry(() => requestContext.delete(`${apiBaseUrl()}/api/v1/repos/${owner}/${name}`, {
|
|
headers: apiHeaders(),
|
|
}), 'apiDeleteRepo');
|
|
}
|
|
|
|
export async function apiDeleteOrg(requestContext: APIRequestContext, name: string) {
|
|
await apiRetry(() => requestContext.delete(`${apiBaseUrl()}/api/v1/orgs/${name}`, {
|
|
headers: apiHeaders(),
|
|
}), 'apiDeleteOrg');
|
|
}
|
|
|
|
export async function clickDropdownItem(page: Page, trigger: Locator, itemText: string) {
|
|
await trigger.click();
|
|
await page.getByText(itemText).click();
|
|
}
|
|
|
|
export async function login(page: Page, username = env.GITEA_TEST_E2E_USER, password = env.GITEA_TEST_E2E_PASSWORD) {
|
|
await page.goto('/user/login');
|
|
await page.getByLabel('Username or Email Address').fill(username);
|
|
await page.getByLabel('Password').fill(password);
|
|
await page.getByRole('button', {name: 'Sign In'}).click();
|
|
await expect(page.getByRole('link', {name: 'Sign In'})).toBeHidden();
|
|
}
|
|
|
|
export async function logout(page: Page) {
|
|
await page.context().clearCookies(); // workaround issues related to fomantic dropdown
|
|
await page.goto('/');
|
|
await expect(page.getByRole('link', {name: 'Sign In'})).toBeVisible();
|
|
}
|