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.

rest-alert.native test: take the unhandledRejection listener off after each test

Duarte Santos9c847d30a5ca
diff --git a/frontend/src/lib/rest-alert.native.test.js b/frontend/src/lib/rest-alert.native.test.js
index 889b29cad..0f5c2f4ce 100644
--- a/frontend/src/lib/rest-alert.native.test.js
+++ b/frontend/src/lib/rest-alert.native.test.js
@@ -4,7 +4,7 @@
// the plugin is a Capacitor proxy that answers `then` with a native call that never settles, so
// it must never become the value of a promise (the Coach hang, #42): here that would hang every
// rest alert call.
-import { afterAll, beforeEach, describe, expect, it, vi } from 'vitest'
+import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { readFileSync } from 'node:fs'
const h = vi.hoisted(() => {
@@ -60,10 +60,10 @@ beforeEach(() => {
unhandled.length = 0
process.on('unhandledRejection', onUnhandled)
})
-afterAll(() => {
- process.off('unhandledRejection', onUnhandled)
- vi.unstubAllEnvs()
-})
+// One listener per test, taken off after it: added in every beforeEach and only removed in
+// afterAll, twenty of them tripped Node's MaxListeners warning in a full run.
+afterEach(() => { process.off('unhandledRejection', onUnhandled) })
+afterAll(() => { vi.unstubAllEnvs() })
describe('the rest alert in the iOS app', () => {
it('schedules the end on the phone, like Android, and rejects nothing', async () => {