mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-21 06:20:31 +00:00
test: run frontend unit tests in browsers (#38860)
Run them in headless [vitest browser mode](https://vitest.dev/guide/browser/) in chromium and firefox. Similar UX than current tests, it's about 5 times as slow (goes from 1s to 5s on my machine), but definitely worth it as it removes all happy-dom problems. --------- Signed-off-by: silverwind <me@silverwind.io>
This commit is contained in:
@@ -1,8 +1,15 @@
|
||||
// there could be different "testing" concepts, for example: backend's "setting.IsInTesting"
|
||||
// even if backend is in testing mode, frontend could be complied in production mode
|
||||
// so this function only checks if the frontend is in unit testing mode (usually from *.test.ts files)
|
||||
export function isInFrontendUnitTest() {
|
||||
return import.meta.env.MODE === 'test';
|
||||
import {onTestFinished} from 'vitest';
|
||||
|
||||
/** Record and block navigations, as a real browser forbids stubbing "window.location" */
|
||||
export function captureNavigations() {
|
||||
const navigations: Array<{url: string, type: NavigationType}> = [];
|
||||
const onNavigate = (e: NavigateEvent) => {
|
||||
navigations.push({url: e.destination.url, type: e.navigationType});
|
||||
e.preventDefault();
|
||||
};
|
||||
window.navigation.addEventListener('navigate', onNavigate);
|
||||
onTestFinished(() => window.navigation.removeEventListener('navigate', onNavigate));
|
||||
return navigations;
|
||||
}
|
||||
|
||||
/** strip common indentation from a string and trim it */
|
||||
|
||||
Reference in New Issue
Block a user