diff --git a/test/progress.test.ts b/test/progress.test.ts index 0e70e0d6f..29d5dddf6 100644 --- a/test/progress.test.ts +++ b/test/progress.test.ts @@ -218,15 +218,21 @@ describe('progress reporter', () => { test('only one process-level signal handler installed across many reporters', () => { // Baseline: one handler already installed by prior tests in this file. const installedBefore = __signalHandlerInstalledForTest(); + // liveReporters is process-global: earlier test files in the same shard + // can leave a live entry behind (e.g. a production path that skips + // finish() on an error branch). Assert NET-zero leak from THIS test's + // lifecycles, not an absolute zero we don't control — same tolerance + // the handler assertion below already applies via `installedBefore`. + const liveBefore = __liveReporterCountForTest(); const { stream } = sink(false); for (let i = 0; i < 50; i++) { const p = createProgress({ mode: 'json', stream, minIntervalMs: 0, minItems: 1 }); p.start(`phase_${i}`, 1); p.finish(); } - // After 50 reporter lifecycles, still exactly one handler and zero leaked live entries. + // After 50 reporter lifecycles, still exactly one handler and zero NEWLY leaked live entries. expect(__signalHandlerInstalledForTest()).toBe(installedBefore || true); - expect(__liveReporterCountForTest()).toBe(0); + expect(__liveReporterCountForTest()).toBe(liveBefore); }); test('startHeartbeat() fires heartbeats and stop() clears', async () => {