Skip to content

Add initial playwright config #18442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 16 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -498,6 +498,77 @@ steps:
- name: deps
path: /go

---
kind: pipeline
type: docker
name: testing-e2e

platform:
os: linux
arch: amd64

#depends_on:
# - testing-amd64
# - testing-arm64

trigger:
event:
- pull_request

volumes:
- name: deps
temp: {}

services:
- name: pgsql
pull: default
image: postgres:10
environment:
POSTGRES_DB: testgitea-e2e
POSTGRES_PASSWORD: postgres
POSTGRES_INITDB_ARGS: --encoding=UTF8 --lc-collate='en_US.UTF-8' --lc-ctype='en_US.UTF-8'

steps:
- name: deps-frontend
image: node:16
pull: always
commands:
- make deps-frontend

- name: deps-backend
image: golang:1.18
pull: always
commands:
- make deps-backend
volumes:
- name: deps
path: /go

# TODO: We should probably build all dependencies into a test image
- name: test-e2e
image: mcr.microsoft.com/playwright:v1.22.2-focal
commands:
- curl -sL https://go.dev/dl/go1.18.3.linux-amd64.tar.gz -o go1.18.3.linux-amd64.tar.gz && tar -C /usr/local -xzf go1.18.3.linux-amd64.tar.gz
- groupadd --gid 1001 gitea && useradd -m --gid 1001 --uid 1001 gitea
- apt-get update
- apt-get install build-essential --yes
- export TEST_PGSQL_SCHEMA=''
- ./build/test-env-prepare.sh
- su gitea bash -c "export PATH=$PATH:/usr/local/go/bin && timeout -s ABRT 40m make test-e2e-pgsql"
environment:
GOPROXY: https://goproxy.io
GOSUMDB: sum.golang.org
TAGS: bindata
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this tag is for go build only in my mind.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just updated the summary. I'm actually building the binary before running e2e tests. Alternatively, I could throw an error "Build gitea before running e2e tests", but I like this better right now.

USE_REPO_TEST_DIR: 1
NO_DEPS_PLAYWRIGHT: 1
TEST_LOGGER: console,file # Debug
TEST_PGSQL_DBNAME: 'testgitea-e2e'
NPX_FLAGS: '--yes'
depends_on: [deps-backend, deps-frontend]
volumes:
- name: deps
path: /go

---
kind: pipeline
name: update_translations
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -118,3 +118,7 @@ prime/

# Manpage
/man
test-results/

# E2E
tools/e2e/reports/
64 changes: 64 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -132,6 +132,10 @@ ifeq ($(filter $(TAGS_SPLIT),bindata),bindata)
GO_SOURCES += $(BINDATA_DEST)
endif

ifneq ($(NO_DEPS_PLAYWRIGHT),1)
PLAYWRIGHT_FLAGS += --with-deps
endif

SWAGGER_SPEC := templates/swagger/v1_json.tmpl
SWAGGER_SPEC_S_TMPL := s|"basePath": *"/api/v1"|"basePath": "{{AppSubUrl \| JSEscape \| Safe}}/api/v1"|g
SWAGGER_SPEC_S_JSON := s|"basePath": *"{{AppSubUrl \| JSEscape \| Safe}}/api/v1"|"basePath": "/api/v1"|g
@@ -183,6 +187,7 @@ help:
@echo " - test test everything"
@echo " - test-frontend test frontend files"
@echo " - test-backend test backend files"
@echo " - test-e2e[\#TestSpecificName] test end to end using playwright"
@echo " - webpack build webpack files"
@echo " - svg build svg files"
@echo " - fomantic build fomantic files"
@@ -390,6 +395,7 @@ gomod-check: tidy

generate-ini-sqlite:
sed -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
-e 's|{{TEST_LOGGER}}|$(or $(TEST_LOGGER),test$(COMMA)file)|g' \
integrations/sqlite.ini.tmpl > integrations/sqlite.ini

.PHONY: test-sqlite
@@ -416,6 +422,7 @@ generate-ini-mysql:
-e 's|{{TEST_MYSQL_USERNAME}}|${TEST_MYSQL_USERNAME}|g' \
-e 's|{{TEST_MYSQL_PASSWORD}}|${TEST_MYSQL_PASSWORD}|g' \
-e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
-e 's|{{TEST_LOGGER}}|$(or $(TEST_LOGGER),test$(COMMA)file)|g' \
integrations/mysql.ini.tmpl > integrations/mysql.ini

.PHONY: test-mysql
@@ -437,6 +444,7 @@ generate-ini-mysql8:
-e 's|{{TEST_MYSQL8_USERNAME}}|${TEST_MYSQL8_USERNAME}|g' \
-e 's|{{TEST_MYSQL8_PASSWORD}}|${TEST_MYSQL8_PASSWORD}|g' \
-e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
-e 's|{{TEST_LOGGER}}|$(or $(TEST_LOGGER),test$(COMMA)file)|g' \
integrations/mysql8.ini.tmpl > integrations/mysql8.ini

.PHONY: test-mysql8
@@ -459,6 +467,7 @@ generate-ini-pgsql:
-e 's|{{TEST_PGSQL_PASSWORD}}|${TEST_PGSQL_PASSWORD}|g' \
-e 's|{{TEST_PGSQL_SCHEMA}}|${TEST_PGSQL_SCHEMA}|g' \
-e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
-e 's|{{TEST_LOGGER}}|$(or $(TEST_LOGGER),test$(COMMA)file)|g' \
integrations/pgsql.ini.tmpl > integrations/pgsql.ini

.PHONY: test-pgsql
@@ -480,6 +489,7 @@ generate-ini-mssql:
-e 's|{{TEST_MSSQL_USERNAME}}|${TEST_MSSQL_USERNAME}|g' \
-e 's|{{TEST_MSSQL_PASSWORD}}|${TEST_MSSQL_PASSWORD}|g' \
-e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
-e 's|{{TEST_LOGGER}}|$(or $(TEST_LOGGER),test$(COMMA)file)|g' \
integrations/mssql.ini.tmpl > integrations/mssql.ini

.PHONY: test-mssql
@@ -495,6 +505,60 @@ test-mssql-migration: migrations.mssql.test migrations.individual.mssql.test gen
GITEA_ROOT="$(CURDIR)" GITEA_CONF=integrations/mssql.ini ./migrations.mssql.test -test.failfast
GITEA_ROOT="$(CURDIR)" GITEA_CONF=integrations/mssql.ini ./migrations.individual.mssql.test -test.failfast

.PHONY: test-e2e%
# Use only file logging for end-to-end tests
test-e2e%: TEST_LOGGER ?= file

.PHONY: test-e2e
test-e2e: test-e2e-sqlite

.PHONY: test-e2e\#%
test-e2e\#%: test-e2e-sqlite\#%
# Kind of a hack to get makefile to accept passing arguement
true

.PHONY: test-e2e-sqlite
test-e2e-sqlite: TAGS+=sqlite sqlite_unlock_notify
test-e2e-sqlite: build generate-ini-sqlite
npx playwright install $(PLAYWRIGHT_FLAGS)
GITEA_ROOT=$(CURDIR) GITEA_URL="http://localhost:3003" GITEA_EXECUTABLE=$(EXECUTABLE) GITEA_CONF=integrations/sqlite.ini ./tools/e2e/run_e2e.sh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to override the GITEA_URL? This port is wrong when I run the make task.


.PHONY: test-e2e-sqlite\#%
test-e2e-sqlite\#%: TAGS+=sqlite sqlite_unlock_notify
test-e2e-sqlite\#%: build generate-ini-sqlite
npx playwright install $(PLAYWRIGHT_FLAGS)
GITEA_URL="http://localhost:3003" GITEA_EXECUTABLE=$(EXECUTABLE) GITEA_CONF=$(CURDIR)/integrations/sqlite.ini E2E_TESTS=$* ./tools/e2e/run_e2e.sh

.PHONY: test-e2e-mysql8
test-e2e-mysql8: build generate-ini-mysql8
npx playwright install $(PLAYWRIGHT_FLAGS)
GITEA_URL="http://localhost:3004" GITEA_EXECUTABLE=$(EXECUTABLE) GITEA_CONF=$(CURDIR)/integrations/mysql8.ini ./tools/e2e/run_e2e.sh

.PHONY: test-e2e-mysql8\#%
test-e2e-mysql8\#%: build generate-ini-mysql8
npx playwright install $(PLAYWRIGHT_FLAGS)
GITEA_URL="http://localhost:3004" GITEA_EXECUTABLE=$(EXECUTABLE) GITEA_CONF=$(CURDIR)/integrations/mysql8.ini E2E_TESTS=$* ./tools/e2e/run_e2e.sh

.PHONY: test-e2e-pgsql
test-e2e-pgsql: build generate-ini-pgsql
npx playwright install $(PLAYWRIGHT_FLAGS)
GITEA_URL="http://localhost:3002" GITEA_EXECUTABLE=$(EXECUTABLE) GITEA_CONF=$(CURDIR)/integrations/pgsql.ini ./tools/e2e/run_e2e.sh

.PHONY: test-e2e-pgsql\#%
test-e2e-pgsql\#%: build generate-ini-pgsql
npx playwright install $(PLAYWRIGHT_FLAGS)
GITEA_URL="http://localhost:3002" GITEA_EXECUTABLE=$(EXECUTABLE) GITEA_CONF=$(CURDIR)/integrations/pgsql.ini E2E_TESTS=$* ./tools/e2e/run_e2e.sh

.PHONY: test-e2e-mssql
test-e2e-mssql: build generate-ini-mssql
npx playwright install $(PLAYWRIGHT_FLAGS)
GITEA_ROOT=$(CURDIR) GITEA_URL="http://localhost:3003" GITEA_EXECUTABLE=$(EXECUTABLE) GITEA_CONF=$(CURDIR)/integrations/mssql.ini ./tools/e2e/run_e2e.sh

.PHONY: test-e2e-mssql\#%
test-e2e-mssql\#%: build generate-ini-mssql
npx playwright install $(PLAYWRIGHT_FLAGS)
GITEA_ROOT=$(CURDIR) GITEA_URL="http://localhost:3003" GITEA_EXECUTABLE=$(EXECUTABLE) GITEA_CONF=$(CURDIR)/integrations/mssql.ini E2E_TESTS=$* ./tools/e2e/run_e2e.sh

.PHONY: bench-sqlite
bench-sqlite: integrations.sqlite.test generate-ini-sqlite
GITEA_ROOT="$(CURDIR)" GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
2 changes: 1 addition & 1 deletion integrations/mssql.ini.tmpl
Original file line number Diff line number Diff line change
@@ -82,7 +82,7 @@ PROVIDER = file
PROVIDER_CONFIG = integrations/gitea-integration-mssql/data/sessions

[log]
MODE = test,file
MODE = {{TEST_LOGGER}}
ROOT_PATH = {{REPO_TEST_DIR}}mssql-log
ROUTER = ,
XORM = file
2 changes: 1 addition & 1 deletion integrations/mysql.ini.tmpl
Original file line number Diff line number Diff line change
@@ -101,7 +101,7 @@ PROVIDER = file
PROVIDER_CONFIG = integrations/gitea-integration-mysql/data/sessions

[log]
MODE = test,file
MODE = {{TEST_LOGGER}}
ROOT_PATH = {{REPO_TEST_DIR}}mysql-log
ROUTER = ,
XORM = file
2 changes: 1 addition & 1 deletion integrations/mysql8.ini.tmpl
Original file line number Diff line number Diff line change
@@ -79,7 +79,7 @@ PROVIDER = file
PROVIDER_CONFIG = integrations/gitea-integration-mysql8/data/sessions

[log]
MODE = test,file
MODE = {{TEST_LOGGER}}
ROOT_PATH = {{REPO_TEST_DIR}}mysql8-log
ROUTER = ,
XORM = file
2 changes: 1 addition & 1 deletion integrations/pgsql.ini.tmpl
Original file line number Diff line number Diff line change
@@ -83,7 +83,7 @@ PROVIDER = file
PROVIDER_CONFIG = integrations/gitea-integration-pgsql/data/sessions

[log]
MODE = test,file
MODE = {{TEST_LOGGER}}
ROOT_PATH = {{REPO_TEST_DIR}}pgsql-log
ROUTER = ,
XORM = file
2 changes: 1 addition & 1 deletion integrations/sqlite.ini.tmpl
Original file line number Diff line number Diff line change
@@ -78,7 +78,7 @@ PROVIDER = file
PROVIDER_CONFIG = integrations/gitea-integration-sqlite/data/sessions

[log]
MODE = test,file
MODE = {{TEST_LOGGER}}
ROOT_PATH = {{REPO_TEST_DIR}}sqlite-log
ROUTER = ,
XORM = file
6,143 changes: 3,750 additions & 2,393 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -45,6 +45,7 @@
},
"devDependencies": {
"@happy-dom/jest-environment": "4.0.1",
"@playwright/test": "1.22.2",
"eslint": "8.15.0",
"eslint-plugin-html": "6.2.0",
"eslint-plugin-import": "2.26.0",
121 changes: 121 additions & 0 deletions playwright.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// @ts-check
import {devices} from '@playwright/test';

const BASE_URL = process.env.GITEA_URL ? process.env.GITEA_URL : 'http://localhost:3000';

/**
* @see https://playwright.dev/docs/test-configuration
* @type {import('@playwright/test').PlaywrightTestConfig}
*/
const config = {
testDir: './tools/e2e/tests', // TODO: Change this to the ./web_src/ dir?
testMatch: /.*\.test\.e2e\.js/, // Match any .test.e2e.js files

/* Maximum time one test can run for. */
timeout: 30 * 1000,

expect: {

/**
* Maximum time expect() should wait for the condition to be met.
* For example in `await expect(locator).toHaveText();`
*/
timeout: 2000
},

/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,

/* Retry on CI only */
retries: process.env.CI ? 2 : 0,

/* Opt out of parallel tests on CI. */
// workers: process.env.CI ? 1 : undefined,

/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: process.env.CI ? 'dot' : [['html', {outputFolder: 'tools/e2e/reports/', open: 'never'}]],

/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
headless: true,

locale: 'en-US',

/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
actionTimeout: 1000,

/* Maximum time allowed for navigation, such as `page.goto()`. */
navigationTimeout: 5 * 1000,

/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: BASE_URL,

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},

/* Configure projects for major browsers */
projects: [
{
name: 'chromium',

/* Project-specific settings. */
use: {
...devices['Desktop Chrome'],
},
},

{
name: 'firefox',
use: {
...devices['Desktop Firefox'],
},
},

{
name: 'webkit',
use: {
...devices['Desktop Safari'],
},
},

/* Test against mobile viewports. */
{
name: 'Mobile Chrome',
use: {
...devices['Pixel 5'],
},
},
{
name: 'Mobile Safari',
use: {
...devices['iPhone 12'],
},
},

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: {
// channel: 'msedge',
// },
// },
// {
// name: 'Google Chrome',
// use: {
// channel: 'chrome',
// },
// },
],

/* Folder for test artifacts such as screenshots, videos, traces, etc. */
// outputDir: 'test-results/',

/* Run your local dev server before starting the tests */
// webServer: {
// command: 'npm run start',
// port: 3000,
// },
};

export default config;
18 changes: 18 additions & 0 deletions tools/e2e/run_e2e.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
set -euo pipefail

# Kill any processes on exit
trap 'kill $(jobs -p)' EXIT

GiteaFlags=()

[[ -v GITEA_CUSTOM ]] && GiteaFlags+=(-C "${GITEA_CUSTOM}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The built-in bash on macOS is ancient. When I run make test-e2e, I get this:

./tools/e2e/run_e2e.sh: line 9: conditional binary operator expected
kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
make: *** [test-e2e-sqlite] Error 1

It should either use this shebang:

#!/usr/bin/env bash

... or use more compatible syntax. The latter will probably lead to fewer gotchas.

[[ -v GITEA_CONF ]] && GiteaFlags+=(-c "${GITEA_CONF}")

./"${GITEA_EXECUTABLE:-gitea}" "${GiteaFlags[@]}" --quiet web &

# Wait up to 30s for server to start
timeout 30 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' ${GITEA_URL:-http://localhost:3000})" != "200" ]]; do sleep 2; done' || \
(echo -e "\033[0;31mTimed out testing server up: ${GITEA_URL:-http://localhost:3000}\033[0m"; false)

npx playwright test ${E2E_TESTS:-""}
24 changes: 24 additions & 0 deletions tools/e2e/tests/example.test.e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// @ts-check
import {test, expect} from '@playwright/test';

test('Load Homepage', async ({page}, workerInfo) => {
const response = await page.goto('/');
await expect(response?.status()).toBe(200); // Status OK
await expect(page).toHaveTitle(/^Gitea: Git with a cup of tea\s*$/);
await expect(page.locator('.logo')).toHaveAttribute('src', '/assets/img/logo.svg');
});

test('Test Register Form', async ({page}, workerInfo) => {
const response = await page.goto('/user/sign_up');
await expect(response?.status()).toBe(200); // Status OK
await page.type('input[name=user_name]', `test-${workerInfo.workerIndex}`);
await page.type('input[name=email]', `test-${workerInfo.workerIndex}@test.com`);
await page.type('input[name=password]', 'test123');
await page.type('input[name=retype]', 'test123');
await page.click('form button.ui.green.button:visible');
// Make sure we routed to the home page. Else login failed.
await expect(page.url()).toBe(`${workerInfo.project.use.baseURL}/`);
// Uncomment to see visual testing
//await expect(page).toHaveScreenshot({ timeout: 20000, mask: [page.locator('footer div.ui.left')] });
//await page.screenshot({ path: `tools/e2e/screenshots/${workerInfo.title}-${workerInfo.project.name}.png` });
});