-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Changes from all commits
f69f99f
418867b
682675b
9a8c600
9b04f90
a6e660a
6d01598
5f998fb
a63ba41
0a41325
dda3d89
22aa0ed
b08bfb5
282397f
0236676
f9aab1f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,3 +118,7 @@ prime/ | |
|
||
# Manpage | ||
/man | ||
test-results/ | ||
|
||
# E2E | ||
tools/e2e/reports/ |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a way to override the |
||
|
||
.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 . | ||
|
Large diffs are not rendered by default.
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; |
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}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The built-in bash on macOS is ancient. When I run
It should either use this shebang:
... 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:-""} |
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` }); | ||
}); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.