From 62723b37e8524d44e96ffc56f6790b1dca28c5b2 Mon Sep 17 00:00:00 2001 From: jubnl Date: Tue, 23 Jun 2026 18:02:35 +0200 Subject: [PATCH] fix(tests): memory leak --- .github/workflows/test.yml | 20 +++++++++---------- client/src/hooks/useRouteCalculation.ts | 4 +++- .../hooks/useRouteCalculation.test.ts | 17 +++++++++------- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 78bc3230..20f1864b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -126,14 +126,12 @@ jobs: run: cd client && npm run lint:pages - name: Run tests - # Two separate OOM sources, both avoided here: - # 1) The v8 coverage report phase (source-map remapping over 150+ files) - # OOMs even with a 12 GB heap, so coverage is NOT collected in CI. - # 2) Each forks worker runs ~38 files and jsdom/MSW state accumulates - # past Node's default ~4 GB, so workers get extra heap. - # Run coverage locally with `npm run test:coverage`. - # TODO(#1258): re-enable coverage in CI via test sharding or the istanbul - # provider, then restore the artifact upload. - env: - NODE_OPTIONS: --max-old-space-size=8192 - run: cd client && npm run test + run: cd client && npm run test:coverage + + - name: Upload coverage + if: success() + uses: actions/upload-artifact@v6 + with: + name: frontend-coverage + path: client/coverage/ + retention-days: 7 diff --git a/client/src/hooks/useRouteCalculation.ts b/client/src/hooks/useRouteCalculation.ts index f356b07f..fa55b755 100644 --- a/client/src/hooks/useRouteCalculation.ts +++ b/client/src/hooks/useRouteCalculation.ts @@ -9,12 +9,14 @@ import type { RouteSegment, RouteResult, Accommodation } from '../types' const TRANSPORT_TYPES = ['flight', 'train', 'bus', 'car', 'taxi', 'bicycle', 'cruise', 'ferry', 'transport_other'] +const NO_ACCOMMODATIONS: Accommodation[] = [] + /** * Manages route calculation state for a selected day. Extracts geo-coded waypoints from * day assignments, draws a straight-line route immediately, then upgrades it to real OSRM * road geometry with per-segment durations. Aborts in-flight requests when the day changes. */ -export function useRouteCalculation(tripStore: TripStoreState, selectedDayId: number | null, enabled: boolean = true, profile: 'driving' | 'walking' | 'cycling' = 'driving', accommodations: Accommodation[] = []) { +export function useRouteCalculation(tripStore: TripStoreState, selectedDayId: number | null, enabled: boolean = true, profile: 'driving' | 'walking' | 'cycling' = 'driving', accommodations: Accommodation[] = NO_ACCOMMODATIONS) { const [route, setRoute] = useState<[number, number][][] | null>(null) const [routeInfo, setRouteInfo] = useState(null) const [routeSegments, setRouteSegments] = useState([]) diff --git a/client/tests/integration/hooks/useRouteCalculation.test.ts b/client/tests/integration/hooks/useRouteCalculation.test.ts index aa97af5b..637e39f8 100644 --- a/client/tests/integration/hooks/useRouteCalculation.test.ts +++ b/client/tests/integration/hooks/useRouteCalculation.test.ts @@ -6,13 +6,16 @@ import { buildAssignment, buildPlace } from '../../helpers/factories'; import type { TripStoreState } from '../../../src/store/tripStore'; import type { RouteSegment } from '../../../src/types'; -// Mock the RouteCalculator module to avoid real OSRM fetch calls -vi.mock('../../../src/components/Map/RouteCalculator', () => ({ - calculateRouteWithLegs: vi.fn(), - calculateRoute: vi.fn(), - optimizeRoute: vi.fn((waypoints: unknown[]) => waypoints), - generateGoogleMapsUrl: vi.fn(), -})); +vi.mock('../../../src/components/Map/RouteCalculator', async (importActual) => { + const actual = await importActual(); + return { + ...actual, + calculateRouteWithLegs: vi.fn(), + calculateRoute: vi.fn(), + optimizeRoute: vi.fn((waypoints: unknown[]) => waypoints), + generateGoogleMapsUrl: vi.fn(), + }; +}); const { calculateRouteWithLegs } = await import('../../../src/components/Map/RouteCalculator');