mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-09 03:27:43 -08:00
25 lines
1.5 KiB
JavaScript
25 lines
1.5 KiB
JavaScript
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`)
|
|
}
|