UNPKG

1.68 kBJavaScriptView Raw
1import videojs from 'video.js';
2import '../../examples/basic-ad-plugin/example-plugin.js';
3import QUnit from 'qunit';
4import document from 'global/document';
5
6QUnit.module('Final Events With No Postroll', {
7 beforeEach() {
8 this.video = document.createElement('video');
9
10 this.fixture = document.querySelector('#qunit-fixture');
11 this.fixture.appendChild(this.video);
12
13 this.player = videojs(this.video);
14
15 this.player.exampleAds({
16 adServerUrl: '/test/integration/lib/inventory.json',
17 playPreroll: false,
18 playMidroll: false,
19 playPostroll: false
20 });
21
22 this.player.src({
23 src: 'http://vjs.zencdn.net/v/oceans.webm',
24 type: 'video/webm'
25 });
26
27 // Mute the player to allow playback without user interaction
28 this.player.muted(true);
29 },
30
31 afterEach() {
32 this.player.dispose();
33 }
34});
35
36QUnit.test('final ended event with no postroll: just 1', function(assert) {
37 const done = assert.async();
38 let endedEvents = 0;
39
40 // Prevent the test from timing out by making it run faster
41 this.player.ads.settings.postrollTimeout = 1;
42
43 this.player.on('ended', () => {
44 endedEvents++;
45 });
46
47 this.player.on(['error', 'aderror'], () => {
48 assert.ok(false, 'no errors');
49 done();
50 });
51
52 this.player.one('ended', () => {
53 // Run checks after a pause in case there are multiple ended events.
54 setTimeout(() => {
55 assert.equal(endedEvents, 1, 'exactly one ended with no postroll');
56 done();
57 }, 1000);
58 });
59
60 // Seek to end once we're ready so postroll can play quickly
61 this.player.one('playing', () => {
62 this.player.currentTime(46);
63 });
64
65 this.player.ready(this.player.play);
66
67});