Skip to content

Add e2e install testing #30241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions templates/install.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,19 @@
<div class="reinstall-confirm">
<div class="ui checkbox">
<label>{{ctx.Locale.Tr "install.reinstall_confirm_check_1"}}</label>
<input name="reinstall_confirm_first" type="checkbox">
<input name="reinstall_confirm_first" data-testid="reinstall_confirm_first" type="checkbox">
</div>
</div>
<div class="reinstall-confirm">
<div class="ui checkbox">
<label>{{ctx.Locale.Tr "install.reinstall_confirm_check_2"}}</label>
<input name="reinstall_confirm_second" type="checkbox">
<input name="reinstall_confirm_second" data-testid="reinstall_confirm_second" type="checkbox">
</div>
</div>
<div class="reinstall-confirm">
<div class="ui checkbox">
<label>{{ctx.Locale.Tr "install.reinstall_confirm_check_3"}}</label>
<input name="reinstall_confirm_third" type="checkbox">
<input name="reinstall_confirm_third" data-testid="reinstall_confirm_third" type="checkbox">
</div>
</div>
</div>
Expand Down
26 changes: 21 additions & 5 deletions tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"os"
"os/exec"
"path/filepath"
"strings"
"testing"

"code.gitea.io/gitea/models/unittest"
Expand All @@ -25,6 +26,7 @@ import (
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/routers"
"code.gitea.io/gitea/routers/install"
"code.gitea.io/gitea/tests"
)

Expand All @@ -38,7 +40,6 @@ func TestMain(m *testing.M) {
defer cancel()

tests.InitTest(false)
testE2eWebRoutes = routers.NormalRoutes()

os.Unsetenv("GIT_AUTHOR_NAME")
os.Unsetenv("GIT_AUTHOR_EMAIL")
Expand Down Expand Up @@ -84,22 +85,37 @@ func TestE2e(t *testing.T) {
t.Fatal(fmt.Errorf("No e2e tests found in %s", searchGlob))
}

runArgs := []string{"npx", "playwright", "test"}
// Also search subdirectories (go globbing does not support the "**" wildcard)
searchGlobSubdir := filepath.Join(filepath.Dir(setting.AppPath), "tests", "e2e", "*", "*.test.e2e.js")
pathsSubdir, _ := filepath.Glob(searchGlobSubdir)

runCommand := []string{"npx", "playwright", "test"}

// To update snapshot outputs
if _, set := os.LookupEnv("ACCEPT_VISUAL"); set {
runArgs = append(runArgs, "--update-snapshots")
runCommand = append(runCommand, "--update-snapshots")
}

// Create new test for each input file
for _, path := range paths {
for _, path := range append(paths, pathsSubdir...) {
_, filename := filepath.Split(path)
testname := filename[:len(filename)-len(filepath.Ext(path))]

runArgs := runCommand
runArgs = append(runArgs, path)

// Load install routes for tests inside that folder
if strings.Contains(path, "install/") {
testE2eWebRoutes = install.Routes()
setting.InstallLock = false
} else {
testE2eWebRoutes = routers.NormalRoutes()
}

t.Run(testname, func(t *testing.T) {
// Default 2 minute timeout
onGiteaRun(t, func(*testing.T, *url.URL) {
cmd := exec.Command(runArgs[0], runArgs...)
cmd := exec.Command(runArgs[0], runArgs[1:]...)
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, fmt.Sprintf("GITEA_URL=%s", setting.AppURL))
var stdout, stderr bytes.Buffer
Expand Down
3 changes: 3 additions & 0 deletions tests/e2e/install/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# End to End Install Tests

Tests in this directory will be run against the Gitea web installer
47 changes: 47 additions & 0 deletions tests/e2e/install/install.test.e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// @ts-check
import {test, expect} from '@playwright/test';

test('Load Install Page', async ({page}) => {
const response = await page.goto('/');

await expect(response?.status()).toBe(200); // Status OK
await expect(page).toHaveTitle(
/^Installation - Gitea: Git with a cup of tea\s*$/,
);
});

test('Perform Install', async ({page}) => {
const response = await page.goto('/');

await expect(response?.status()).toBe(200); // Status OK
await expect(page).toHaveTitle(
/^Installation - Gitea: Git with a cup of tea\s*$/,
);

await page.getByRole('combobox').click();

await page.getByRole('option', {name: 'SQLite3'}).click();

// Past this point, testing the install page functionality runs into a few issues:
// - The existing fixtures/setup don't handle various db stuff that install
// performs (clobbers subsequent tests)
// - Existing .ini and db files trigger the "reinstall" dialogue rather than normal install
// - Successfully reinstalling seems to work, but the backend will drop the "install" routes
// and is not setup to start the "normal" routes (thats something the CLI handles)
// - Playwright will run all browsers simultaneously which leads to race conditions between the test runs
// Those are probably all resolvable but might take a larger re-work of the fixtures/setup logic

// await page.getByRole('button', {name: "Install Gitea"}).click();

// await expect(page.getByTestId('reinstall_confirm_first'), 'performs database checks').toBeVisible();

// await page.waitForLoadState('domcontentloaded');

// await page.getByTestId('reinstall_confirm_first').check();
// await page.getByTestId('reinstall_confirm_second').check();
// await page.getByTestId('reinstall_confirm_third').check();

// await page.getByRole('button', {name: "Install Gitea"}).click();

// await page.getByRole('link', { name: 'Loading…' });
});