'use strict'; // #146 web-player fix — the no-change-refresh branch-selection decision. This is the unit // the refresh handler consults to decide whether to re-attach the media surface. It is the // smallest testable piece of the "no new content lost the video but not the audio" fix. const { test } = require('node:test'); const assert = require('node:assert/strict'); const PlayerMediaHealth = require('../lib/player-media-health'); const { needsReattach, shouldShowIdle } = PlayerMediaHealth; // Guards the define-vs-call class of bug: every method the player calls on // PlayerMediaHealth must actually be exported (a missing one throws "X is not a function" // at the browser call site and aborts the socket handler). test('module surface: needsReattach AND shouldShowIdle are both exported functions', () => { assert.equal(typeof PlayerMediaHealth.needsReattach, 'function'); assert.equal(typeof PlayerMediaHealth.shouldShowIdle, 'function'); }); const video = (o) => ({ isPlaying: true, hasCurrentItem: true, itemKind: 'video', videoEl: o, surfaceAttached: true }); test('healthy attached+live video on a no-change refresh -> NO re-attach (no flicker)', () => { assert.equal(needsReattach(video({ attached: true, ended: false, errored: false })), false); }); test('THE BUG: a detached-but-playing