Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

BodyMap tests: import the geometry before the first render, not inside the wait

TheophileDiot5370e2184c23
diff --git a/frontend/src/components/BodyMap.test.jsx b/frontend/src/components/BodyMap.test.jsx
index 1cc2b4375..cc328bb3a 100644
--- a/frontend/src/components/BodyMap.test.jsx
+++ b/frontend/src/components/BodyMap.test.jsx
@@ -1,7 +1,7 @@
// @vitest-environment happy-dom
import React, { act } from 'react'
import { createRoot } from 'react-dom/client'
-import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
import BodyMap, { BodyMapLegend } from './BodyMap.jsx'
globalThis.IS_REACT_ACT_ENVIRONMENT = true
@@ -9,6 +9,14 @@ globalThis.IS_REACT_ACT_ENVIRONMENT = true
let container
let root
+// BodyMap fetches its ~90 KB of geometry with a dynamic import on first render, and the
+// waitFor below allows one second for it. That is ample once the module is in the ESM
+// registry and not always ample when it is not: on a loaded CI runner the first map render
+// in this file paid the cold import and timed out, while every later test passed on the
+// component's warm CACHE. Import it here so the wait covers rendering, not module loading,
+// and the file stops depending on how fast the machine is.
+beforeAll(() => import('../lib/body-paths.js'))
+
beforeEach(() => {
container = document.createElement('div')
document.body.appendChild(container)