From 39f37e5ad95bbf98c409aff47a1c939260cdea46 Mon Sep 17 00:00:00 2001 From: SivertEikrem Date: Tue, 24 Nov 2026 12:32:56 +0100 Subject: [PATCH] test(frontend): load the lazy pages once before the route tests (#103) --- frontend/src/app/App.test.tsx | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/frontend/src/app/App.test.tsx b/frontend/src/app/App.test.tsx index 6e8bb37..bd6ef64 100644 --- a/frontend/src/app/App.test.tsx +++ b/frontend/src/app/App.test.tsx @@ -1,5 +1,5 @@ import { Suspense } from 'react'; -import { describe, expect, it } from 'vitest'; +import { beforeAll, describe, expect, it } from 'vitest'; import { render, screen } from '@testing-library/react'; import { MockedProvider } from '@apollo/client/testing/react'; import { MemoryRouter } from 'react-router'; @@ -26,11 +26,23 @@ function renderRoute(route: string) { ); } -/** The pages are lazy, and the import takes longer when the whole test suite runs at once. */ const findHeading = (name: string) => screen.findByRole('heading', { level: 1, name }, { timeout: 5000 }); describe('AppRoutes', () => { + // Build the lazy pages once, with plenty of time. The tests then check the routes, + // not how fast the machine is when the whole suite runs at once. + beforeAll(async () => { + await Promise.all([ + import('../features/search/SearchPage'), + import('../features/wine/WinePage'), + import('../features/my/MyPage'), + import('../features/my/MyListPage'), + import('../features/my/MyReviewsPage'), + import('../features/auth/AccountPage'), + ]); + }, 30_000); + it.each([ ['/finnes-ikke', 'Fant ikke siden'], ['/vin/abc', 'Fant ikke vinen'], @@ -55,4 +67,4 @@ describe('AppRoutes', () => { renderRoute('/sok'); expect(await findHeading('Utforsk viner')).toBeInTheDocument(); }); -}); +}); \ No newline at end of file