···11# End to end tests
2233-E2e tests largely follow the same syntax as [integration tests](../integration).
44-Whereas integration tests are intended to mock and stress the back-end, server-side code, e2e tests the interface between front-end and back-end, as well as visual regressions with both assertions and visual comparisons.
55-They can be run with make commands for the appropriate backends, namely:
66-```shell
77-make test-sqlite
88-make test-pgsql
99-make test-mysql
1010-```
33+Thank you for your effort to provide good software tests for Forgejo.
44+Please also read the general testing instructions in the
55+[Forgejo contributor documentation](https://forgejo.org/docs/next/contributor/testing/)
66+and make sure to also check the
77+[Playwright documentation](https://playwright.dev/docs/intro)
88+for further information.
99+1010+This file is meant to provide specific information for the integration tests
1111+as well as some tips and tricks you should know.
1212+1313+Feel free to extend this file with more instructions if you feel like you have something to share!
1414+1515+1616+## How to run the tests?
1717+1818+Before running any tests, please ensure you perform a clean frontend build:
11191212-Make sure to perform a clean front-end build before running tests:
1320```
1421make clean frontend
1522```
16231717-## Install playwright system dependencies
2424+Whenever you modify frontend code (i.e. JavaScript and CSS files),
2525+you need to create a new frontend build.
2626+2727+For tests that require interactive Git repos,
2828+you also need to ensure a Forgejo binary is ready to be used by Git hooks.
2929+For this, you additionally need to run
3030+3131+~~~
3232+make TAGS="sqlite sqlite_unlock_notify" backend
3333+~~~
3434+3535+### Install dependencies
3636+3737+Browsertesting is performed by playwright.
3838+You need certain system libraries and playwright will download required browsers.
3939+Playwright takes care of this when you run:
4040+1841```
1942npx playwright install-deps
2043```
21442222-## Interactive testing
4545+> **Note**
4646+> On some operating systems, the installation of missing libraries can complicate testing certain browsers.
4747+> It is often not necessary to test with all browsers locally.
4848+> Choosing either Firefox or Chromium is fine.
4949+23502424-You can make use of Playwright's integrated UI mode to run individual tests,
2525-get feedback and visually trace what your browser is doing.
5151+### Run all tests
5252+5353+If you want to run the full test suite, you can use
5454+5555+```
5656+make test-e2e-sqlite
5757+```
5858+5959+### Interactive testing
26602727-To do so, launch the debugserver using:
6161+We recommend that you use interactive testing for the development.
6262+After you performed the required builds,
6363+you should use one shell to start the debugserver (and leave it running):
28642965```
3066make test-e2e-debugserver
3167```
32683333-Then launch the Playwright UI:
6969+It allows you to explore the test data in your local browser,
7070+and playwright to perform tests on it.
7171+7272+> **Note**
7373+> The modifications persist while the debugserver is running.
7474+> If you modified things, it might be useful to restart it to get back to a fresh state.
7575+> While writing playwright tests, you either
7676+> need to ensure they are resilient against repeated runs
7777+> (e.g. when only creating new content),
7878+> or that they restore the initial state for the next browser run.
7979+8080+#### With the playwright UI:
8181+8282+Playwright ships with an integrated UI mode which allows you to
8383+run individual tests and to debug them by seeing detailed traces of what playwright does.
8484+Launch it with:
34853586```
3687npx playwright test --ui
3788```
38893939-You can also run individual tests while the debugserver using:
9090+#### Running individual tests
40914192```
4293npx playwright test actions.test.e2e.js:9
···4697and after the colon you can put the linenumber where the test is defined.
479848994949-## Run all tests via local act_runner
100100+#### With VSCodium or VSCode
101101+102102+To debug a test, you can also use "Playwright Test" for
103103+[VScodium](https://open-vsx.org/extension/ms-playwright/playwright)
104104+or [VSCode](https://marketplace.visualstudio.com/items?itemName=ms-playwright.playwright).
105105+106106+107107+### Run all tests via local act_runner
108108+109109+If you have a [forgejo runner](https://code.forgejo.org/forgejo/runner/),
110110+you can use it to run the test jobs:
111111+50112```
5151-act_runner exec -W ./.github/workflows/pull-e2e-tests.yml --event=pull_request --default-actions-url="https://github.com" -i catthehacker/ubuntu:runner-latest
113113+forgejo-runner exec -W .forgejo/workflows/e2e.yml --event=pull_request
52114```
531155454-## Run sqlite e2e tests
5555-Start tests
5656-```
5757-make test-e2e-sqlite
5858-```
116116+### Run e2e tests with another database
117117+118118+This approach is not currently used,
119119+neither in the CI/CD nor by core contributors on their lcoal machines.
120120+It is still documented for the sake of completeness:
121121+You can also perform e2e tests using MariaDB/MySQL or PostgreSQL if you want.
591226060-## Run MySQL e2e tests
61123Setup a MySQL database inside docker
62124```
63125docker run -e "MYSQL_DATABASE=test" -e "MYSQL_ALLOW_EMPTY_PASSWORD=yes" -p 3306:3306 --rm --name mysql mysql:latest #(just ctrl-c to stop db and clean the container)
···68130TEST_MYSQL_HOST=localhost:3306 TEST_MYSQL_DBNAME=test TEST_MYSQL_USERNAME=root TEST_MYSQL_PASSWORD='' make test-e2e-mysql
69131```
701327171-## Run pgsql e2e tests
72133Setup a pgsql database inside docker
73134```
74135docker run -e "POSTGRES_DB=test" -p 5432:5432 --rm --name pgsql postgres:latest #(just ctrl-c to stop db and clean the container)
···78139TEST_PGSQL_HOST=localhost:5432 TEST_PGSQL_DBNAME=test TEST_PGSQL_USERNAME=postgres TEST_PGSQL_PASSWORD=postgres make test-e2e-pgsql
79140```
801418181-## Running individual tests
142142+### Running individual tests
8214383144Example command to run `example.test.e2e.js` test file:
841458585-_Note: unlike integration tests, this filtering is at the file level, not function_
146146+> **Note**
147147+> Unlike integration tests, this filtering is at the file level, not function
8614887149For SQLite:
88150···90152make test-e2e-sqlite#example
91153```
921549393-For PostgreSQL databases(replace `mysql` to `pgsql`):
9494-9595-```
9696-TEST_MYSQL_HOST=localhost:1433 TEST_MYSQL_DBNAME=test TEST_MYSQL_USERNAME=sa TEST_MYSQL_PASSWORD=MwantsaSecurePassword1 make test-e2e-mysql#example
9797-```
155155+### Visual testing
981569999-## Visual testing
157157+> **Warning**
158158+> This is not currently used by most Forgejo contributors.
159159+> Your help to improve the situation and allow for visual testing is appreciated.
100160101161Although the main goal of e2e is assertion testing, we have added a framework for visual regress testing. If you are working on front-end features, please use the following:
102162 - Check out `main`, `make clean frontend`, and run e2e tests with `VISUAL_TEST=1` to generate outputs. This will initially fail, as no screenshots exist. You can run the e2e tests again to assert it passes.
···106166107167ACCEPT_VISUAL=1 will overwrite the snapshot images with new images.
108168109109-## With VSCodium or VSCode
169169+170170+## Tips and tricks
110171111111-To debug a test, you can use "Playwright Test" for
112112-[VScodium](https://open-vsx.org/extension/ms-playwright/playwright)
113113-or [VSCode](https://marketplace.visualstudio.com/items?itemName=ms-playwright.playwright).
114114-Before doing that you will need to manually start a Forgejo instance and populate it
115115-with data from `models/fixtures` by running:
172172+If you know noteworthy tests that can act as an inspiration for new tests,
173173+please add some details here.
116174117117-```sh
118118-make TAGS='sqlite sqlite_unlock_notify' 'test-e2e-debugserver'
119119-```
175175+### Run tests very selectively
176176+177177+Browser testing can take some time.
178178+If you want to iterate fast,
179179+save your time and only run very selected tests.
180180+Use only one browser.
181181+182182+### Skip Safari if it doesn't work
183183+184184+Many contributors have issues getting Safari (webkit)
185185+and especially Safari Mobile to work.
186186+187187+At the top of your test function, you can use:
188188+189189+~~~javascript
190190+test.skip(workerInfo.project.name === 'Mobile Safari', 'Unable to get tests working on Safari Mobile.');
191191+~~~
192192+193193+### Don't forget the formatting.
194194+195195+When writing tests without modifying other frontend code,
196196+it is easy to forget that the JavaScript test files also need formatting.
197197+198198+Run `make lint-frontend-fix`.
199199+200200+### Define new repos
201201+202202+Take a look at `declare_repos_test.go` to see how to add your repositories.
203203+Feel free to improve the logic used there if you need more advanced functionality
204204+(it is a simplified version of the code used in the integration tests).
205205+206206+### Accessibility testing
207207+208208+If you can, perform automated accessibility testing using
209209+[AxeCore](https://github.com/dequelabs/axe-core-npm/blob/develop/packages/playwright/README.md).
210210+211211+Take a look at `shared/forms.js` and some other places for inspiration.
212212+213213+### List related files coverage
214214+215215+If you think your playwright tests covers an important aspect of some template, CSS or backend files,
216216+consider adding the paths to `.forgejo/workflows/e2e.yml` in the path filter.
217217+218218+It ensures that future modifications to this file will be tested as well.
219219+220220+Currently, we do not run the e2e tests on all changes.
+8-4
tests/e2e/declare_repos_test.go
···2121 "github.com/stretchr/testify/require"
2222)
23232424+// first entry represents filename
2525+// the following entries define the full file content over time
2426type FileChanges [][]string
25272628// put your Git repo declarations in here
2729// feel free to amend the helper function below or use the raw variant directly
2830func DeclareGitRepos(t *testing.T) func() {
2929- var cleanupFunctions []func()
3030- cleanupFunctions = append(cleanupFunctions, newRepo(t, 2, "diff-test", FileChanges{
3131- {"testfile", "hello", "hallo", "hola", "native", "ubuntu-latest", "- runs-on: ubuntu-latest", "- runs-on: debian-latest"},
3232- }))
3131+ cleanupFunctions := []func(){
3232+ newRepo(t, 2, "diff-test", FileChanges{
3333+ {"testfile", "hello", "hallo", "hola", "native", "ubuntu-latest", "- runs-on: ubuntu-latest", "- runs-on: debian-latest"},
3434+ }),
3535+ // add your repo declarations here
3636+ }
33373438 return func() {
3539 for _, cleanup := range cleanupFunctions {
+36-14
tests/integration/README.md
···11# Integration tests
2233+Thank you for your effort to provide good software tests for Forgejo.
44+Please also read the general testing instructions in the
55+[Forgejo contributor documentation](https://forgejo.org/docs/next/contributor/testing/).
66+77+This file is meant to provide specific information for the integration tests
88+as well as some tips and tricks you should know.
99+1010+Feel free to extend this file with more instructions if you feel like you have something to share!
1111+1212+1313+## How to run the tests?
1414+1515+Before running any tests, please ensure you perform a clean build:
1616+1717+```
1818+make clean build
1919+```
2020+321Integration tests can be run with make commands for the
422appropriate backends, namely:
523```shell
···826make test-mysql
927```
10281111-Make sure to perform a clean build before running tests:
1212-```
1313-make clean build
1414-```
15291616-## Run tests via local act_runner
3030+### Run tests via local forgejo runner
17311818-### Run all jobs
3232+If you have a [forgejo runner](https://code.forgejo.org/forgejo/runner/),
3333+you can use it to run the test jobs:
3434+3535+#### Run all jobs
19362037```
2121-act_runner exec -W ./.github/workflows/pull-db-tests.yml --event=pull_request --default-actions-url="https://github.com" -i catthehacker/ubuntu:runner-latest
3838+forgejo-runner exec -W .forgejo/workflows/testing.yml --event=pull_request
2239```
23402441Warning: This file defines many jobs, so it will be resource-intensive and therefore not recommended.
25422626-### Run single job
4343+#### Run single job
27442845```SHELL
2929-act_runner exec -W ./.github/workflows/pull-db-tests.yml --event=pull_request --default-actions-url="https://github.com" -i catthehacker/ubuntu:runner-latest -j <job_name>
4646+forgejo-runner exec -W .forgejo/workflows/testing.yml --event=pull_request -j <job_name>
3047```
31483249You can list all job names via:
33503451```SHELL
3535-act_runner exec -W ./.github/workflows/pull-db-tests.yml --event=pull_request --default-actions-url="https://github.com" -i catthehacker/ubuntu:runner-latest -l
5252+forgejo-runner exec -W .forgejo/workflows/testing.yml --event=pull_request -l
3653```
37543838-## Run sqlite integration tests
5555+### Run sqlite integration tests
3956Start tests
4057```
4158make test-sqlite
4259```
43604444-## Run MySQL integration tests
6161+### Run MySQL integration tests
4562Setup a MySQL database inside docker
4663```
4764docker run -e "MYSQL_DATABASE=test" -e "MYSQL_ALLOW_EMPTY_PASSWORD=yes" -p 3306:3306 --rm --name mysql mysql:latest #(just ctrl-c to stop db and clean the container)
···5269TEST_MYSQL_HOST=localhost:3306 TEST_MYSQL_DBNAME=test TEST_MYSQL_USERNAME=root TEST_MYSQL_PASSWORD='' make test-mysql
5370```
54715555-## Run pgsql integration tests
7272+### Run pgsql integration tests
5673Setup a pgsql database inside docker
5774```
5875docker run -e "POSTGRES_DB=test" -p 5432:5432 --rm --name pgsql postgres:latest #(just ctrl-c to stop db and clean the container)
···6279TEST_PGSQL_HOST=localhost:5432 TEST_PGSQL_DBNAME=test TEST_PGSQL_USERNAME=postgres TEST_PGSQL_PASSWORD=postgres make test-pgsql
6380```
64816565-## Running individual tests
8282+### Running individual tests
66836784Example command to run GPG test:
6885···99116```bash
100117GITEA_SLOW_TEST_TIME="10s" GITEA_SLOW_FLUSH_TIME="5s" make test-sqlite
101118```
119119+120120+## Tips and tricks
121121+122122+If you know noteworthy tests that can act as an inspiration for new tests,
123123+please add some details here.