1
// Copyright 2022 The Gitea Authors. All rights reserved.
2
// SPDX-License-Identifier: MIT
4
// This is primarily coped from /tests/integration/integration_test.go
5
// TODO: Move common functions to shared file
20
"code.gitea.io/gitea/models/unittest"
21
"code.gitea.io/gitea/modules/graceful"
22
"code.gitea.io/gitea/modules/log"
23
"code.gitea.io/gitea/modules/setting"
24
"code.gitea.io/gitea/modules/testlogger"
25
"code.gitea.io/gitea/modules/util"
26
"code.gitea.io/gitea/modules/web"
27
"code.gitea.io/gitea/routers"
28
"code.gitea.io/gitea/tests"
31
var testE2eWebRoutes *web.Route
33
func TestMain(m *testing.M) {
34
defer log.GetManager().Close()
36
managerCtx, cancel := context.WithCancel(context.Background())
37
graceful.InitManager(managerCtx)
41
testE2eWebRoutes = routers.NormalRoutes()
43
os.Unsetenv("GIT_AUTHOR_NAME")
44
os.Unsetenv("GIT_AUTHOR_EMAIL")
45
os.Unsetenv("GIT_AUTHOR_DATE")
46
os.Unsetenv("GIT_COMMITTER_NAME")
47
os.Unsetenv("GIT_COMMITTER_EMAIL")
48
os.Unsetenv("GIT_COMMITTER_DATE")
50
err := unittest.InitFixtures(
51
unittest.FixturesOptions{
52
Dir: filepath.Join(filepath.Dir(setting.AppPath), "models/fixtures/"),
56
fmt.Printf("Error initializing test database: %v\n", err)
62
testlogger.WriterCloser.Reset()
64
if err = util.RemoveAll(setting.Indexer.IssuePath); err != nil {
65
fmt.Printf("util.RemoveAll: %v\n", err)
68
if err = util.RemoveAll(setting.Indexer.RepoPath); err != nil {
69
fmt.Printf("Unable to remove repo indexer: %v\n", err)
76
// TestE2e should be the only test e2e necessary. It will collect all "*.test.e2e.js" files in this directory and build a test for each.
77
func TestE2e(t *testing.T) {
78
// Find the paths of all e2e test files in test directory.
79
searchGlob := filepath.Join(filepath.Dir(setting.AppPath), "tests", "e2e", "*.test.e2e.js")
80
paths, err := filepath.Glob(searchGlob)
83
} else if len(paths) == 0 {
84
t.Fatal(fmt.Errorf("No e2e tests found in %s", searchGlob))
87
runArgs := []string{"npx", "playwright", "test"}
89
// To update snapshot outputs
90
if _, set := os.LookupEnv("ACCEPT_VISUAL"); set {
91
runArgs = append(runArgs, "--update-snapshots")
94
// Create new test for each input file
95
for _, path := range paths {
96
_, filename := filepath.Split(path)
97
testname := filename[:len(filename)-len(filepath.Ext(path))]
99
t.Run(testname, func(t *testing.T) {
100
// Default 2 minute timeout
101
onGiteaRun(t, func(*testing.T, *url.URL) {
102
cmd := exec.Command(runArgs[0], runArgs...)
103
cmd.Env = os.Environ()
104
cmd.Env = append(cmd.Env, fmt.Sprintf("GITEA_URL=%s", setting.AppURL))
105
var stdout, stderr bytes.Buffer
110
// Currently colored output is conflicting. Using Printf until that is resolved.
111
fmt.Printf("%v", stdout.String())
112
fmt.Printf("%v", stderr.String())
113
log.Fatal("Playwright Failed: %s", err)
115
fmt.Printf("%v", stdout.String())