mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-27 16:35:57 +00:00
In https://codeberg.org/forgejo/forgejo/pulls/7906#issuecomment-5511884, I noticed that the e2e tests were failing without obvious reasons. I was able to reproduce locally with Mobile Chrome, but the error doesn't make sense to me. So I tried to downgrade playwright to the previous version, and it works fine. I actually suspect a bug in playwright, but I currently lack the capacity to reach out to upstream with a reproducer (I also found conversation with the playwright team a little difficult, unless you have absolutely convincing arguments that the flakiness you observe is really their fault, which is very hard to prove). Tests pass with this version of playwright. In order to detect such cases earlier, I added a way to run all playwright tests (which I thought I had added with the changed files patch, but apparently forgot). All tests are triggered by an explicit label (but only after firing a next event, because the testing workflows don't listen to label changes) and when the PR title contains "playwright", which should cover at least renovate dependency updates of playwright and the axe framework (both contain playwright). Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8245 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Reviewed-by: Michael Kriese <michael.kriese@gmx.de> Reviewed-by: Beowulf <beowulf@beocode.eu> Co-authored-by: Otto Richter <git@otto.splvs.net> Co-committed-by: Otto Richter <git@otto.splvs.net>
120 lines
2.8 KiB
Go
120 lines
2.8 KiB
Go
// Copyright 2024 The Forgejo Authors. All rights reserved.
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package e2e
|
|
|
|
import (
|
|
"bufio"
|
|
"os"
|
|
"strings"
|
|
|
|
"forgejo.org/modules/log"
|
|
|
|
"github.com/gobwas/glob"
|
|
)
|
|
|
|
var (
|
|
changesetFiles []string
|
|
changesetAvailable bool
|
|
globalFullRun = false
|
|
)
|
|
|
|
func initChangedFiles() {
|
|
_, globalFullRun = os.LookupEnv("RUN_ALL")
|
|
if globalFullRun {
|
|
log.Info("Full run of all tests requested via RUN_ALL environment.")
|
|
return
|
|
}
|
|
var changes string
|
|
changes, changesetAvailable = os.LookupEnv("CHANGED_FILES")
|
|
// the output of the Action seems to actually contain \n and not a newline literal
|
|
changesetFiles = strings.Split(changes, `\n`)
|
|
log.Info("Only running tests covered by a subset of test files. Received the following list of CHANGED_FILES: %q", changesetFiles)
|
|
|
|
globalPatterns := []string{
|
|
// meta and config
|
|
"Makefile",
|
|
"playwright.config.ts",
|
|
".forgejo/workflows/testing.yml",
|
|
"tests/e2e/*.go",
|
|
"tests/e2e/shared/*",
|
|
// frontend files
|
|
"web_src/js/{index,utils}.*",
|
|
"web_src/css/{base,index}.css",
|
|
// templates and helpers
|
|
"templates/base/**",
|
|
"modules/templates/**",
|
|
}
|
|
fullRunPatterns := []glob.Glob{}
|
|
for _, expr := range globalPatterns {
|
|
fullRunPatterns = append(fullRunPatterns, glob.MustCompile(expr, '.', '/'))
|
|
}
|
|
|
|
for _, changedFile := range changesetFiles {
|
|
for _, pattern := range fullRunPatterns {
|
|
if pattern.Match(changedFile) {
|
|
globalFullRun = true
|
|
log.Info("Changed files match global test pattern, running all tests")
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func canSkipTest(testFile string) bool {
|
|
// run all tests when environment variable is not set or changes match global pattern
|
|
if !changesetAvailable || globalFullRun {
|
|
return false
|
|
}
|
|
|
|
for _, changedFile := range changesetFiles {
|
|
if strings.HasSuffix(testFile, changedFile) {
|
|
return false
|
|
}
|
|
for _, pattern := range getWatchPatterns(testFile) {
|
|
if pattern.Match(changedFile) {
|
|
return false
|
|
}
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
func getWatchPatterns(filename string) []glob.Glob {
|
|
file, err := os.Open(filename)
|
|
if err != nil {
|
|
log.Fatal(err.Error())
|
|
}
|
|
defer file.Close()
|
|
scanner := bufio.NewScanner(file)
|
|
|
|
watchSection := false
|
|
patterns := []glob.Glob{}
|
|
for scanner.Scan() {
|
|
line := scanner.Text()
|
|
// check for watch block
|
|
if strings.HasPrefix(line, "// @watch") {
|
|
if watchSection {
|
|
break
|
|
}
|
|
watchSection = true
|
|
}
|
|
if !watchSection {
|
|
continue
|
|
}
|
|
|
|
line = strings.TrimPrefix(line, "// ")
|
|
if line != "" {
|
|
globPattern, err := glob.Compile(line, '.', '/')
|
|
if err != nil {
|
|
log.Fatal("Invalid glob pattern '%s' (skipped): %v", line, err)
|
|
}
|
|
patterns = append(patterns, globPattern)
|
|
}
|
|
}
|
|
// if no watch block in file
|
|
if !watchSection {
|
|
patterns = append(patterns, glob.MustCompile("*"))
|
|
}
|
|
return patterns
|
|
}
|