Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

fix(tests): memory leak

jubnl6cc8908f8793
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 78bc32304..20f1864b2 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 f356b07f7..fa55b7555 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<RouteResult | null>(null)
const [routeSegments, setRouteSegments] = useState<RouteSegment[]>([])
diff --git a/client/tests/integration/hooks/useRouteCalculation.test.ts b/client/tests/integration/hooks/useRouteCalculation.test.ts
index aa97af5be..637e39f82 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<typeof import('../../../src/components/Map/RouteCalculator')>();
+ 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');