loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request 'feat: Improve diffs generated by Forgejo' (#5110) from fnetx/better-diffs into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/5110
Reviewed-by: Gusted <gusted@noreply.codeberg.org>

Otto e5ea08b3 d6231261

+123 -7
+3 -1
.forgejo/workflows/e2e.yml
··· 22 22 go-version-file: "go.mod" 23 23 - run: | 24 24 apt-get -qq update 25 - apt-get -qq install -q sudo 25 + apt-get -qq install -q sudo git git-lfs 26 26 sed -i -e 's/%sudo.*/%sudo ALL=(ALL:ALL) NOPASSWD:ALL/' /etc/sudoers 27 27 git config --add safe.directory '*' 28 28 adduser --quiet --comment forgejo --disabled-password forgejo ··· 30 30 chown -R forgejo:forgejo . 31 31 - run: | 32 32 su forgejo -c 'make deps-frontend frontend deps-backend' 33 + - run: | 34 + su forgejo -c 'make backend' 33 35 - run: | 34 36 su forgejo -c 'make generate test-e2e-sqlite' 35 37 timeout-minutes: 40
+1
routers/web/repo/issue_content_history.go
··· 154 154 dmp := diffmatchpatch.New() 155 155 // `checklines=false` makes better diff result 156 156 diff := dmp.DiffMain(prevHistoryContentText, history.ContentText, false) 157 + diff = dmp.DiffCleanupSemantic(diff) 157 158 diff = dmp.DiffCleanupEfficiency(diff) 158 159 159 160 // use chroma to render the diff html
+1
services/gitdiff/highlightdiff.go
··· 97 97 convertedCodeB := hcd.ConvertToPlaceholders(string(highlightCodeB)) 98 98 99 99 diffs := diffMatchPatch.DiffMain(convertedCodeA, convertedCodeB, true) 100 + diffs = diffMatchPatch.DiffCleanupSemantic(diffs) 100 101 diffs = diffMatchPatch.DiffCleanupEfficiency(diffs) 101 102 102 103 for i := range diffs {
+1
tests/e2e/.eslintrc.yaml
··· 14 14 15 15 rules: 16 16 playwright/no-conditional-in-test: [0] 17 + playwright/no-conditional-expect: [0] 17 18 playwright/no-networkidle: [0] 18 19 playwright/no-skipped-test: [2, {allowConditional: true}] 19 20 playwright/prefer-comparison-matcher: [2]
+2 -1
tests/e2e/debugserver_test.go
··· 24 24 done := make(chan os.Signal, 1) 25 25 signal.Notify(done, syscall.SIGINT, syscall.SIGTERM) 26 26 27 - onGiteaRun(t, func(*testing.T, *url.URL) { 27 + onForgejoRun(t, func(*testing.T, *url.URL) { 28 + defer DeclareGitRepos(t)() 28 29 fmt.Println(setting.AppURL) 29 30 <-done 30 31 })
+83
tests/e2e/declare_repos_test.go
··· 1 + // Copyright 2024 The Forgejo Authors. All rights reserved. 2 + // SPDX-License-Identifier: GPL-3.0-or-later 3 + 4 + package e2e 5 + 6 + import ( 7 + "fmt" 8 + "strconv" 9 + "strings" 10 + "testing" 11 + "time" 12 + 13 + unit_model "code.gitea.io/gitea/models/unit" 14 + "code.gitea.io/gitea/models/unittest" 15 + user_model "code.gitea.io/gitea/models/user" 16 + "code.gitea.io/gitea/modules/git" 17 + files_service "code.gitea.io/gitea/services/repository/files" 18 + "code.gitea.io/gitea/tests" 19 + 20 + "github.com/stretchr/testify/assert" 21 + "github.com/stretchr/testify/require" 22 + ) 23 + 24 + type FileChanges [][]string 25 + 26 + // put your Git repo declarations in here 27 + // feel free to amend the helper function below or use the raw variant directly 28 + func DeclareGitRepos(t *testing.T) func() { 29 + var cleanupFunctions []func() 30 + cleanupFunctions = append(cleanupFunctions, newRepo(t, 2, "diff-test", FileChanges{ 31 + {"testfile", "hello", "hallo", "hola", "native", "ubuntu-latest", "- runs-on: ubuntu-latest", "- runs-on: debian-latest"}, 32 + })) 33 + 34 + return func() { 35 + for _, cleanup := range cleanupFunctions { 36 + cleanup() 37 + } 38 + } 39 + } 40 + 41 + func newRepo(t *testing.T, userID int64, repoName string, fileChanges FileChanges) func() { 42 + user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: userID}) 43 + somerepo, _, cleanupFunc := tests.CreateDeclarativeRepo(t, user, repoName, 44 + []unit_model.Type{unit_model.TypeCode, unit_model.TypeIssues}, nil, 45 + nil, 46 + ) 47 + 48 + for _, file := range fileChanges { 49 + changeLen := len(file) 50 + for i := 1; i < changeLen; i++ { 51 + operation := "create" 52 + if i != 1 { 53 + operation = "update" 54 + } 55 + resp, err := files_service.ChangeRepoFiles(git.DefaultContext, somerepo, user, &files_service.ChangeRepoFilesOptions{ 56 + Files: []*files_service.ChangeRepoFile{{ 57 + Operation: operation, 58 + TreePath: file[0], 59 + ContentReader: strings.NewReader(file[i]), 60 + }}, 61 + Message: fmt.Sprintf("Patch: %s-%s", file[0], strconv.Itoa(i)), 62 + OldBranch: "main", 63 + NewBranch: "main", 64 + Author: &files_service.IdentityOptions{ 65 + Name: user.Name, 66 + Email: user.Email, 67 + }, 68 + Committer: &files_service.IdentityOptions{ 69 + Name: user.Name, 70 + Email: user.Email, 71 + }, 72 + Dates: &files_service.CommitDateOptions{ 73 + Author: time.Now(), 74 + Committer: time.Now(), 75 + }, 76 + }) 77 + require.NoError(t, err) 78 + assert.NotEmpty(t, resp) 79 + } 80 + } 81 + 82 + return cleanupFunc 83 + }
+3 -2
tests/e2e/e2e_test.go
··· 37 37 graceful.InitManager(managerCtx) 38 38 defer cancel() 39 39 40 - tests.InitTest(false) 40 + tests.InitTest(true) 41 41 testE2eWebRoutes = routers.NormalRoutes() 42 42 43 43 os.Unsetenv("GIT_AUTHOR_NAME") ··· 102 102 103 103 t.Run(testname, func(t *testing.T) { 104 104 // Default 2 minute timeout 105 - onGiteaRun(t, func(*testing.T, *url.URL) { 105 + onForgejoRun(t, func(*testing.T, *url.URL) { 106 + defer DeclareGitRepos(t)() 106 107 thisTest := runArgs 107 108 thisTest = append(thisTest, path) 108 109 cmd := exec.Command(runArgs[0], thisTest...)
+26
tests/e2e/repo-code.test.e2e.js
··· 51 51 await page.goto(`${filePath}#L1-L100`); 52 52 await assertSelectedLines(page, ['1', '2', '3']); 53 53 }); 54 + 55 + test('Readable diff', async ({page}, workerInfo) => { 56 + // remove this when the test covers more (e.g. accessibility scans or interactive behaviour) 57 + test.skip(workerInfo.project.name !== 'firefox', 'This currently only tests the backend-generated HTML code and it is not necessary to test with multiple browsers.'); 58 + const expectedDiffs = [ 59 + {id: 'testfile-2', removed: 'e', added: 'a'}, 60 + {id: 'testfile-3', removed: 'allo', added: 'ola'}, 61 + {id: 'testfile-4', removed: 'hola', added: 'native'}, 62 + {id: 'testfile-5', removed: 'native', added: 'ubuntu-latest'}, 63 + {id: 'testfile-6', added: '- runs-on: '}, 64 + {id: 'testfile-7', removed: 'ubuntu', added: 'debian'}, 65 + ]; 66 + for (const thisDiff of expectedDiffs) { 67 + const response = await page.goto('/user2/diff-test/commits/branch/main'); 68 + await expect(response?.status()).toBe(200); // Status OK 69 + await page.getByText(`Patch: ${thisDiff.id}`).click(); 70 + if (thisDiff.removed) { 71 + await expect(page.getByText(thisDiff.removed, {exact: true})).toHaveClass(/removed-code/); 72 + await expect(page.getByText(thisDiff.removed, {exact: true})).toHaveCSS('background-color', 'rgb(252, 165, 165)'); 73 + } 74 + if (thisDiff.added) { 75 + await expect(page.getByText(thisDiff.added, {exact: true})).toHaveClass(/added-code/); 76 + await expect(page.getByText(thisDiff.added, {exact: true})).toHaveCSS('background-color', 'rgb(134, 239, 172)'); 77 + } 78 + } 79 + });
+3 -3
tests/e2e/utils_e2e_test.go
··· 17 17 "github.com/stretchr/testify/require" 18 18 ) 19 19 20 - func onGiteaRunTB(t testing.TB, callback func(testing.TB, *url.URL), prepare ...bool) { 20 + func onForgejoRunTB(t testing.TB, callback func(testing.TB, *url.URL), prepare ...bool) { 21 21 if len(prepare) == 0 || prepare[0] { 22 22 defer tests.PrepareTestEnv(t, 1)() 23 23 } ··· 49 49 callback(t, u) 50 50 } 51 51 52 - func onGiteaRun(t *testing.T, callback func(*testing.T, *url.URL), prepare ...bool) { 53 - onGiteaRunTB(t, func(t testing.TB, u *url.URL) { 52 + func onForgejoRun(t *testing.T, callback func(*testing.T, *url.URL), prepare ...bool) { 53 + onForgejoRunTB(t, func(t testing.TB, u *url.URL) { 54 54 callback(t.(*testing.T), u) 55 55 }, prepare...) 56 56 }