fix(video): guard sourceless player play attempts

This commit is contained in:
2026-09-05 22:04:24 +08:00
parent 51dd38163d
commit 5a61e68a8c
2 changed files with 26 additions and 7 deletions
@@ -101,6 +101,20 @@ test('video cover: the player video fills and center-crops like the image cover'
);
});
test('video cover: play never runs against a sourceless player', () => {
const player = read('assets/js/video-player.js');
// toggle 必须先守卫无源状态,且 play() 的 promise 必须被捕获。
assert.match(player, /hasSource\s*=\s*function\s*\(\)\s*\{[^}]*currentSrc[^}]*\}/);
assert.match(player, /toggle\s*=\s*function\s*\(\)\s*\{\s*if\s*\(!this\.hasSource\(\)\)\s*return;/);
assert.match(player, /this\.video\.play\(\)\.catch\(function/);
// hls/flv CDN 脚本加载失败必须收敛,不得产生未处理 rejection。
assert.match(player, /loadScript\(HLS_SRC\)\.then\([\s\S]*?\}\)\.catch\(function/);
assert.match(player, /loadScript\(FLV_SRC\)\.then\([\s\S]*?\}\)\.catch\(function/);
// iframe 剧集归 runtime main 的 .switch-iframe 链路,播放器不得接管其选择器。
assert.doesNotMatch(player, /closest\('\.switch-video, \.switch-iframe'\)/);
assert.doesNotMatch(player, /querySelectorAll\('\.switch-video, \.switch-iframe'\)/);
});
test('resource singles get the cover leaf versioned, never via the aggregate @import', () => {
// 聚合文件的 @import 无版本号:浏览器会拿旧缓存(含已废弃的 .single-cover
// padding 规则)把封面高度链挤成 0,资源型文章封面直接空白。