mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-15 00:56:16 -08:00
fix(vast): [PKG-VAST-03] preserve npm initialization with explicit workspace mode
This commit is contained in:
1 parent
314a1c3163
commit
c162d2b3b3
27 files changed
+13189
-191
No files matched your search
+34
-13
@@ -8,11 +8,12 @@ const implementations = await vastImplementations()
|
||||
async function setup(page, core, implementation, testInfo, deferLoad = false) {
|
||||
await page.goto(`/test/player.html?core=${core}`)
|
||||
await page.addScriptTag({ content: `window.createVastSdk = ${createVastSdk.toString()};` })
|
||||
await page.evaluate((deferLoad) => {
|
||||
await page.evaluate(({ deferLoad, options }) => {
|
||||
window.vastSdk = window.createVastSdk({ deferLoad })
|
||||
window.vastOptions = options
|
||||
window.google = { ima: window.vastSdk.ima }
|
||||
window.art = new window.Artplayer({ container: '.player', url: '/test/pattern.mp4', muted: true })
|
||||
}, deferLoad)
|
||||
}, { deferLoad, options: implementation.options })
|
||||
await page.addScriptTag({ content: `(() => {
|
||||
const module = { exports: {} };
|
||||
const exports = module.exports;
|
||||
@@ -23,7 +24,7 @@ async function setup(page, core, implementation, testInfo, deferLoad = false) {
|
||||
${implementation.code}
|
||||
window.artplayerPluginVast = module.exports.default || module.exports;
|
||||
})();` })
|
||||
await testInfo.attach('vast-inputs', { contentType: 'application/json', body: JSON.stringify({ core, implementation: implementation.name, sha256: hash(implementation.code), sdk: 'controlled wrapper recorder, no IMA execution' }) })
|
||||
await testInfo.attach('vast-inputs', { contentType: 'application/json', body: JSON.stringify({ core, implementation: implementation.name, options: implementation.options || {}, sha256: hash(implementation.code), sdk: 'controlled wrapper recorder, no IMA execution' }) })
|
||||
}
|
||||
|
||||
test.afterEach(async ({ page }, testInfo) => {
|
||||
@@ -62,7 +63,7 @@ for (const core of ['published-5.1.7', 'published', 'candidate']) {
|
||||
await gate
|
||||
context.playUrl('/test/ad-tag.xml')
|
||||
context.playRes('<VAST/>')
|
||||
})).then(() => {
|
||||
}, window.vastOptions)).then(() => {
|
||||
window.vastDone = true
|
||||
})
|
||||
}, !implementation.historical)
|
||||
@@ -71,6 +72,19 @@ for (const core of ['published-5.1.7', 'published', 'candidate']) {
|
||||
await expect.poll(() => page.evaluate(() => window.vastCalls)).toBe(1)
|
||||
expect(await page.evaluate(() => window.vastDone)).toBe(false)
|
||||
expect(await page.evaluate(() => Object.hasOwn(window.art.plugins, 'artplayerPluginVast'))).toBe(false)
|
||||
const beforeRequests = await page.evaluate(() => {
|
||||
const context = window.vastContext
|
||||
const player = window.vastSdk.state.players[0]
|
||||
return {
|
||||
players: window.vastSdk.state.players.length,
|
||||
allocated: context.imaPlayer !== null,
|
||||
publishedAliases: !!player && context.$container === player.args[2] && context.id === player.args[2].id,
|
||||
writablePlayer: Object.getOwnPropertyDescriptor(context, 'imaPlayer').writable === true,
|
||||
preloading: player?.args[3].enablePreloading === true,
|
||||
background: player?.args[2].style.backgroundColor || '',
|
||||
}
|
||||
})
|
||||
expect(beforeRequests).toEqual({ players: implementation.published ? 1 : 0, allocated: !!implementation.published, publishedAliases: !!implementation.published, writablePlayer: !!implementation.published, preloading: false, background: '' })
|
||||
await page.evaluate(() => window.finishVastCallback())
|
||||
await page.evaluate(() => window.vastRegistration)
|
||||
const result = await page.evaluate(() => ({
|
||||
@@ -88,7 +102,7 @@ for (const core of ['published-5.1.7', 'published', 'candidate']) {
|
||||
const result = await page.evaluate(async () => {
|
||||
const failure = new Error('controlled SDK failure')
|
||||
let calls = 0
|
||||
const registration = window.art.plugins.add(window.artplayerPluginVast(() => calls++))
|
||||
const registration = window.art.plugins.add(window.artplayerPluginVast(() => calls++, window.vastOptions))
|
||||
const observed = registration.catch(error => error === failure)
|
||||
window.vastSdk.rejectLoad(failure)
|
||||
return { sameFailure: await observed, calls, players: window.vastSdk.state.players.length, registered: Object.hasOwn(window.art.plugins, 'artplayerPluginVast') }
|
||||
@@ -109,7 +123,7 @@ for (const core of ['published-5.1.7', 'published', 'candidate']) {
|
||||
await page.evaluate(async () => {
|
||||
await window.art.plugins.add(window.artplayerPluginVast((context) => {
|
||||
window.vastContext = context
|
||||
}))
|
||||
}, window.vastOptions))
|
||||
window.vastContext.playUrl('/first.xml')
|
||||
})
|
||||
const container = page.locator('[id^="art-vast-"]')
|
||||
@@ -154,7 +168,7 @@ for (const core of ['published-5.1.7', 'published', 'candidate']) {
|
||||
window.vastRegistration = window.art.plugins.add(window.artplayerPluginVast((context) => {
|
||||
window.vastCalls++
|
||||
context.playUrl('/late.xml')
|
||||
}))
|
||||
}, window.vastOptions))
|
||||
window.art.destroy()
|
||||
window.vastSdk.resolveLoad()
|
||||
})
|
||||
@@ -173,7 +187,7 @@ for (const core of ['published-5.1.7', 'published', 'candidate']) {
|
||||
await setup(page, core, implementation, testInfo, true)
|
||||
const state = await page.evaluate(async () => {
|
||||
let calls = 0
|
||||
const registration = window.art.plugins.add(window.artplayerPluginVast(() => calls++))
|
||||
const registration = window.art.plugins.add(window.artplayerPluginVast(() => calls++, window.vastOptions))
|
||||
window.art.destroy()
|
||||
window.vastSdk.resolveLoad()
|
||||
await registration
|
||||
@@ -187,14 +201,21 @@ for (const core of ['published-5.1.7', 'published', 'candidate']) {
|
||||
await page.evaluate(async () => {
|
||||
await window.art.plugins.add(window.artplayerPluginVast((context) => {
|
||||
window.vastContext = context
|
||||
}))
|
||||
}, window.vastOptions))
|
||||
window.vastContext.playUrl('/one.xml')
|
||||
const first = window.vastContext.imaPlayer
|
||||
window.lateVastEvents = [...first.listeners.values()].flatMap(values => [...values])
|
||||
first.emit('AdStarted')
|
||||
})
|
||||
const container = page.locator('[id^="art-vast-"]')
|
||||
await expect(container).toBeVisible()
|
||||
const container = page.locator(implementation.published ? '[id^="art-"]' : '[id^="art-vast-"]')
|
||||
await expect(container).toHaveCount(1)
|
||||
expect(await page.evaluate(() => window.lateVastEvents.length)).toBe(implementation.published ? 0 : 4)
|
||||
// The published wrapper delegates overlay visibility to the real SDK.
|
||||
// This recorder does not implement that SDK behavior.
|
||||
if (implementation.published)
|
||||
await expect(container).toBeHidden()
|
||||
else
|
||||
await expect(container).toBeVisible()
|
||||
await page.evaluate(() => {
|
||||
window.art.plugins.artplayerPluginVast.destroy()
|
||||
window.vastContext.playUrl('/two.xml')
|
||||
@@ -218,11 +239,11 @@ for (const core of ['published-5.1.7', 'published', 'candidate']) {
|
||||
const registration = window.art.plugins.add(window.artplayerPluginVast((context) => {
|
||||
context.init()
|
||||
return Promise.reject(failure)
|
||||
}))
|
||||
}, window.vastOptions))
|
||||
return { sameError: await registration.catch(error => error === failure), destroys: window.vastSdk.state.players[0].destroyCalls, coreDestroyed: window.art.isDestroy }
|
||||
})
|
||||
expect(result).toEqual({ sameError: true, destroys: 1, coreDestroyed: false })
|
||||
await expect(page.locator('[id^="art-vast-"]')).toHaveCount(0)
|
||||
await expect(page.locator(implementation.published ? '[id^="art-"]' : '[id^="art-vast-"]')).toHaveCount(0)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,8 @@ export async function vastImplementations() {
|
||||
const { outputFiles } = await build({ entryPoints: [resolveSource('packages/artplayer-plugin-vast/src/index')], bundle: true, write: false, format: 'cjs', platform: 'browser', external: ['@glomex/vast-ima-player'] })
|
||||
const frozen = async source => (await transform(source, { loader: 'js', format: 'cjs', target: 'es2020' })).code
|
||||
return [
|
||||
{ name: 'source', code: outputFiles[0].text },
|
||||
{ name: 'source', published: true, code: outputFiles[0].text },
|
||||
{ name: 'source-workspace', options: { compatibility: 'workspace-1.2' }, code: outputFiles[0].text },
|
||||
{ name: 'published-1.0.0-source', historical: true, published: true, code: await frozen(readMember(archive, 'package/src/index.js').toString()) },
|
||||
{ name: 'frozen-workspace-1.2.0', historical: true, code: await frozen(contract.sources.get('packages/artplayer-plugin-vast/src/index.js')) },
|
||||
]
|
||||
|
||||
@@ -0,0 +1,181 @@
|
||||
import assert from 'node:assert/strict'
|
||||
// eslint-disable-next-line test/no-import-node-test -- Published and candidate callback contracts use controlled SDKs.
|
||||
import test from 'node:test'
|
||||
import { deferred, vastEnvironment, vastImplementations } from './helpers/vast.js'
|
||||
|
||||
const implementations = await vastImplementations()
|
||||
const source = implementations.find(item => item.name === 'source')
|
||||
|
||||
for (const implementation of implementations.filter(item => item.name === 'source' || item.published)) {
|
||||
test(`${implementation.name}: npm callback receives an allocated SDK and original data fields without changing SDK defaults`, async () => {
|
||||
const env = vastEnvironment(implementation)
|
||||
const host = env.host()
|
||||
let context
|
||||
await env.factory((value) => {
|
||||
context = value
|
||||
assert.equal(env.state.players.length, 1)
|
||||
assert.equal(value.imaPlayer, env.state.players[0])
|
||||
assert.equal(value.$container, host.parent.children[0])
|
||||
assert.equal(value.id, value.$container.id)
|
||||
assert.match(value.id, /^art-\d/)
|
||||
value.imaPlayer.addEventListener('custom', () => {})
|
||||
for (const key of ['imaPlayer', 'id', '$container']) {
|
||||
const descriptor = Object.getOwnPropertyDescriptor(value, key)
|
||||
assert.equal(descriptor.get, undefined)
|
||||
assert.equal(descriptor.writable, true)
|
||||
assert.equal(descriptor.enumerable, true)
|
||||
assert.equal(descriptor.configurable, true)
|
||||
}
|
||||
})(host.art)
|
||||
const player = env.state.players[0]
|
||||
assert.equal(player.args[3].enablePreloading, undefined)
|
||||
assert.equal(player.args[3].restoreCustomPlaybackStateOnAdBreakComplete, undefined)
|
||||
assert.equal(context.$container.style.backgroundColor, undefined)
|
||||
assert.equal(context.$container.style.pointerEvents, undefined)
|
||||
context.playUrl('/first.xml')
|
||||
player.emit('AdStarted')
|
||||
context.playUrl('/second.xml')
|
||||
assert.equal(player.requests.length, 2, 'The published wrapper forwards both explicit requests')
|
||||
})
|
||||
}
|
||||
|
||||
test('VAST explicit workspace mode retains lazy initialization and caller option identities', async () => {
|
||||
const env = vastEnvironment(source)
|
||||
const host = env.host()
|
||||
let context
|
||||
await env.factory((value) => {
|
||||
context = value
|
||||
assert.equal(value.imaPlayer, null)
|
||||
assert.equal(value.container, null)
|
||||
assert.equal(env.state.players.length, 0)
|
||||
value.playerOptions.custom = 'before initialization'
|
||||
}, { compatibility: 'workspace-1.2' })(host.art)
|
||||
const player = context.init()
|
||||
assert.equal(player.args[3], context.adsRenderingSettings)
|
||||
assert.equal(player.args[4], context.playerOptions)
|
||||
assert.equal(player.args[4].custom, 'before initialization')
|
||||
assert.equal(player.args[3].enablePreloading, true)
|
||||
assert.equal(player.args[3].restoreCustomPlaybackStateOnAdBreakComplete, true)
|
||||
assert.match(context.container.id, /^art-vast-/)
|
||||
context.playUrl('/first.xml')
|
||||
player.emit('AdStarted')
|
||||
context.playUrl('/suppressed.xml')
|
||||
assert.equal(player.requests.length, 1)
|
||||
host.art.destroy()
|
||||
assert.equal(player.destroyCalls, 1)
|
||||
assert.equal(context.imaPlayer, null)
|
||||
})
|
||||
|
||||
test('VAST default initializes even without a callback and releases on core destruction', async () => {
|
||||
const env = vastEnvironment(source)
|
||||
const host = env.host()
|
||||
await env.factory()(host.art)
|
||||
assert.equal(env.state.players.length, 1)
|
||||
host.art.destroy()
|
||||
assert.equal(env.state.players[0].destroyCalls, 1)
|
||||
assert.equal(host.parent.children.length, 0)
|
||||
})
|
||||
|
||||
test('VAST eager constructor failure rejects registration before callback and removes owned DOM', async () => {
|
||||
const failure = new Error('eager allocation failed')
|
||||
const env = vastEnvironment(source, { constructError: failure })
|
||||
const host = env.host()
|
||||
let called = false
|
||||
await assert.rejects(env.factory(() => {
|
||||
called = true
|
||||
})(host.art), error => error === failure)
|
||||
assert.equal(called, false)
|
||||
assert.equal(host.parent.children.length, 0)
|
||||
assert.equal(host.listeners.get('destroy').size, 0)
|
||||
})
|
||||
|
||||
test('VAST eager allocation reentered by core destruction never invokes callback', async () => {
|
||||
const env = vastEnvironment(source)
|
||||
const host = env.host()
|
||||
env.state.onConstruct = () => host.art.destroy()
|
||||
let called = false
|
||||
await env.factory(() => {
|
||||
called = true
|
||||
})(host.art)
|
||||
assert.equal(called, false)
|
||||
assert.equal(env.state.players[0].destroyCalls, 1)
|
||||
assert.equal(host.parent.children.length, 0)
|
||||
})
|
||||
|
||||
test('VAST eager callback cancellation releases the live SDK without rewriting its published snapshots', async () => {
|
||||
const env = vastEnvironment(source)
|
||||
const host = env.host()
|
||||
const gate = deferred()
|
||||
const started = deferred()
|
||||
let context
|
||||
const pending = env.factory(async (value) => {
|
||||
context = value
|
||||
started.resolve()
|
||||
await gate.promise
|
||||
value.playUrl('/too-late.xml')
|
||||
})(host.art)
|
||||
await started.promise
|
||||
const player = context.imaPlayer
|
||||
assert(player)
|
||||
const container = context.$container
|
||||
host.art.destroy()
|
||||
gate.resolve()
|
||||
await pending
|
||||
assert.equal(context.imaPlayer, player)
|
||||
assert.equal(context.$container, container)
|
||||
assert.equal(container.parentNode, null)
|
||||
assert.equal(player.destroyCalls, 1)
|
||||
assert.equal(player.requests.length, 0)
|
||||
assert.equal(context.init(), null)
|
||||
})
|
||||
|
||||
test('VAST default callback rejection releases allocation and keeps the original failure', async () => {
|
||||
for (const destroyError of [null, new Error('secondary cleanup')]) {
|
||||
const env = vastEnvironment(source, { destroyError })
|
||||
const host = env.host()
|
||||
const failure = new Error('callback failed')
|
||||
let context
|
||||
await assert.rejects(env.factory((value) => {
|
||||
context = value
|
||||
return Promise.reject(failure)
|
||||
})(host.art), error => error === failure)
|
||||
assert.equal(env.state.players[0].destroyCalls, 1)
|
||||
assert.equal(host.parent.children.length, 0)
|
||||
assert.equal(host.listeners.get('destroy').size, 0)
|
||||
assert.equal(context.init(), null)
|
||||
}
|
||||
})
|
||||
|
||||
test('VAST default explicit destroy and recreation update aliases without reusing disposed resources', async () => {
|
||||
const env = vastEnvironment(source)
|
||||
const host = env.host()
|
||||
let context
|
||||
const result = await env.factory((value) => {
|
||||
context = value
|
||||
})(host.art)
|
||||
const first = context.imaPlayer
|
||||
const firstId = context.id
|
||||
result.destroy()
|
||||
result.destroy()
|
||||
assert.equal(context.imaPlayer, first)
|
||||
assert.equal(first.destroyCalls, 1)
|
||||
context.playUrl('/fresh.xml')
|
||||
assert.notEqual(context.imaPlayer, first)
|
||||
assert.notEqual(context.id, firstId)
|
||||
assert.equal(context.$container, context.container)
|
||||
assert.equal(context.imaPlayer.requests[0].adTagUrl, '/fresh.xml')
|
||||
assert.equal(host.parent.children.length, 1)
|
||||
host.art.destroy()
|
||||
assert.deepEqual(env.state.players.map(player => player.destroyCalls), [1, 1])
|
||||
})
|
||||
|
||||
test('VAST rejects an unknown mode before loading the SDK and snapshots a valid mode once', async () => {
|
||||
const env = vastEnvironment(source)
|
||||
assert.throws(() => env.factory(undefined, { compatibility: 'typo' }), /Unsupported VAST compatibility mode/)
|
||||
assert.equal(env.state.loads, 0)
|
||||
const options = { compatibility: 'workspace-1.2' }
|
||||
const attach = env.factory(undefined, options)
|
||||
options.compatibility = 'changed later'
|
||||
await attach(env.host().art)
|
||||
assert.equal(env.state.players.length, 0)
|
||||
})
|
||||
+16
-16
@@ -3,7 +3,7 @@ import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
import { deferred, vastEnvironment, vastImplementations } from './helpers/vast.js'
|
||||
|
||||
const candidates = (await vastImplementations()).filter(item => !item.historical)
|
||||
const candidates = (await vastImplementations()).filter(item => !item.historical && !item.published)
|
||||
|
||||
for (const implementation of candidates) {
|
||||
const { name } = implementation
|
||||
@@ -14,7 +14,7 @@ for (const implementation of candidates) {
|
||||
const result = await env.factory((value) => {
|
||||
context = value
|
||||
value.playUrl('/first.xml')
|
||||
})(host.art)
|
||||
}, implementation.options)(host.art)
|
||||
const player = context.imaPlayer
|
||||
host.art.destroy()
|
||||
result.destroy()
|
||||
@@ -32,7 +32,7 @@ for (const implementation of candidates) {
|
||||
const env = vastEnvironment(implementation, { deferLoad: true })
|
||||
const host = env.host()
|
||||
let calls = 0
|
||||
const attaching = env.factory(() => calls++)(host.art)
|
||||
const attaching = env.factory(() => calls++, implementation.options)(host.art)
|
||||
assert.equal(host.listeners.get('destroy').size, 1)
|
||||
host.art.destroy()
|
||||
env.resolveLoad()
|
||||
@@ -47,7 +47,7 @@ for (const implementation of candidates) {
|
||||
const env = vastEnvironment(implementation)
|
||||
const host = env.host()
|
||||
host.art.destroy()
|
||||
await env.factory(() => assert.fail('Unexpected callback'))(host.art)
|
||||
await env.factory(() => assert.fail('Unexpected callback'), implementation.options)(host.art)
|
||||
assert.equal(env.state.loads, 0)
|
||||
assert.equal(host.listeners.size, 0)
|
||||
})
|
||||
@@ -55,7 +55,7 @@ for (const implementation of candidates) {
|
||||
test(`${name}: SDK rejection unregisters the pending core listener`, async () => {
|
||||
const env = vastEnvironment(implementation, { deferLoad: true })
|
||||
const host = env.host()
|
||||
const attaching = env.factory()(host.art)
|
||||
const attaching = env.factory(undefined, implementation.options)(host.art)
|
||||
const failure = new Error('load failure')
|
||||
const rejected = assert.rejects(attaching, error => error === failure)
|
||||
env.rejectLoad(failure)
|
||||
@@ -73,7 +73,7 @@ for (const implementation of candidates) {
|
||||
context = value
|
||||
context.init()
|
||||
throw failure
|
||||
})(host.art), error => error === failure)
|
||||
}, implementation.options)(host.art), error => error === failure)
|
||||
assert.equal(env.state.players[0].destroyCalls, 1)
|
||||
assert.equal(host.parent.children.length, 0)
|
||||
assert.equal(host.listeners.get('destroy').size, 0)
|
||||
@@ -94,7 +94,7 @@ for (const implementation of candidates) {
|
||||
await finish.promise
|
||||
context.playUrl('/late.xml')
|
||||
assert.equal(context.init(), null)
|
||||
})(host.art)
|
||||
}, implementation.options)(host.art)
|
||||
await started.promise
|
||||
host.art.destroy()
|
||||
finish.resolve()
|
||||
@@ -113,7 +113,7 @@ for (const implementation of candidates) {
|
||||
let context
|
||||
await env.factory((value) => {
|
||||
context = value
|
||||
})(host.art)
|
||||
}, implementation.options)(host.art)
|
||||
assert.throws(() => context.init(), error => error === failure)
|
||||
assert.equal(host.parent.children.length, 0)
|
||||
assert.equal(context.imaPlayer, null)
|
||||
@@ -133,7 +133,7 @@ for (const implementation of candidates) {
|
||||
const attach = env.factory((context) => {
|
||||
context.init()
|
||||
contexts.push(context)
|
||||
})
|
||||
}, implementation.options)
|
||||
const one = env.host()
|
||||
const two = env.host()
|
||||
const [result] = await Promise.all([attach(one.art), attach(two.art)])
|
||||
@@ -150,7 +150,7 @@ for (const implementation of candidates) {
|
||||
let context
|
||||
const result = await env.factory((value) => {
|
||||
context = value
|
||||
})(env.host().art)
|
||||
}, implementation.options)(env.host().art)
|
||||
context.playUrl('/first.xml')
|
||||
context.imaPlayer.emit('AdStarted')
|
||||
result.destroy()
|
||||
@@ -164,7 +164,7 @@ for (const implementation of candidates) {
|
||||
let context
|
||||
const result = await env.factory((value) => {
|
||||
context = value
|
||||
})(env.host().art)
|
||||
}, implementation.options)(env.host().art)
|
||||
const first = context.init()
|
||||
const late = [...first.listeners.values()].flatMap(listeners => [...listeners])
|
||||
result.destroy()
|
||||
@@ -184,7 +184,7 @@ for (const implementation of candidates) {
|
||||
let context
|
||||
const result = await env.factory((value) => {
|
||||
context = value
|
||||
})(host.art)
|
||||
}, implementation.options)(host.art)
|
||||
const player = context.init()
|
||||
assert.throws(() => result.destroy(), error => error === failure)
|
||||
assert.equal(context.container, null)
|
||||
@@ -202,7 +202,7 @@ for (const implementation of candidates) {
|
||||
let context
|
||||
await env.factory((value) => {
|
||||
context = value
|
||||
})(host.art)
|
||||
}, implementation.options)(host.art)
|
||||
context.playUrl('/cancelled.xml', { get extra() {
|
||||
host.art.destroy()
|
||||
return 1
|
||||
@@ -217,7 +217,7 @@ for (const implementation of candidates) {
|
||||
let context
|
||||
const result = await env.factory((value) => {
|
||||
context = value
|
||||
})(env.host().art)
|
||||
}, implementation.options)(env.host().art)
|
||||
context.playUrl('/stale.xml', { get extra() {
|
||||
result.destroy()
|
||||
context.init()
|
||||
@@ -237,7 +237,7 @@ for (const implementation of candidates) {
|
||||
let context
|
||||
await env.factory((value) => {
|
||||
context = value
|
||||
})(host.art)
|
||||
}, implementation.options)(host.art)
|
||||
env.state[hook] = () => host.art.destroy()
|
||||
assert.equal(context.init(), null)
|
||||
assert.equal(env.state.players[0].destroyCalls, 1)
|
||||
@@ -251,7 +251,7 @@ for (const implementation of candidates) {
|
||||
let context
|
||||
const result = await env.factory((value) => {
|
||||
context = value
|
||||
})(env.host().art)
|
||||
}, implementation.options)(env.host().art)
|
||||
context.init()
|
||||
env.state.onDestroy = () => {
|
||||
assert.equal(context.init(), null)
|
||||
|
||||
+21
-21
@@ -42,7 +42,7 @@ for (const implementation of implementations) {
|
||||
calls++
|
||||
started.resolve(context)
|
||||
await finish.promise
|
||||
})(host.art)
|
||||
}, implementation.options)(host.art)
|
||||
attaching.then(() => {
|
||||
settled = true
|
||||
})
|
||||
@@ -63,7 +63,7 @@ for (const implementation of implementations) {
|
||||
const env = vastEnvironment(implementation, { deferLoad: true })
|
||||
const host = env.host()
|
||||
let calls = 0
|
||||
const attaching = env.factory(() => calls++)(host.art)
|
||||
const attaching = env.factory(() => calls++, implementation.options)(host.art)
|
||||
const failure = new Error('SDK unavailable')
|
||||
const rejected = assert.rejects(attaching, error => error === failure)
|
||||
env.rejectLoad(failure)
|
||||
@@ -75,7 +75,7 @@ for (const implementation of implementations) {
|
||||
|
||||
test(`${name}: absent callback remains accepted at runtime`, async () => {
|
||||
const env = vastEnvironment(implementation)
|
||||
const result = await env.factory()(env.host().art)
|
||||
const result = await env.factory(undefined, implementation.options)(env.host().art)
|
||||
assert.equal(result.name, 'artplayerPluginVast')
|
||||
})
|
||||
|
||||
@@ -84,7 +84,7 @@ for (const implementation of implementations) {
|
||||
let context
|
||||
await env.factory((value) => {
|
||||
context = value
|
||||
})(env.host().art)
|
||||
}, implementation.options)(env.host().art)
|
||||
assert.equal(context.playUrl('https://example.test/ad.xml'), undefined)
|
||||
assert.equal(context.playRes('<VAST version="3.0"/>'), undefined)
|
||||
const [player] = env.state.players
|
||||
@@ -97,7 +97,7 @@ for (const implementation of implementations) {
|
||||
test(`${name}: one attach factory creates independent contexts, players and requests`, async () => {
|
||||
const env = vastEnvironment(implementation)
|
||||
const contexts = []
|
||||
const attach = env.factory(context => contexts.push(context))
|
||||
const attach = env.factory(context => contexts.push(context), implementation.options)
|
||||
const one = env.host()
|
||||
const two = env.host()
|
||||
await Promise.all([attach(one.art), attach(two.art)])
|
||||
@@ -117,7 +117,7 @@ for (const implementation of implementations) {
|
||||
let context
|
||||
await env.factory((value) => {
|
||||
context = value
|
||||
})(env.host().art)
|
||||
}, implementation.options)(env.host().art)
|
||||
assert.throws(() => context.playUrl('/ad.xml'), error => error === failure)
|
||||
env.state.playError = null
|
||||
context.playUrl('/retry.xml')
|
||||
@@ -132,7 +132,7 @@ for (const implementation of implementations) {
|
||||
if (asynchronous)
|
||||
return Promise.reject(failure)
|
||||
throw failure
|
||||
})(env.host().art)
|
||||
}, implementation.options)(env.host().art)
|
||||
await assert.rejects(attaching, error => error === failure)
|
||||
}
|
||||
})
|
||||
@@ -146,7 +146,7 @@ for (const implementation of implementations) {
|
||||
let context
|
||||
await env.factory((value) => {
|
||||
context = value
|
||||
})(host.art)
|
||||
}, implementation.options)(host.art)
|
||||
assert.equal(context.imaPlayer, null)
|
||||
assert.equal(context.container, null)
|
||||
context.playerOptions.custom = 'caller option'
|
||||
@@ -166,7 +166,7 @@ for (const implementation of implementations) {
|
||||
let context
|
||||
await env.factory((value) => {
|
||||
context = value
|
||||
})(env.host().art)
|
||||
}, implementation.options)(env.host().art)
|
||||
const config = Object.assign(Object.create({ inherited: 'legacy field' }), { adTagUrl: '/override.xml', adsResponse: 'override response' })
|
||||
context.playUrl('/ignored.xml', config)
|
||||
config.adTagUrl = '/changed.xml'
|
||||
@@ -183,7 +183,7 @@ for (const implementation of implementations) {
|
||||
let context
|
||||
await env.factory((value) => {
|
||||
context = value
|
||||
})(env.host().art)
|
||||
}, implementation.options)(env.host().art)
|
||||
context.playUrl('/first.xml')
|
||||
const player = context.imaPlayer
|
||||
assert.equal(context.container.style.display, 'none')
|
||||
@@ -211,7 +211,7 @@ for (const implementation of implementations) {
|
||||
let context
|
||||
const result = await env.factory((value) => {
|
||||
context = value
|
||||
})(host.art)
|
||||
}, implementation.options)(host.art)
|
||||
const first = context.init()
|
||||
assert.equal(result.destroy(), undefined)
|
||||
result.destroy()
|
||||
@@ -232,7 +232,7 @@ for (const implementation of implementations.filter(item => item.historical)) {
|
||||
test(`${name} historical: core destroy leaves the SDK allocated`, async () => {
|
||||
const env = vastEnvironment(implementation)
|
||||
const host = env.host()
|
||||
await env.factory(context => initialize(context))(host.art)
|
||||
await env.factory(context => initialize(context), implementation.options)(host.art)
|
||||
const [player] = env.state.players
|
||||
host.art.destroy()
|
||||
assert.equal(player.destroyCalls, 0)
|
||||
@@ -246,7 +246,7 @@ for (const implementation of implementations.filter(item => item.historical)) {
|
||||
const attaching = env.factory((context) => {
|
||||
calls++
|
||||
initialize(context)
|
||||
})(host.art)
|
||||
}, implementation.options)(host.art)
|
||||
host.art.destroy()
|
||||
env.resolveLoad()
|
||||
await attaching
|
||||
@@ -262,7 +262,7 @@ for (const implementation of implementations.filter(item => item.historical)) {
|
||||
await assert.rejects(env.factory((context) => {
|
||||
initialize(context)
|
||||
return Promise.reject(failure)
|
||||
})(host.art), error => error === failure)
|
||||
}, implementation.options)(host.art), error => error === failure)
|
||||
assert.equal(env.state.players[0].destroyCalls, 0)
|
||||
assert.equal(host.parent.children.length, 1)
|
||||
})
|
||||
@@ -276,7 +276,7 @@ for (const implementation of implementations.filter(item => item.historical)) {
|
||||
started.resolve()
|
||||
await finish.promise
|
||||
context.playUrl('/late.xml')
|
||||
})(host.art)
|
||||
}, implementation.options)(host.art)
|
||||
await started.promise
|
||||
host.art.destroy()
|
||||
finish.resolve()
|
||||
@@ -289,7 +289,7 @@ for (const implementation of implementations.filter(item => item.historical)) {
|
||||
const failure = new Error('constructor failure')
|
||||
const env = vastEnvironment(implementation, { constructError: failure })
|
||||
const host = env.host()
|
||||
await assert.rejects(env.factory(context => initialize(context))(host.art), error => error === failure)
|
||||
await assert.rejects(env.factory(context => initialize(context), implementation.options)(host.art), error => error === failure)
|
||||
assert.equal(host.parent.children.length, 1)
|
||||
assert.equal(env.state.players.length, 0)
|
||||
})
|
||||
@@ -298,7 +298,7 @@ for (const implementation of implementations.filter(item => item.historical)) {
|
||||
const env = vastEnvironment(implementation)
|
||||
const one = env.host()
|
||||
const two = env.host()
|
||||
const attach = env.factory(context => initialize(context))
|
||||
const attach = env.factory(context => initialize(context), implementation.options)
|
||||
await Promise.all([attach(one.art), attach(two.art)])
|
||||
assert.equal(one.parent.children[0].id, two.parent.children[0].id)
|
||||
assert.notEqual(one.parent.children[0], two.parent.children[0])
|
||||
@@ -312,7 +312,7 @@ for (const implementation of implementations.filter(item => item.historical)) {
|
||||
let context
|
||||
const result = await env.factory((value) => {
|
||||
context = value
|
||||
})(env.host().art)
|
||||
}, implementation.options)(env.host().art)
|
||||
context.playUrl('/first.xml')
|
||||
context.imaPlayer.emit('AdStarted')
|
||||
result.destroy()
|
||||
@@ -326,7 +326,7 @@ for (const implementation of implementations.filter(item => item.historical)) {
|
||||
let context
|
||||
const result = await env.factory((value) => {
|
||||
context = value
|
||||
})(env.host().art)
|
||||
}, implementation.options)(env.host().art)
|
||||
const first = context.init()
|
||||
const lateStart = [...first.listeners.get('AdStarted')][0]
|
||||
result.destroy()
|
||||
@@ -345,7 +345,7 @@ for (const implementation of implementations.filter(item => item.historical)) {
|
||||
let context
|
||||
const result = await env.factory((value) => {
|
||||
context = value
|
||||
})(host.art)
|
||||
}, implementation.options)(host.art)
|
||||
const player = context.init()
|
||||
assert.throws(() => result.destroy(), error => error === failure)
|
||||
assert.equal(context.imaPlayer, player)
|
||||
@@ -359,7 +359,7 @@ for (const implementation of implementations.filter(item => item.historical)) {
|
||||
let context
|
||||
await env.factory((value) => {
|
||||
context = value
|
||||
})(host.art)
|
||||
}, implementation.options)(host.art)
|
||||
assert.throws(() => context.init(), error => error === failure)
|
||||
env.state.listenError = null
|
||||
const player = context.init()
|
||||
|
||||
Reference in new issue
Block a user