Skip to content
Merged
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
10 changes: 8 additions & 2 deletions modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ var (
CfgProvider ConfigProvider
IsWindows bool

// IsInTesting indicates whether the testing is running. A lot of unreliable code causes a lot of nonsense error logs during testing
// TODO: this is only a temporary solution, we should make the test code more reliable
// IsInTesting indicates whether the testing is running (unit test or integration test). It can be used for:
// * Skip nonsense error logs during testing caused by unreliable code (TODO: this is only a temporary solution, we should make the test code more reliable)
// * Panic in dev or testing mode to make the problem more obvious and easier to debug
// * Mock some functions or options to make testing easier (eg: session store, time, URL detection, etc.)
IsInTesting = false
)

Expand Down Expand Up @@ -57,6 +59,10 @@ func IsRunUserMatchCurrentUser(runUser string) (string, bool) {
return currentUser, runUser == currentUser
}

func IsInE2eTesting() bool {
return os.Getenv("GITEA_TEST_E2E") == "true"
}

// PrepareAppDataPath creates app data directory if necessary
func PrepareAppDataPath() error {
// FIXME: There are too many calls to MkdirAll in old code. It is incorrect.
Expand Down
2 changes: 1 addition & 1 deletion routers/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -1740,7 +1740,7 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
m.Get("/swagger.v1.json", SwaggerV1Json)
}

if !setting.IsProd {
if !setting.IsProd || setting.IsInE2eTesting() {
m.Group("/devtest", func() {
m.Any("", devtest.List)
m.Any("/fetch-action-test", devtest.FetchActionTest)
Expand Down
2 changes: 1 addition & 1 deletion templates/devtest/relative-time.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="tw-grid tw-grid-cols-3 tw-gap-4">
<div>
<h2>Relative (auto)</h2>
<div>now: <relative-time datetime="{{.TimeNow.Format "2006-01-02T15:04:05Z07:00"}}"></relative-time></div>
<div>now: <relative-time data-testid="relative-time-now" datetime="{{.TimeNow.Format "2006-01-02T15:04:05Z07:00"}}"></relative-time></div>
<div>3m ago: <relative-time datetime="{{.TimePast3m.Format "2006-01-02T15:04:05Z07:00"}}"></relative-time></div>
<div>3h ago: <relative-time datetime="{{.TimePast3h.Format "2006-01-02T15:04:05Z07:00"}}"></relative-time></div>
<div>1d ago: <relative-time datetime="{{.TimePast1d.Format "2006-01-02T15:04:05Z07:00"}}"></relative-time></div>
Expand Down
10 changes: 10 additions & 0 deletions tests/e2e/relative-time.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {test, expect} from '@playwright/test';
import {assertNoJsError} from './utils.ts';

test('relative-time renders without errors', async ({page}) => {
await page.goto('/devtest/relative-time');
const relativeTime = page.getByTestId('relative-time-now');
await expect(relativeTime).toHaveAttribute('data-tooltip-content', /.+/);
await expect(relativeTime).toHaveText('now');
await assertNoJsError(page);
});
4 changes: 4 additions & 0 deletions tests/e2e/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ export async function login(page: Page, username = env.GITEA_TEST_E2E_USER, pass
await expect(page.getByRole('link', {name: 'Sign In'})).toBeHidden();
}

export async function assertNoJsError(page: Page) {
await expect(page.locator('.js-global-error')).toHaveCount(0);
}

export async function logout(page: Page) {
await page.context().clearCookies(); // workaround issues related to fomantic dropdown
await page.goto('/');
Expand Down
1 change: 1 addition & 0 deletions tools/test-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ LEVEL = Warn
EOF

export GITEA_WORK_DIR="$WORK_DIR"
export GITEA_TEST_E2E=true

# Start Gitea server
echo "Starting Gitea server on port $FREE_PORT (workdir: $WORK_DIR)..."
Expand Down
10 changes: 5 additions & 5 deletions web_src/js/webcomponents/relative-time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,12 @@ class RelativeTime extends HTMLElement {

get #lang(): string {
const lang = this.closest('[lang]')?.getAttribute('lang');
if (!lang) return navigator.language;
try {
return new Intl.Locale(lang).toString();
} catch {
return navigator.language;
if (lang) {
try {
return new Intl.Locale(lang).toString();
} catch { /* invalid locale, fall through */ }
}
return navigator.language ?? 'en';
}

get second(): 'numeric' | '2-digit' | undefined {
Expand Down