mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-06-30 18:46:00 +00:00
fix(tests): memory leak
This commit is contained in:
@@ -126,14 +126,12 @@ jobs:
|
|||||||
run: cd client && npm run lint:pages
|
run: cd client && npm run lint:pages
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
# Two separate OOM sources, both avoided here:
|
run: cd client && npm run test:coverage
|
||||||
# 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.
|
- name: Upload coverage
|
||||||
# 2) Each forks worker runs ~38 files and jsdom/MSW state accumulates
|
if: success()
|
||||||
# past Node's default ~4 GB, so workers get extra heap.
|
uses: actions/upload-artifact@v6
|
||||||
# Run coverage locally with `npm run test:coverage`.
|
with:
|
||||||
# TODO(#1258): re-enable coverage in CI via test sharding or the istanbul
|
name: frontend-coverage
|
||||||
# provider, then restore the artifact upload.
|
path: client/coverage/
|
||||||
env:
|
retention-days: 7
|
||||||
NODE_OPTIONS: --max-old-space-size=8192
|
|
||||||
run: cd client && npm run test
|
|
||||||
|
|||||||
@@ -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 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
|
* 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
|
* 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.
|
* 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 [route, setRoute] = useState<[number, number][][] | null>(null)
|
||||||
const [routeInfo, setRouteInfo] = useState<RouteResult | null>(null)
|
const [routeInfo, setRouteInfo] = useState<RouteResult | null>(null)
|
||||||
const [routeSegments, setRouteSegments] = useState<RouteSegment[]>([])
|
const [routeSegments, setRouteSegments] = useState<RouteSegment[]>([])
|
||||||
|
|||||||
@@ -6,13 +6,16 @@ import { buildAssignment, buildPlace } from '../../helpers/factories';
|
|||||||
import type { TripStoreState } from '../../../src/store/tripStore';
|
import type { TripStoreState } from '../../../src/store/tripStore';
|
||||||
import type { RouteSegment } from '../../../src/types';
|
import type { RouteSegment } from '../../../src/types';
|
||||||
|
|
||||||
// Mock the RouteCalculator module to avoid real OSRM fetch calls
|
vi.mock('../../../src/components/Map/RouteCalculator', async (importActual) => {
|
||||||
vi.mock('../../../src/components/Map/RouteCalculator', () => ({
|
const actual = await importActual<typeof import('../../../src/components/Map/RouteCalculator')>();
|
||||||
calculateRouteWithLegs: vi.fn(),
|
return {
|
||||||
calculateRoute: vi.fn(),
|
...actual,
|
||||||
optimizeRoute: vi.fn((waypoints: unknown[]) => waypoints),
|
calculateRouteWithLegs: vi.fn(),
|
||||||
generateGoogleMapsUrl: vi.fn(),
|
calculateRoute: vi.fn(),
|
||||||
}));
|
optimizeRoute: vi.fn((waypoints: unknown[]) => waypoints),
|
||||||
|
generateGoogleMapsUrl: vi.fn(),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
const { calculateRouteWithLegs } = await import('../../../src/components/Map/RouteCalculator');
|
const { calculateRouteWithLegs } = await import('../../../src/components/Map/RouteCalculator');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user