Skip to content

Commit 18e0746

Browse files
silverwindclaude
andauthored
Rework e2e tests (#36634)
- 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>
1 parent 86d1024 commit 18e0746

22 files changed

+416
-521
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: e2e-tests
2+
3+
on:
4+
pull_request:
5+
6+
concurrency:
7+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
8+
cancel-in-progress: true
9+
10+
jobs:
11+
files-changed:
12+
uses: ./.github/workflows/files-changed.yml
13+
permissions:
14+
contents: read
15+
16+
test-e2e:
17+
if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.frontend == 'true'
18+
needs: files-changed
19+
runs-on: ubuntu-latest
20+
permissions:
21+
contents: read
22+
steps:
23+
- uses: actions/checkout@v6
24+
- uses: actions/setup-go@v6
25+
with:
26+
go-version-file: go.mod
27+
check-latest: true
28+
- uses: pnpm/action-setup@v4
29+
- uses: actions/setup-node@v6
30+
with:
31+
node-version: 24
32+
cache: pnpm
33+
cache-dependency-path: pnpm-lock.yaml
34+
- run: make deps-frontend
35+
- run: make frontend
36+
- run: make deps-backend
37+
- run: make gitea-e2e
38+
- run: make playwright
39+
- run: make test-e2e
40+
timeout-minutes: 10
41+
env:
42+
FORCE_COLOR: 1
43+
GITEA_TEST_E2E_DEBUG: 1

.gitignore

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ cpu.out
5555
*.log.*.gz
5656

5757
/gitea
58+
/gitea-e2e
5859
/gitea-vet
5960
/debug
6061
/integrations.test
@@ -67,13 +68,9 @@ cpu.out
6768
/indexers
6869
/log
6970
/public/assets/img/avatar
71+
/tests/e2e-output
7072
/tests/integration/gitea-integration-*
7173
/tests/integration/indexers-*
72-
/tests/e2e/gitea-e2e-*
73-
/tests/e2e/indexers-*
74-
/tests/e2e/reports
75-
/tests/e2e/test-artifacts
76-
/tests/e2e/test-snapshots
7774
/tests/*.ini
7875
/tests/**/*.git/**/*.sample
7976
/node_modules

CONTRIBUTING.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,14 @@ Here's how to run the test suite:
178178
| :------------------------------------------ | :------------------------------------------------------- | ------------------------------------------- |
179179
|``make test[\#SpecificTestName]`` | run unit test(s) | |
180180
|``make test-sqlite[\#SpecificTestName]`` | run [integration](tests/integration) test(s) for SQLite | [More details](tests/integration/README.md) |
181-
|``make test-e2e-sqlite[\#SpecificTestName]`` | run [end-to-end](tests/e2e) test(s) for SQLite | [More details](tests/e2e/README.md) |
181+
|``make test-e2e`` | run [end-to-end](tests/e2e) test(s) using Playwright | |
182+
183+
- E2E test environment variables
184+
185+
| Variable | Description |
186+
| :------------------------ | :---------------------------------------------------------------- |
187+
| ``GITEA_TEST_E2E_DEBUG`` | When set, show Gitea server output |
188+
| ``GITEA_TEST_E2E_FLAGS`` | Additional flags passed to Playwright, for example ``--ui`` |
182189

183190
## Translation
184191

Makefile

Lines changed: 12 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ endif
5353
ifeq ($(IS_WINDOWS),yes)
5454
GOFLAGS := -v -buildmode=exe
5555
EXECUTABLE ?= gitea.exe
56+
EXECUTABLE_E2E ?= gitea-e2e.exe
5657
else
5758
GOFLAGS := -v
5859
EXECUTABLE ?= gitea
60+
EXECUTABLE_E2E ?= gitea-e2e
5961
endif
6062

6163
ifeq ($(shell sed --version 2>/dev/null | grep -q GNU && echo gnu),gnu)
@@ -115,7 +117,7 @@ LDFLAGS := $(LDFLAGS) -X "main.Version=$(GITEA_VERSION)" -X "main.Tags=$(TAGS)"
115117

116118
LINUX_ARCHS ?= linux/amd64,linux/386,linux/arm-5,linux/arm-6,linux/arm64,linux/riscv64
117119

118-
GO_TEST_PACKAGES ?= $(filter-out $(shell $(GO) list code.gitea.io/gitea/models/migrations/...) code.gitea.io/gitea/tests/integration/migration-test code.gitea.io/gitea/tests code.gitea.io/gitea/tests/integration code.gitea.io/gitea/tests/e2e,$(shell $(GO) list ./... | grep -v /vendor/))
120+
GO_TEST_PACKAGES ?= $(filter-out $(shell $(GO) list code.gitea.io/gitea/models/migrations/...) code.gitea.io/gitea/tests/integration/migration-test code.gitea.io/gitea/tests code.gitea.io/gitea/tests/integration,$(shell $(GO) list ./... | grep -v /vendor/))
119121
MIGRATE_TEST_PACKAGES ?= $(shell $(GO) list code.gitea.io/gitea/models/migrations/...)
120122

121123
WEBPACK_SOURCES := $(shell find web_src/js web_src/css -type f)
@@ -153,10 +155,6 @@ GO_SOURCES := $(wildcard *.go)
153155
GO_SOURCES += $(shell find $(GO_DIRS) -type f -name "*.go")
154156
GO_SOURCES += $(GENERATED_GO_DEST)
155157

156-
# Force installation of playwright dependencies by setting this flag
157-
ifdef DEPS_PLAYWRIGHT
158-
PLAYWRIGHT_FLAGS += --with-deps
159-
endif
160158

161159
SWAGGER_SPEC := templates/swagger/v1_json.tmpl
162160
SWAGGER_SPEC_INPUT := templates/swagger/v1_input.json
@@ -187,7 +185,7 @@ all: build
187185
.PHONY: help
188186
help: Makefile ## print Makefile help information.
189187
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m[TARGETS] default target: build\033[0m\n\n\033[35mTargets:\033[0m\n"} /^[0-9A-Za-z._-]+:.*?##/ { printf " \033[36m%-45s\033[0m %s\n", $$1, $$2 }' Makefile #$(MAKEFILE_LIST)
190-
@printf " \033[36m%-46s\033[0m %s\n" "test-e2e[#TestSpecificName]" "test end to end using playwright"
188+
@printf " \033[36m%-46s\033[0m %s\n" "test-e2e" "test end to end using playwright"
191189
@printf " \033[36m%-46s\033[0m %s\n" "test[#TestSpecificName]" "run unit test"
192190
@printf " \033[36m%-46s\033[0m %s\n" "test-sqlite[#TestSpecificName]" "run integration test for sqlite"
193191

@@ -204,9 +202,8 @@ clean-all: clean ## delete backend, frontend and integration files
204202

205203
.PHONY: clean
206204
clean: ## delete backend and integration files
207-
rm -rf $(EXECUTABLE) $(DIST) $(BINDATA_DEST_WILDCARD) \
205+
rm -rf $(EXECUTABLE) $(EXECUTABLE_E2E) $(DIST) $(BINDATA_DEST_WILDCARD) \
208206
integrations*.test \
209-
e2e*.test \
210207
tests/integration/gitea-integration-* \
211208
tests/integration/indexers-* \
212209
tests/sqlite.ini tests/mysql.ini tests/pgsql.ini tests/mssql.ini man/ \
@@ -535,47 +532,12 @@ test-mssql-migration: migrations.mssql.test migrations.individual.mssql.test
535532

536533
.PHONY: playwright
537534
playwright: deps-frontend
538-
$(NODE_VARS) pnpm exec playwright install $(PLAYWRIGHT_FLAGS)
539-
540-
.PHONY: test-e2e%
541-
test-e2e%: TEST_TYPE ?= e2e
542-
# Clear display env variable. Otherwise, chromium tests can fail.
543-
DISPLAY=
535+
@# on GitHub Actions VMs, playwright's system deps are pre-installed
536+
@$(NODE_VARS) pnpm exec playwright install $(if $(GITHUB_ACTIONS),,--with-deps) chromium $(if $(CI),firefox) $(PLAYWRIGHT_FLAGS)
544537

545538
.PHONY: test-e2e
546-
test-e2e: test-e2e-sqlite
547-
548-
.PHONY: test-e2e-sqlite
549-
test-e2e-sqlite: playwright e2e.sqlite.test generate-ini-sqlite
550-
GITEA_TEST_CONF=tests/sqlite.ini ./e2e.sqlite.test
551-
552-
.PHONY: test-e2e-sqlite\#%
553-
test-e2e-sqlite\#%: playwright e2e.sqlite.test generate-ini-sqlite
554-
GITEA_TEST_CONF=tests/sqlite.ini ./e2e.sqlite.test -test.run TestE2e/$*
555-
556-
.PHONY: test-e2e-mysql
557-
test-e2e-mysql: playwright e2e.mysql.test generate-ini-mysql
558-
GITEA_TEST_CONF=tests/mysql.ini ./e2e.mysql.test
559-
560-
.PHONY: test-e2e-mysql\#%
561-
test-e2e-mysql\#%: playwright e2e.mysql.test generate-ini-mysql
562-
GITEA_TEST_CONF=tests/mysql.ini ./e2e.mysql.test -test.run TestE2e/$*
563-
564-
.PHONY: test-e2e-pgsql
565-
test-e2e-pgsql: playwright e2e.pgsql.test generate-ini-pgsql
566-
GITEA_TEST_CONF=tests/pgsql.ini ./e2e.pgsql.test
567-
568-
.PHONY: test-e2e-pgsql\#%
569-
test-e2e-pgsql\#%: playwright e2e.pgsql.test generate-ini-pgsql
570-
GITEA_TEST_CONF=tests/pgsql.ini ./e2e.pgsql.test -test.run TestE2e/$*
571-
572-
.PHONY: test-e2e-mssql
573-
test-e2e-mssql: playwright e2e.mssql.test generate-ini-mssql
574-
GITEA_TEST_CONF=tests/mssql.ini ./e2e.mssql.test
575-
576-
.PHONY: test-e2e-mssql\#%
577-
test-e2e-mssql\#%: playwright e2e.mssql.test generate-ini-mssql
578-
GITEA_TEST_CONF=tests/mssql.ini ./e2e.mssql.test -test.run TestE2e/$*
539+
test-e2e: playwright $(EXECUTABLE_E2E)
540+
@EXECUTABLE=$(EXECUTABLE_E2E) ./tools/test-e2e.sh $(GITEA_TEST_E2E_FLAGS)
579541

580542
.PHONY: bench-sqlite
581543
bench-sqlite: integrations.sqlite.test generate-ini-sqlite
@@ -671,18 +633,6 @@ migrations.individual.sqlite.test: $(GO_SOURCES) generate-ini-sqlite
671633
migrations.individual.sqlite.test\#%: $(GO_SOURCES) generate-ini-sqlite
672634
GITEA_TEST_CONF=tests/sqlite.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' code.gitea.io/gitea/models/migrations/$*
673635

674-
e2e.mysql.test: $(GO_SOURCES)
675-
$(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/e2e -o e2e.mysql.test
676-
677-
e2e.pgsql.test: $(GO_SOURCES)
678-
$(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/e2e -o e2e.pgsql.test
679-
680-
e2e.mssql.test: $(GO_SOURCES)
681-
$(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/e2e -o e2e.mssql.test
682-
683-
e2e.sqlite.test: $(GO_SOURCES)
684-
$(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/e2e -o e2e.sqlite.test -tags '$(TEST_TAGS)'
685-
686636
.PHONY: check
687637
check: test
688638

@@ -721,6 +671,9 @@ ifneq ($(and $(STATIC),$(findstring pam,$(TAGS))),)
721671
endif
722672
CGO_ENABLED="$(CGO_ENABLED)" CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) build $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(EXTLDFLAGS) $(LDFLAGS)' -o $@
723673

674+
$(EXECUTABLE_E2E): $(GO_SOURCES)
675+
CGO_ENABLED=1 $(GO) build $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TEST_TAGS)' -ldflags '-s -w $(EXTLDFLAGS) $(LDFLAGS)' -o $@
676+
724677
.PHONY: release
725678
release: frontend generate release-windows release-linux release-darwin release-freebsd release-copy release-compress vendor release-sources release-check
726679

eslint.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -911,9 +911,10 @@ export default defineConfig([
911911
},
912912
{
913913
...playwright.configs['flat/recommended'],
914-
files: ['tests/e2e/**'],
914+
files: ['tests/e2e/**/*.test.ts'],
915915
rules: {
916916
...playwright.configs['flat/recommended'].rules,
917+
'playwright/expect-expect': [0],
917918
},
918919
},
919920
{

playwright.config.ts

Lines changed: 17 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,35 @@
1-
import {devices} from '@playwright/test';
21
import {env} from 'node:process';
3-
import type {PlaywrightTestConfig} from '@playwright/test';
2+
import {defineConfig, devices} from '@playwright/test';
43

5-
const BASE_URL = env.GITEA_TEST_SERVER_URL?.replace?.(/\/$/g, '') || 'http://localhost:3000';
6-
7-
export default {
4+
export default defineConfig({
85
testDir: './tests/e2e/',
9-
testMatch: /.*\.test\.e2e\.ts/, // Match any .test.e2e.ts files
10-
11-
/* Maximum time one test can run for. */
12-
timeout: 30 * 1000,
13-
6+
outputDir: './tests/e2e-output/',
7+
testMatch: /.*\.test\.ts/,
8+
forbidOnly: Boolean(env.CI),
9+
reporter: 'list',
10+
timeout: env.CI ? 12000 : 6000,
1411
expect: {
15-
16-
/**
17-
* Maximum time expect() should wait for the condition to be met.
18-
* For example in `await expect(locator).toHaveText();`
19-
*/
20-
timeout: 2000,
12+
timeout: env.CI ? 6000 : 3000,
2113
},
22-
23-
/* Fail the build on CI if you accidentally left test.only in the source code. */
24-
forbidOnly: Boolean(env.CI),
25-
26-
/* Retry on CI only */
27-
retries: env.CI ? 2 : 0,
28-
29-
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
30-
reporter: env.CI ? 'list' : [['list'], ['html', {outputFolder: 'tests/e2e/reports/', open: 'never'}]],
31-
32-
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
3314
use: {
34-
headless: true, // set to false to debug
35-
15+
baseURL: env.GITEA_TEST_E2E_URL?.replace?.(/\/$/g, ''),
3616
locale: 'en-US',
37-
38-
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
39-
actionTimeout: 1000,
40-
41-
/* Maximum time allowed for navigation, such as `page.goto()`. */
42-
navigationTimeout: 5 * 1000,
43-
44-
/* Base URL to use in actions like `await page.goto('/')`. */
45-
baseURL: BASE_URL,
46-
47-
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
48-
trace: 'on-first-retry',
49-
50-
screenshot: 'only-on-failure',
17+
actionTimeout: env.CI ? 6000 : 3000,
18+
navigationTimeout: env.CI ? 12000 : 6000,
5119
},
52-
53-
/* Configure projects for major browsers */
5420
projects: [
5521
{
5622
name: 'chromium',
57-
58-
/* Project-specific settings. */
5923
use: {
6024
...devices['Desktop Chrome'],
25+
permissions: ['clipboard-read', 'clipboard-write'],
6126
},
6227
},
63-
64-
// disabled because of https://github.com/go-gitea/gitea/issues/21355
65-
// {
66-
// name: 'firefox',
67-
// use: {
68-
// ...devices['Desktop Firefox'],
69-
// },
70-
// },
71-
72-
{
73-
name: 'webkit',
74-
use: {
75-
...devices['Desktop Safari'],
76-
},
77-
},
78-
79-
/* Test against mobile viewports. */
80-
{
81-
name: 'Mobile Chrome',
82-
use: {
83-
...devices['Pixel 5'],
84-
},
85-
},
86-
{
87-
name: 'Mobile Safari',
28+
...env.CI ? [{
29+
name: 'firefox',
8830
use: {
89-
...devices['iPhone 12'],
31+
...devices['Desktop Firefox'],
9032
},
91-
},
33+
}] : [],
9234
],
93-
94-
/* Folder for test artifacts such as screenshots, videos, traces, etc. */
95-
outputDir: 'tests/e2e/test-artifacts/',
96-
/* Folder for test artifacts such as screenshots, videos, traces, etc. */
97-
snapshotDir: 'tests/e2e/test-snapshots/',
98-
} satisfies PlaywrightTestConfig;
35+
});

0 commit comments

Comments
 (0)