mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-23 05:41:20 -08:00
fix(PKG-VAST-07): restore historical default factory calls
This commit is contained in:
1 parent
eb6402fdca
commit
fe5534ac24
20 files changed
+3706
-52
No files matched your search
@@ -47,13 +47,16 @@ for (const core of ['published-5.1.7', 'published', 'candidate']) {
|
||||
const label = `${core} / ${implementation.name}`
|
||||
test(`${label}: async SDK and callback gate real core registration and preserve requests`, async ({ page }, testInfo) => {
|
||||
await setup(page, core, implementation, testInfo, true)
|
||||
await page.evaluate(() => {
|
||||
await page.evaluate((useDefault) => {
|
||||
window.vastCalls = 0
|
||||
window.vastDone = false
|
||||
const gate = new Promise((resolve) => {
|
||||
window.finishVastCallback = resolve
|
||||
})
|
||||
window.vastRegistration = window.art.plugins.add(window.artplayerPluginVast(async (context) => {
|
||||
const factory = window.artplayerPluginVast
|
||||
if (useDefault && factory.default !== factory)
|
||||
throw new Error('Historical default calls must share the direct factory')
|
||||
window.vastRegistration = window.art.plugins.add((useDefault ? factory.default : factory)(async (context) => {
|
||||
window.vastContext = context
|
||||
window.vastCalls++
|
||||
await gate
|
||||
@@ -62,7 +65,7 @@ for (const core of ['published-5.1.7', 'published', 'candidate']) {
|
||||
})).then(() => {
|
||||
window.vastDone = true
|
||||
})
|
||||
})
|
||||
}, !implementation.historical)
|
||||
expect(await page.evaluate(() => ({ calls: window.vastCalls, players: window.vastSdk.state.players.length, registered: Object.hasOwn(window.art.plugins, 'artplayerPluginVast') }))).toEqual({ calls: 0, players: 0, registered: false })
|
||||
await page.evaluate(() => window.vastSdk.resolveLoad())
|
||||
await expect.poll(() => page.evaluate(() => window.vastCalls)).toBe(1)
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { Buffer } from 'node:buffer'
|
||||
import fs from 'node:fs'
|
||||
import process from 'node:process'
|
||||
// eslint-disable-next-line test/no-import-node-test -- Exercise real bundled SDK exports without external ad loading.
|
||||
import test from 'node:test'
|
||||
import vm from 'node:vm'
|
||||
import { compilePackage } from './helpers/load.js'
|
||||
|
||||
const code = process.env.ARTPLAYER_VAST_ARTIFACT
|
||||
? fs.readFileSync(process.env.ARTPLAYER_VAST_ARTIFACT, 'utf8')
|
||||
: await compilePackage('artplayer-plugin-vast', 'umd')
|
||||
|
||||
for (const format of ['commonjs', 'global', 'amd']) {
|
||||
test(`VAST ${format} preserves direct and historical default calls on one factory`, async () => {
|
||||
const window = {}
|
||||
const box = { window, CustomEvent }
|
||||
let factory
|
||||
if (format === 'commonjs') {
|
||||
box.module = { exports: {} }
|
||||
box.exports = box.module.exports
|
||||
}
|
||||
else if (format === 'amd') {
|
||||
box.define = (dependencies, create) => {
|
||||
if (typeof dependencies === 'function') {
|
||||
factory = dependencies()
|
||||
}
|
||||
else {
|
||||
assert.deepEqual([...dependencies], [])
|
||||
factory = create()
|
||||
}
|
||||
}
|
||||
box.define.amd = {}
|
||||
}
|
||||
vm.runInNewContext(code, box, { timeout: 5000 })
|
||||
factory ||= format === 'commonjs' ? box.module.exports : box.artplayerPluginVast || window.artplayerPluginVast
|
||||
assert.equal(typeof factory, 'function')
|
||||
assert.equal(factory.default, factory)
|
||||
assert.equal(factory.default.default, factory)
|
||||
assert.deepEqual(Object.getOwnPropertyDescriptor(factory, 'default'), { value: factory, writable: true, enumerable: true, configurable: true })
|
||||
for (const entry of [factory, factory.default]) {
|
||||
const pending = entry(() => assert.fail('A destroyed core cannot receive a callback'))({ isDestroy: true })
|
||||
assert.equal(typeof pending.then, 'function')
|
||||
const result = await pending
|
||||
assert.equal(result.name, 'artplayerPluginVast')
|
||||
assert.equal(result.destroy(), undefined)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
test('VAST ESM default import retains the same callable alias', async () => {
|
||||
const esm = process.env.ARTPLAYER_VAST_ESM_ARTIFACT
|
||||
? fs.readFileSync(process.env.ARTPLAYER_VAST_ESM_ARTIFACT, 'utf8')
|
||||
: await compilePackage('artplayer-plugin-vast', 'es')
|
||||
const { default: factory } = await import(`data:text/javascript;base64,${Buffer.from(esm).toString('base64')}`)
|
||||
assert.equal(typeof factory, 'function')
|
||||
assert.equal(factory.default, factory)
|
||||
const pending = factory.default()({ isDestroy: true })
|
||||
assert.equal(typeof pending.then, 'function')
|
||||
assert.equal((await pending).name, 'artplayerPluginVast')
|
||||
})
|
||||
@@ -5,6 +5,30 @@ import { deferred, vastEnvironment, vastImplementations } from './helpers/vast.j
|
||||
|
||||
const implementations = await vastImplementations()
|
||||
|
||||
test('VAST source default alias preserves deferred registration, requests and cleanup', async () => {
|
||||
const env = vastEnvironment(implementations.find(item => item.name === 'source'), { deferLoad: true })
|
||||
const host = env.host()
|
||||
assert.equal(env.factory.default, env.factory)
|
||||
const gate = deferred()
|
||||
const started = deferred()
|
||||
const pending = env.factory.default(async (context) => {
|
||||
started.resolve(context)
|
||||
await gate.promise
|
||||
context.playUrl('/alias.xml')
|
||||
})(host.art)
|
||||
assert.equal(typeof pending.then, 'function')
|
||||
assert.equal(env.state.players.length, 0)
|
||||
env.resolveLoad()
|
||||
await started.promise
|
||||
gate.resolve()
|
||||
const result = await pending
|
||||
assert.equal(result.name, 'artplayerPluginVast')
|
||||
assert.equal(env.state.players[0].requests[0].adTagUrl, '/alias.xml')
|
||||
host.art.destroy()
|
||||
assert.equal(host.parent.children.length, 0)
|
||||
assert.equal(env.state.players[0].destroyCalls, 1)
|
||||
})
|
||||
|
||||
for (const implementation of implementations) {
|
||||
const { name, published } = implementation
|
||||
test(`${name}: SDK resolution precedes callback and result waits for callback completion`, async () => {
|
||||
|
||||
Reference in new issue
Block a user