mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-26 17:01:20 -08:00
test(refactor): [BASE-HARNESS-01] add isolated published API fixture
This commit is contained in:
1 parent
1d705b3056
commit
3c759f14c2
9 files changed
+283
-7
No files matched your search
@@ -0,0 +1,14 @@
|
||||
# 发布基线浏览器夹具
|
||||
|
||||
`node refactor/scripts/browser-server.mjs` 在 127.0.0.1:8083 启动独立测试服务;ARTPLAYER_TEST_PORT 可更换端口。它不启动或修改用户的 Chrome,也不占用 docs 的 8082 开发服务。
|
||||
|
||||
- `/fixtures/api.html` 加载固定核心/chapter tarball 的真实 JS,准备捕获描述符、默认配置、utils/子系统/插件形状及基础调用。
|
||||
- `/releases/<name>/<member>` 只读取 releases.json 明确登记的成员;启动时核对 archive 完整性,不使用未编译源码或 CDN latest。
|
||||
- `/assets/sample/` 读取本仓库样本,支持普通 bytes 范围请求。当前服务用于最小基线;不是完整 ENG-05 故障注入或 HTTP Range 兼容实现,不支持后缀/多段 Range。
|
||||
- 页面将 `public-api` 报告发送给同源 `/reports/api`,服务器保存 refactor/.cache/reports/api.json。最多 1 MiB;其他 Origin 和未知写入路径失败。临时报告不能自动覆盖冻结快照。
|
||||
|
||||
运行 `node --test refactor/scripts/browser-server.test.mjs` 验证真实 HTTP 服务返回原始 JS 字节、样本范围和路由隔离;`node --check refactor/fixtures/api.js` 只检查脚本语法。两者不能证明页面能在浏览器运行。
|
||||
|
||||
2026-09-10:Chrome 连接服务连续失败,用户要求先继续其他任务;api.html 尚未实际执行,没有 API 快照或浏览器通过记录。BASE-02 保持 blocked;恢复连接后打开完整 URL,确认页面 PASS、没有错误,再核对报告和来源、生成持久基线。
|
||||
|
||||
夹具与报告路径由基线任务维护;ENG-05 可复用并扩充受控等待、媒体错误和正式自动化。api.js 依据已核对源码设计断言,真实发布行为如有不同应调查并记录,不能修改断言来盲目通过。
|
||||
@@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<meta charset="utf-8">
|
||||
<title>ArtPlayer published API baseline</title>
|
||||
<style>.player { width: 640px; height: 360px; } pre { white-space: pre-wrap; }</style>
|
||||
<h1>Published API contract</h1>
|
||||
<p id="status">Capturing...</p>
|
||||
<div class="player"></div>
|
||||
<pre id="result"></pre>
|
||||
<script src="/releases/artplayer/dist/artplayer.js"></script>
|
||||
<script src="/releases/artplayer-plugin-chapter/dist/artplayer-plugin-chapter.js"></script>
|
||||
<script src="/fixtures/api.js"></script>
|
||||
</html>
|
||||
@@ -0,0 +1,74 @@
|
||||
/* global Artplayer, artplayerPluginChapter */
|
||||
(async () => {
|
||||
const report = { kind: 'public-api', environment: { userAgent: navigator.userAgent }, checks: [], errors: [] }
|
||||
const check = (name, result) => {
|
||||
report.checks.push({ name, passed: Boolean(result) })
|
||||
if (!result) throw new Error(name)
|
||||
}
|
||||
function descriptors(object) {
|
||||
return Object.fromEntries(Object.getOwnPropertyNames(object).sort().map((name) => {
|
||||
const d = Object.getOwnPropertyDescriptor(object, name)
|
||||
return [name, {
|
||||
enumerable: d.enumerable,
|
||||
configurable: d.configurable,
|
||||
...(Object.hasOwn(d, 'value') ? { writable: d.writable, type: typeof d.value } : { get: typeof d.get, set: typeof d.set }),
|
||||
}]
|
||||
}))
|
||||
}
|
||||
function valueOf(input) {
|
||||
if (typeof input === 'function') return { $function: true }
|
||||
if (input === undefined) return { $undefined: true }
|
||||
if (typeof input === 'number' && !Number.isFinite(input)) return { $number: String(input) }
|
||||
if (Array.isArray(input)) return input.map(valueOf)
|
||||
if (input && typeof input === 'object') return Object.fromEntries(Object.keys(input).sort().map(key => [key, valueOf(input[key])]))
|
||||
return input
|
||||
}
|
||||
let art
|
||||
try {
|
||||
check('published core version', Artplayer.version === '5.4.0')
|
||||
const defaults = valueOf(Artplayer.option)
|
||||
art = new Artplayer({ container: '.player', url: '/assets/sample/video.mp4', muted: true, plugins: [artplayerPluginChapter()] })
|
||||
check('constructor registers exact instance', Artplayer.instances.includes(art))
|
||||
check('native media element exposed', art.video instanceof HTMLVideoElement)
|
||||
check('chapter registered synchronously', art.plugins.artplayerPluginChapter?.name === 'artplayerPluginChapter')
|
||||
const plugin = { name: 'baselineProbe', ping: () => 'pong' }
|
||||
const added = art.plugins.add(() => plugin)
|
||||
check('plugins.add returns synchronous registry', added === art.plugins)
|
||||
check('plugin result methods callable', art.plugins.baselineProbe.ping() === 'pong')
|
||||
let received = 0
|
||||
const handler = amount => { received += amount }
|
||||
check('on is chainable', art.on('baseline:event', handler) === art)
|
||||
art.emit('baseline:event', 3)
|
||||
art.off('baseline:event', handler)
|
||||
art.emit('baseline:event', 7)
|
||||
check('custom event on/emit/off', received === 3)
|
||||
const integrations = {}
|
||||
for (const name of ['template', 'events', 'controls', 'setting', 'contextmenu', 'layers', 'plugins', 'storage', 'subtitle', 'i18n']) {
|
||||
integrations[name] = { own: descriptors(art[name]), prototype: descriptors(Object.getPrototypeOf(art[name])) }
|
||||
}
|
||||
report.snapshot = {
|
||||
static: descriptors(Artplayer),
|
||||
prototype: descriptors(Artplayer.prototype),
|
||||
emitterPrototype: descriptors(Object.getPrototypeOf(Artplayer.prototype)),
|
||||
defaults,
|
||||
config: valueOf(Artplayer.config),
|
||||
utilityDescriptors: descriptors(Artplayer.utils),
|
||||
instance: descriptors(art),
|
||||
chapterFactory: descriptors(artplayerPluginChapter),
|
||||
chapterResult: descriptors(art.plugins.artplayerPluginChapter),
|
||||
integrations,
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
report.errors.push(error.message)
|
||||
}
|
||||
finally {
|
||||
if (art) {
|
||||
art.destroy(true)
|
||||
report.checks.push({ name: 'instance cleanup', passed: !Artplayer.instances.includes(art) })
|
||||
}
|
||||
}
|
||||
const response = await fetch('/reports/api', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(report) })
|
||||
document.getElementById('status').textContent = response.ok && !report.errors.length && report.checks.every(c => c.passed) ? 'PASS: published API captured' : 'FAIL: inspect report'
|
||||
document.getElementById('result').textContent = JSON.stringify({ environment: report.environment, checks: report.checks, errors: report.errors }, null, 2)
|
||||
})()
|
||||
Reference in new issue
Block a user