mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-21 21:01:20 -08:00
test: [ENG-08] add verified TS coverage and paired performance reports
This commit is contained in:
1 parent
8ed0a5228c
commit
4a9a26d4fc
38 files changed
+24335
-61
No files matched your search
@@ -0,0 +1,24 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import fs from 'node:fs'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
// Reuse the frozen BASE-06 measurement body; only adapt transport and bundle URLs.
|
||||
const directory = fileURLToPath(new URL('../refactor/fixtures/', import.meta.url))
|
||||
function replaceOnce(source, before, after) {
|
||||
assert.equal(source.split(before).length, 2, `Performance fixture adapter drift: ${before}`)
|
||||
return source.replace(before, after)
|
||||
}
|
||||
|
||||
export function performanceScript() {
|
||||
const source = fs.readFileSync(`${directory}/performance.js`, 'utf8')
|
||||
return replaceOnce(source, 'const response = await fetch(\'/reports/performance\', { method: \'POST\', headers: { \'Content-Type\': \'application/json\' }, body: JSON.stringify(report) })', 'window.artplayerPerformanceReport = report; const response = { ok: true }')
|
||||
}
|
||||
|
||||
export function performanceHtml(variant) {
|
||||
assert(['published', 'candidate'].includes(variant), 'Invalid performance variant')
|
||||
let source = fs.readFileSync(`${directory}/performance.html`, 'utf8')
|
||||
source = replaceOnce(source, '/releases/artplayer/dist/artplayer.js', `/${variant}/artplayer.js`)
|
||||
source = replaceOnce(source, '/releases/artplayer-plugin-chapter/dist/artplayer-plugin-chapter.js', `/${variant}/artplayer-plugin-chapter.js`)
|
||||
source = replaceOnce(source, '/fixtures/performance.js', '/test/performance.js')
|
||||
return source.replaceAll('published performance baseline', `${variant} performance comparison`).replaceAll('Published performance and resource baseline', `${variant}: performance and resource comparison`)
|
||||
}
|
||||
Reference in new issue
Block a user