Skip to content

Commit 2861aa4

Browse files
committed
Cleanup test generation
1 parent 7933e44 commit 2861aa4

File tree

3 files changed

+37
-19
lines changed

3 files changed

+37
-19
lines changed

docs/content/doc/developers/guidelines-backend.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ To maintain understandable code and avoid circular dependencies it is important
3333

3434
- `build`: Scripts to help build Gitea.
3535
- `cmd`: All Gitea actual sub commands includes web, doctor, serv, hooks, admin and etc. `web` will start the web service. `serv` and `hooks` will be invoked by Git or OpenSSH. Other sub commands could help to maintain Gitea.
36-
- `tests`: Tests
37-
- `tests/integration`: Integration tests
36+
- `tests`: Common test utility functions
37+
- `tests/integration`: Integration tests, to test back-end regressions
38+
- `tests/e2e`: E2e tests, to test test front-end <> back-end compatibility and visual regressions.
3839
- `models`: Contains the data structures used by xorm to construct database tables. It also contains functions to query and update the database. Dependencies to other Gitea code should be avoided. You can make exceptions in cases such as logging.
3940
- `models/db`: Basic database operations. All other `models/xxx` packages should depend on this package. The `GetEngine` function should only be invoked from `models/`.
4041
- `models/fixtures`: Sample data used in unit tests and integration tests. One `yml` file means one table which will be loaded into database when beginning the tests.

playwright.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const config = {
3333
// workers: process.env.CI ? 1 : undefined,
3434

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

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

tests/e2e/e2e_test.go

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,37 @@ func TestMain(m *testing.M) {
6767
}
6868

6969
func TestE2e(t *testing.T) {
70-
// Default 5 minute timeout
71-
onGiteaRun(t, func(*testing.T, *url.URL) {
72-
cmd := exec.Command("npx", "playwright", "test")
73-
cmd.Env = os.Environ()
74-
cmd.Env = append(cmd.Env, fmt.Sprintf("GITEA_URL=%s", setting.AppURL))
75-
var out bytes.Buffer
76-
cmd.Stdout = &out
77-
err := cmd.Run()
78-
if err != nil {
79-
// Currently colored output is conflicting. Using Printf until that is resolved.
80-
fmt.Printf("%v", out.String())
81-
log.Fatal("Playwright Failed: %s", err)
82-
} else {
83-
fmt.Printf("%v", out.String())
84-
}
85-
})
70+
// Find the paths of all e2e test files in test test directory.
71+
search_glob := filepath.Join(filepath.Dir(setting.AppPath), "tests", "e2e", "*.test.e2e.js")
72+
paths, err := filepath.Glob(search_glob)
73+
if err != nil {
74+
t.Fatal(err)
75+
} else if len(paths) == 0 {
76+
t.Fatal(fmt.Errorf("No e2e tests found in %s", search_glob))
77+
}
78+
79+
// Create new test for each input file
80+
for _, path := range paths {
81+
_, filename := filepath.Split(path)
82+
testname := filename[:len(filename)-len(filepath.Ext(path))]
83+
84+
t.Run(testname, func(t *testing.T) {
85+
// Default 2 minute timeout
86+
onGiteaRun(t, func(*testing.T, *url.URL) {
87+
cmd := exec.Command("npx", "playwright", "test")
88+
cmd.Env = os.Environ()
89+
cmd.Env = append(cmd.Env, fmt.Sprintf("GITEA_URL=%s", setting.AppURL))
90+
var out bytes.Buffer
91+
cmd.Stdout = &out
92+
err := cmd.Run()
93+
if err != nil {
94+
// Currently colored output is conflicting. Using Printf until that is resolved.
95+
fmt.Printf("%v", out.String())
96+
log.Fatal("Playwright Failed: %s", err)
97+
} else {
98+
fmt.Printf("%v", out.String())
99+
}
100+
})
101+
})
102+
}
86103
}

0 commit comments

Comments
 (0)