diff --git a/test/sse-connect-timeout.test.ts b/test/sse-connect-timeout.test.ts index 0f6d3232..b379c2c8 100644 --- a/test/sse-connect-timeout.test.ts +++ b/test/sse-connect-timeout.test.ts @@ -194,6 +194,26 @@ describe('SSE connect timeout', () => { expect(app.reconnectAttempts).toBe(1); }); + it('a late error from a replaced EventSource leaves the connection that replaced it alone', () => { + const app = makeApp(); + app.connectSSE(); + const first = FakeEventSource.all[0]; + app.connectSSE(); // e.g. the user pressed Retry + const second = FakeEventSource.all[1]; + // A browser that still fires onerror on the closed first attempt. + first.fail(); + expect(app.eventSource).toBe(second); + expect(second.closed).toBe(false); + expect(app.reconnectAttempts).toBe(0); + // No retry was scheduled, and the second attempt keeps its own deadline. + vi.advanceTimersByTime(TIMEOUT - 1); + expect(FakeEventSource.all).toHaveLength(2); + expect(second.closed).toBe(false); + vi.advanceTimersByTime(1); + expect(second.closed).toBe(true); + expect(app.reconnectAttempts).toBe(1); + }); + it('connectSSE() while offline cancels the pending timer (the online event reconnects)', () => { const app = makeApp(); app.connectSSE(); diff --git a/test/tile-grid-sse-filter.test.ts b/test/tile-grid-sse-filter.test.ts index e444f3ee..b733a768 100644 --- a/test/tile-grid-sse-filter.test.ts +++ b/test/tile-grid-sse-filter.test.ts @@ -80,7 +80,11 @@ describe('the SSE filter while tiles own the terminal', () => { const app = readFileSync(resolve(import.meta.dirname, '../src/web/public/app.js'), 'utf8'); const start = app.indexOf('const _sseParams = new URLSearchParams('); expect(start).toBeGreaterThan(-1); - const block = app.slice(start, app.indexOf('this.eventSource = new EventSource(', start)); + // Both ends must be found: a missing end marker makes slice() take the + // rest of app.js, and the checks below would then pass on any text. + const end = app.indexOf('const eventSource = new EventSource(', start); + expect(end).toBeGreaterThan(start); + const block = app.slice(start, end); expect(block).toContain('this._sseFilterSessionId(this.activeSessionId)'); expect(block).not.toMatch(/set\('sessions', this\.activeSessionId\)/); });