From df10d456b80b25e84afd9aab9752d8d92080c4db Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Fri, 28 Sep 2018 13:01:53 -0400 Subject: [PATCH] chore: lint to code to vjs 7 standards (#433) * chore: lint to code to vjs 7 standards * travis * update vjsstandard to disable jsdoc rules * update to vjs standard 8 --- .gitignore | 1 + .travis.yml | 32 +- package.json | 22 +- scripts/modules.rollup.config.js | 2 +- scripts/test.rollup.config.js | 6 +- scripts/version.js | 1 - src/ads.js | 3 +- src/cancelContentPlay.js | 12 +- src/plugin.js | 3 +- src/states/abstract/State.js | 7 +- test/integration/lib/shared-module-hooks.js | 139 +++++---- test/integration/test.ads.js | 288 +++++++++++------- test/integration/test.cancelContentPlay.js | 39 ++- test/integration/test.cueTextTracks.js | 73 +++-- test/integration/test.events-midroll.js | 39 +-- test/integration/test.events-no-postroll.js | 18 +- test/integration/test.events-no-preroll.js | 29 +- test/integration/test.events-postroll.js | 45 +-- test/integration/test.events-preroll.js | 80 ++--- test/integration/test.macros.js | 76 +++-- test/integration/test.playMiddleware.js | 78 +++-- test/integration/test.snapshot.js | 66 ++-- test/integration/test.stitchedAds.js | 4 +- test/karma.conf.js | 7 +- test/unit/states/abstract/test.AdState.js | 5 +- .../unit/states/abstract/test.ContentState.js | 4 +- test/unit/states/abstract/test.State.js | 6 +- test/unit/states/test.AdsDone.js | 5 +- test/unit/states/test.BeforePreroll.js | 9 +- test/unit/states/test.ContentPlayback.js | 3 +- test/unit/states/test.Midroll.js | 6 +- test/unit/states/test.Postroll.js | 4 +- test/unit/states/test.Preroll.js | 43 ++- test/unit/states/test.StitchedAdRoll.js | 4 +- .../states/test.StitchedContentPlayback.js | 3 +- test/unit/test.ads.js | 4 +- test/unit/test.playMiddleware.js | 99 +++--- test/unit/test.redispatch.js | 37 ++- test/unit/test.register.js | 1 + 39 files changed, 736 insertions(+), 567 deletions(-) diff --git a/.gitignore b/.gitignore index dab39950..c8449e7d 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,4 @@ dist/ docs/api/ test/dist/ examples/module-import/bundle.js +.eslintcache diff --git a/.travis.yml b/.travis.yml index 4deb53e4..ec0a6f3f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,32 +1,16 @@ sudo: false dist: trusty language: node_js -node_js: - - 'node' - - 'lts/argon' +# node version is specified using the .nvmrc file +before_install: + - npm install -g greenkeeper-lockfile@1 before_script: - - # Check if the current version is equal to the major version for the env. - - 'export IS_INSTALLED="$(npm list video.js | grep "video.js@$VJS")"' - - # We have to add semicolons to the end of each line in the if as Travis runs - # this all on one line. - - 'if [ -z "$IS_INSTALLED" ]; then - echo "INSTALLING video.js@>=$VJS.0.0-RC.0 <$(($VJS+1)).0.0"; - npm i "video.js@>=$VJS.0.0-RC.0 <\$(($VJS+1)).0.0"; - else - echo "video.js@$VJS ALREADY INSTALLED"; - fi' - - export CHROME_BIN=/usr/bin/google-chrome - export DISPLAY=:99.0 - sh -e /etc/init.d/xvfb start -env: - - VJS=5 - - VJS=6 + - greenkeeper-lockfile-update +after_script: + - greenkeeper-lockfile-upload addons: firefox: latest - apt: - sources: - - google-chrome - packages: - - google-chrome-stable + chrome: stable + diff --git a/package.json b/package.json index 771040ec..e44c4187 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "build:test": "rollup -c scripts/test.rollup.config.js", "clean": "rimraf dist test/dist", "postclean": "mkdirp dist test/dist", - "lint": "eslint src", + "lint": "vjsstandard", "prestart": "npm run build", "start": "npm-run-all -p start:* watch", "start:server": "static -a 0.0.0.0 -p 9999 -H '{\"Cache-Control\": \"no-cache, must-revalidate\"}' .", @@ -47,7 +47,6 @@ "prepush": "npm run lint" }, "devDependencies": { - "babel-eslint": "^8.0.2", "babel-plugin-external-helpers": "^6.22.0", "babel-plugin-transform-object-assign": "^6.8.0", "babel-preset-es2015": "^6.14.0", @@ -58,8 +57,6 @@ "cpy-cli": "^1.0.1", "doctoc": "^1.3.0", "es5-shim": "^4.5.9", - "eslint": "^4.11.0", - "eslint-config-videojs": "^2.1.0", "husky": "^0.13.3", "karma": "^2.0.2", "karma-chrome-launcher": "^2.1.1", @@ -85,19 +82,22 @@ "rollup-watch": "^3.2.2", "semver": "^5.3.0", "sinon": "^2.2.0", - "uglify-js": "^3.0.7" + "uglify-js": "^3.0.7", + "videojs-standard": "^8.0.2" }, "keywords": [ "videojs", "videojs-plugin" ], "license": "Apache-2.0", - "eslintConfig": { - "extends": "videojs", - "rules": { - "require-jsdoc": "off", - "consistent-this": "off" - } + "vjsstandard": { + "jsdoc": false, + "ignore": [ + "dist", + "docs", + "test/dist", + "examples" + ] }, "files": [ "CONTRIBUTING.md", diff --git a/scripts/modules.rollup.config.js b/scripts/modules.rollup.config.js index 1b69f3c9..3e318b84 100644 --- a/scripts/modules.rollup.config.js +++ b/scripts/modules.rollup.config.js @@ -21,7 +21,7 @@ export default { }, output: [{ file: 'dist/videojs-contrib-ads.cjs.js', - format: 'cjs', + format: 'cjs' }, { file: 'dist/videojs-contrib-ads.es.js', format: 'es' diff --git a/scripts/test.rollup.config.js b/scripts/test.rollup.config.js index a7cae9a3..25d4cc54 100644 --- a/scripts/test.rollup.config.js +++ b/scripts/test.rollup.config.js @@ -20,13 +20,15 @@ export default { 'qunit', 'qunitjs', 'sinon', - 'video.js' + 'video.js', + 'lodash' ], globals: { 'qunit': 'QUnit', 'qunitjs': 'QUnit', 'sinon': 'sinon', - 'video.js': 'videojs' + 'video.js': 'videojs', + 'lodash': '_' }, legacy: true, plugins: [ diff --git a/scripts/version.js b/scripts/version.js index bec49a84..f99e9bb9 100644 --- a/scripts/version.js +++ b/scripts/version.js @@ -1,5 +1,4 @@ const exec = require('child_process').exec; -const fs = require('fs'); const path = require('path'); const semver = require('semver'); const pkg = require('../package.json'); diff --git a/src/ads.js b/src/ads.js index dc9f27d8..719f1c3b 100644 --- a/src/ads.js +++ b/src/ads.js @@ -113,8 +113,7 @@ export default function getAds(player) { } if (!this.snapshot) { - throw new Error( - 'You cannot use videoElementRecycled while there is no snapshot.'); + throw new Error('You cannot use videoElementRecycled while there is no snapshot.'); } const srcChanged = player.tech_.src() !== this.snapshot.src; diff --git a/src/cancelContentPlay.js b/src/cancelContentPlay.js index e2b126c2..a2d09954 100644 --- a/src/cancelContentPlay.js +++ b/src/cancelContentPlay.js @@ -17,9 +17,9 @@ then signalling that we should play after the ad is done. */ function cancelContentPlay() { - const player = this; + // this function is in the player's context - if (player.ads._shouldBlockPlay === false) { + if (this.ads._shouldBlockPlay === false) { // Only block play if the ad plugin is in a state when content // playback should be blocked. This currently means during // BeforePrerollState and PrerollState. @@ -27,12 +27,12 @@ function cancelContentPlay() { } // pause playback so ads can be handled. - if (!player.paused()) { - player.ads.debug('Playback was canceled by cancelContentPlay'); - player.pause(); + if (!this.paused()) { + this.ads.debug('Playback was canceled by cancelContentPlay'); + this.pause(); } // When the 'content-playback' state is entered, this will let us know to play. // This is needed if there is no preroll or if it errors, times out, etc. - player.ads._cancelledPlay = true; + this.ads._cancelledPlay = true; } diff --git a/src/plugin.js b/src/plugin.js index 95190fc5..d8b4fcbf 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -248,7 +248,8 @@ const contribAdsPlugin = function(options) { 'adsready', 'adscanceled', 'adskip', 'adserror', 'adtimeout', 'adended', 'ads-ad-started', 'contentchanged', 'dispose', 'contentresumed', 'readyforpostroll', - 'nopreroll', 'nopostroll'], (e) => { + 'nopreroll', 'nopostroll' + ], (e) => { player.ads._state.handleEvent(e.type); }); diff --git a/src/states/abstract/State.js b/src/states/abstract/State.js index b458f91d..eb202138 100644 --- a/src/states/abstract/State.js +++ b/src/states/abstract/State.js @@ -17,13 +17,14 @@ export default class State { */ transitionTo(NewState, ...args) { const player = this.player; - const previousState = this; - previousState.cleanup(player); + // Since State is an abstract class, this will refer to + // the state that is extending this class + this.cleanup(player); const newState = new NewState(player); player.ads._state = newState; - player.ads.debug(previousState.constructor._getName() + ' -> ' + + player.ads.debug(this.constructor._getName() + ' -> ' + newState.constructor._getName()); newState.init(player, ...args); } diff --git a/test/integration/lib/shared-module-hooks.js b/test/integration/lib/shared-module-hooks.js index ed997f12..d8170046 100644 --- a/test/integration/lib/shared-module-hooks.js +++ b/test/integration/lib/shared-module-hooks.js @@ -1,90 +1,95 @@ -/* - * Composes per-module `beforeEach` and `afterEach` hooks with common/shared - * hooks. - * - * @param {Object} [hooks] - * @param {Function} [hooks.beforeEach] - * @param {Function} [hooks.afterEach] - * @return {Object} - */ -window.sharedModuleHooks = (function(){ - var Html5 = videojs.getTech('Html5'); +import videojs from 'video.js'; +import sinon from 'sinon'; +import document from 'global/document'; +import window from 'global/window'; +import _ from 'lodash'; - var backup = { - Html5: { - isSupported: Html5.isSupported, - setSource: Html5.prototype.setSource - } - }; +const Html5 = videojs.getTech('Html5'); - var common = { +const backup = { + Html5: { + isSupported: Html5.isSupported, + setSource: Html5.prototype.setSource + } +}; - beforeEach: function() { +const common = { - // Fake HTML 5 support. - Html5.isSupported = function() { - return true; - }; + beforeEach() { - delete Html5.setSource; + // Fake HTML 5 support. + Html5.isSupported = function() { + return true; + }; + + delete Html5.setSource; - this.sandbox = sinon.sandbox.create(); + this.sandbox = sinon.sandbox.create(); - // Use fake timers to replace setTimeout and so forth. - this.clock = sinon.useFakeTimers(); + // Use fake timers to replace setTimeout and so forth. + this.clock = sinon.useFakeTimers(); - // Create video element and player. - this.video = document.createElement('video'); + // Create video element and player. + this.video = document.createElement('video'); - // backfill broken phantom implementation(s) - if (/phantom/i.test(window.navigator.userAgent)) { - this.video.removeAttribute = function(attr) { - this[attr] = ''; - }; - this.video.load = function(){}; - this.video.play = function(){}; - this.video.pause = function(){}; - } + // backfill broken phantom implementation(s) + if (/phantom/i.test(window.navigator.userAgent)) { + this.video.removeAttribute = function(attr) { + this[attr] = ''; + }; + this.video.load = function() {}; + this.video.play = function() {}; + this.video.pause = function() {}; + } - document.getElementById('qunit-fixture').appendChild(this.video); + document.getElementById('qunit-fixture').appendChild(this.video); - this.player = videojs(this.video); + this.player = videojs(this.video); - // Tick the clock because videojs player creation is now async. - this.clock.tick(1000); + // Tick the clock because videojs player creation is now async. + this.clock.tick(1000); - this.player.buffered = function() { - return videojs.createTimeRange(0, 0); - }; + this.player.buffered = function() { + return videojs.createTimeRange(0, 0); + }; - this.player.ads(this.adsOptions); - }, + this.player.ads(this.adsOptions); + }, - afterEach: function() { + afterEach() { - // Restore original state of the Html5 component. - Html5.isSupported = backup.Html5.isSupported; - Html5.prototype.setSource = backup.Html5.setSource; + // Restore original state of the Html5 component. + Html5.isSupported = backup.Html5.isSupported; + Html5.prototype.setSource = backup.Html5.setSource; - // Restore setTimeout et al. - this.clock.restore(); + // Restore setTimeout et al. + this.clock.restore(); - // Kill the player and its element (i.e. `this.video`). - this.player.dispose(); + // Kill the player and its element (i.e. `this.video`). + this.player.dispose(); - // Kill the "contentplayback" spy. - this.contentPlaybackSpy = this.contentPlaybackReason = null; + // Kill the "contentplayback" spy. + this.contentPlaybackSpy = this.contentPlaybackReason = null; - this.sandbox.restore(); - } - }; + this.sandbox.restore(); + } +}; - return function(hooks) { - hooks = hooks || {}; - return { - beforeEach: _.flow(common.beforeEach, hooks.beforeEach || _.noop), - afterEach: _.flow(common.afterEach, hooks.afterEach || _.noop) - }; +/* + * Composes per-module `beforeEach` and `afterEach` hooks with common/shared + * hooks. + * + * @param {Object} [hooks] + * @param {Function} [hooks.beforeEach] + * @param {Function} [hooks.afterEach] + * @return {Object} + */ +const sharedModuleHooks = function(hooks) { + hooks = hooks || {}; + return { + beforeEach: _.flow(common.beforeEach, hooks.beforeEach || _.noop), + afterEach: _.flow(common.afterEach, hooks.afterEach || _.noop) }; -}()); +}; +export default sharedModuleHooks; diff --git a/test/integration/test.ads.js b/test/integration/test.ads.js index 55ff3ccd..7424b6e4 100644 --- a/test/integration/test.ads.js +++ b/test/integration/test.ads.js @@ -1,15 +1,16 @@ -var timerExists = function(env, id) { - return env.clock.timers.hasOwnProperty(id); -}; +import QUnit from 'qunit'; +import sinon from 'sinon'; +import videojs from 'video.js'; +import sharedModuleHooks from './lib/shared-module-hooks.js'; -QUnit.module('Contrib Ads', window.sharedModuleHooks()); +QUnit.module('Contrib Ads', sharedModuleHooks()); QUnit.test('begins in BeforePreroll', function(assert) { assert.equal(this.player.ads._state.constructor.name, 'BeforePreroll'); }); QUnit.test('adstart is fired before a preroll', function(assert) { - var spy = sinon.spy(); + const spy = sinon.spy(); assert.expect(1); @@ -31,7 +32,7 @@ QUnit.test('player has the .vjs-has-started class once a preroll begins', functi }); QUnit.test('calls start immediately on play when ads are ready', function(assert) { - var readyForPrerollSpy = sinon.spy(); + const readyForPrerollSpy = sinon.spy(); assert.expect(1); @@ -43,73 +44,68 @@ QUnit.test('calls start immediately on play when ads are ready', function(assert }); QUnit.test('adds the ad-mode class when a preroll plays', function(assert) { - var el; - assert.expect(1); this.player.trigger('adsready'); this.player.trigger('play'); this.player.ads.startLinearAdMode(); - el = this.player.el(); + const el = this.player.el(); + assert.ok(this.player.hasClass('vjs-ad-playing'), 'the ad class should be in "' + el.className + '"'); }); QUnit.test('removes the ad-mode class when a preroll finishes', function(assert) { - var el; this.player.trigger('adsready'); this.player.trigger('play'); this.player.ads.startLinearAdMode(); this.player.ads.endLinearAdMode(); - el = this.player.el(); + const el = this.player.el(); + assert.notOk(this.player.hasClass('vjs-ad-playing'), 'the ad class should not be in "' + el.className + '"'); this.player.trigger('playing'); }); QUnit.test('adds a class while waiting for an ad plugin to load', function(assert) { - var el; - assert.expect(1); this.player.trigger('play'); - el = this.player.el(); + const el = this.player.el(); + assert.ok(this.player.hasClass('vjs-ad-loading'), 'the ad loading class should be in "' + el.className + '"'); }); QUnit.test('adds a class while waiting for a preroll', function(assert) { - var el; - assert.expect(1); this.player.trigger('adsready'); this.player.trigger('play'); - el = this.player.el(); + const el = this.player.el(); + assert.ok(this.player.hasClass('vjs-ad-loading'), 'the ad loading class should be in "' + el.className + '"'); }); QUnit.test('removes the loading class when the preroll begins', function(assert) { - var el; - assert.expect(1); this.player.trigger('adsready'); this.player.trigger('play'); this.player.ads.startLinearAdMode(); this.player.trigger('ads-ad-started'); - el = this.player.el(); + const el = this.player.el(); + assert.notOk(this.player.hasClass('vjs-ad-loading'), 'there should be no ad loading class present in "' + el.className + '"'); }); QUnit.test('removes the loading class when the preroll times out', function(assert) { - var el; - this.player.trigger('loadstart'); this.player.trigger('adsready'); this.player.trigger('play'); this.player.trigger('adtimeout'); this.player.trigger('playing'); - el = this.player.el(); + const el = this.player.el(); + assert.notOk(this.player.hasClass('vjs-ad-loading'), 'there should be no ad loading class present in "' + el.className + '"'); }); @@ -136,7 +132,7 @@ QUnit.test('removes the poster attribute so it does not flash between videos', f }); QUnit.test('changing the src triggers "contentupdate"', function(assert) { - var spy = sinon.spy(); + const spy = sinon.spy(); assert.expect(1); @@ -149,7 +145,7 @@ QUnit.test('changing the src triggers "contentupdate"', function(assert) { }); QUnit.test('"contentupdate" should fire when src is changed after postroll', function(assert) { - var contentupdateSpy = sinon.spy(); + const contentupdateSpy = sinon.spy(); this.player.on('contentupdate', contentupdateSpy); @@ -169,7 +165,7 @@ QUnit.test('"contentupdate" should fire when src is changed after postroll', fun }); QUnit.test('"contentupdate" should fire when src is changed after postroll', function(assert) { - var contentupdateSpy = sinon.spy(); + const contentupdateSpy = sinon.spy(); this.player.on('contentupdate', contentupdateSpy); this.player.trigger('adsready'); @@ -189,7 +185,7 @@ QUnit.test('"contentupdate" should fire when src is changed after postroll', fun }); QUnit.test('changing src does not trigger "contentupdate" during ad playback', function(assert) { - var spy = sinon.spy(); + const spy = sinon.spy(); this.player.on('contentupdate', spy); @@ -213,20 +209,28 @@ QUnit.test('changing src does not trigger "contentupdate" during ad playback', f QUnit.test('the `_playRequested` flag is set on the first play request', function(assert) { this.player.trigger('loadstart'); this.player.trigger('adsready'); - assert.strictEqual(this.player.ads._playRequested, false, - 'initially set to false'); - assert.strictEqual(this.player.ads.isInAdMode(), false, - 'starts in a content state'); + assert.strictEqual( + this.player.ads._playRequested, false, + 'initially set to false' + ); + assert.strictEqual( + this.player.ads.isInAdMode(), false, + 'starts in a content state' + ); this.player.trigger('play'); - assert.strictEqual(this.player.ads._playRequested, true, - '_playRequested is now true'); - assert.strictEqual(this.player.ads.isInAdMode(), true, - 'now in ad state'); + assert.strictEqual( + this.player.ads._playRequested, true, + '_playRequested is now true' + ); + assert.strictEqual( + this.player.ads.isInAdMode(), true, + 'now in ad state' + ); }); QUnit.test('ended event happens after postroll errors out', function(assert) { - var endedSpy = sinon.spy(); + const endedSpy = sinon.spy(); this.player.on('ended', endedSpy); @@ -234,7 +238,8 @@ QUnit.test('ended event happens after postroll errors out', function(assert) { this.player.trigger('adsready'); this.player.trigger('play'); this.player.trigger('adtimeout'); - this.player.trigger('playing'); // Entered content + // Entered content + this.player.trigger('playing'); this.player.trigger('ended'); this.player.trigger('adserror'); @@ -243,7 +248,7 @@ QUnit.test('ended event happens after postroll errors out', function(assert) { }); QUnit.test('ended event happens after postroll timed out', function(assert) { - var endedSpy = sinon.spy(); + const endedSpy = sinon.spy(); this.player.on('ended', endedSpy); @@ -251,7 +256,8 @@ QUnit.test('ended event happens after postroll timed out', function(assert) { this.player.trigger('adsready'); this.player.trigger('play'); this.player.trigger('adtimeout'); - this.player.trigger('playing'); // Entered content + // Entered content + this.player.trigger('playing'); this.player.trigger('ended'); this.player.trigger('adtimeout'); @@ -260,16 +266,19 @@ QUnit.test('ended event happens after postroll timed out', function(assert) { }); QUnit.test('ended event happens after postroll skipped', function(assert) { - var endedSpy = sinon.spy(); + const endedSpy = sinon.spy(); this.player.on('ended', endedSpy); this.player.trigger('loadstart'); this.player.trigger('adsready'); this.player.trigger('play'); - this.player.trigger('adtimeout'); // preroll times out - this.player.trigger('playing'); // Entered content - this.player.trigger('ended'); // content ends + // preroll times out + this.player.trigger('adtimeout'); + // Entered content + this.player.trigger('playing'); + // content ends + this.player.trigger('ended'); this.player.ads.skipLinearAdMode(); this.clock.tick(1); @@ -277,37 +286,46 @@ QUnit.test('ended event happens after postroll skipped', function(assert) { }); QUnit.test('an "ended" event is fired after postroll if not fired naturally', function(assert) { - var endedSpy = sinon.spy(); + const endedSpy = sinon.spy(); this.player.on('ended', endedSpy); this.player.trigger('loadstart'); this.player.trigger('adsready'); this.player.trigger('play'); - this.player.trigger('adtimeout'); // skip preroll - this.player.trigger('playing'); // return to content - this.player.trigger('ended'); // handled by redispatch + // skip preroll + this.player.trigger('adtimeout'); + // return to content + this.player.trigger('playing'); + // handled by redispatch + this.player.trigger('ended'); assert.strictEqual(endedSpy.callCount, 0, 'no ended event before postroll'); - this.player.ads.startLinearAdMode(); // start postroll + // start postroll + this.player.ads.startLinearAdMode(); this.player.ads.endLinearAdMode(); this.player.trigger('resumeended'); assert.strictEqual(endedSpy.callCount, 1, 'ended event happened'); }); QUnit.test('ended events when content ends first and second time', function(assert) { - var endedSpy = sinon.spy(); + const endedSpy = sinon.spy(); + this.player.on('ended', endedSpy); this.player.trigger('loadstart'); this.player.trigger('adsready'); this.player.trigger('play'); - this.player.trigger('adtimeout'); // Preroll times out - this.player.trigger('playing'); // Entered content - this.player.trigger('ended'); // Triggers readyforpostroll + // Preroll times out + this.player.trigger('adtimeout'); + // Entered content + this.player.trigger('playing'); + // Triggers readyforpostroll + this.player.trigger('ended'); - this.player.ads.startLinearAdMode(); // Postroll starts + // Postroll starts + this.player.ads.startLinearAdMode(); this.player.ads.endLinearAdMode(); this.player.trigger('resumeended'); @@ -318,7 +336,7 @@ QUnit.test('ended events when content ends first and second time', function(asse }); QUnit.test('endLinearAdMode during ad break triggers adend', function(assert) { - var adendSpy = sinon.spy(); + const adendSpy = sinon.spy(); this.player.on('adend', adendSpy); @@ -335,7 +353,7 @@ QUnit.test('endLinearAdMode during ad break triggers adend', function(assert) { }); QUnit.test('calling startLinearAdMode() when already in ad-playback does not trigger adstart', function(assert) { - var spy = sinon.spy(); + const spy = sinon.spy(); this.player.on('adstart', spy); this.player.trigger('adsready'); @@ -356,9 +374,8 @@ QUnit.test('calling startLinearAdMode() when already in ad-playback does not tri }); QUnit.test('calling endLinearAdMode() outside of linear ad mode does not trigger adend', function(assert) { - var adendSpy; + const adendSpy = sinon.spy(); - adendSpy = sinon.spy(); this.player.on('adend', adendSpy); this.player.ads.endLinearAdMode(); @@ -386,9 +403,8 @@ QUnit.test('calling endLinearAdMode() outside of linear ad mode does not trigger }); QUnit.test('skipLinearAdMode during ad playback does not trigger adskip', function(assert) { - var adskipSpy; + const adskipSpy = sinon.spy(); - adskipSpy = sinon.spy(); this.player.on('adskip', adskipSpy); this.player.trigger('adsready'); @@ -396,24 +412,27 @@ QUnit.test('skipLinearAdMode during ad playback does not trigger adskip', functi this.player.ads.startLinearAdMode(); this.player.ads.skipLinearAdMode(); - assert.strictEqual(adskipSpy.callCount, 0, - 'adskip event should not trigger when skipLinearAdMode is called during an ad'); + assert.strictEqual( + adskipSpy.callCount, 0, + 'adskip event should not trigger when skipLinearAdMode is called during an ad' + ); }); QUnit.test('adsready in content-playback triggers readyforpreroll', function(assert) { - var spy = sinon.spy(); + const spy = sinon.spy(); this.player.on('readyforpreroll', spy); this.player.trigger('loadstart'); this.player.trigger('play'); this.player.trigger('adtimeout'); - this.player.trigger('playing'); // entered ContentPlayback + // entered ContentPlayback + this.player.trigger('playing'); this.player.trigger('adsready'); assert.strictEqual(spy.callCount, 1, 'readyforpreroll should have been triggered.'); }); QUnit.test('adsready while preroll content resuming triggers readyforpreroll', function(assert) { - var spy = sinon.spy(); + const spy = sinon.spy(); this.player.on('readyforpreroll', spy); this.player.trigger('loadstart'); @@ -429,17 +448,17 @@ QUnit.test('adsready while preroll content resuming triggers readyforpreroll', f // ---------------------------------- QUnit.test('player events during prerolls are prefixed if tech is reused for ad', function(assert) { - var sawLoadstart = sinon.spy(); - var sawPlaying = sinon.spy(); - var sawPause = sinon.spy(); - var sawEnded = sinon.spy(); - var sawFirstplay = sinon.spy(); - var sawLoadedalldata = sinon.spy(); - var sawAdloadstart = sinon.spy(); - var sawAdpause = sinon.spy(); - var sawAdended = sinon.spy(); - var sawAdfirstplay = sinon.spy(); - var sawAdloadedalldata = sinon.spy(); + const sawLoadstart = sinon.spy(); + const sawPlaying = sinon.spy(); + const sawPause = sinon.spy(); + const sawEnded = sinon.spy(); + const sawFirstplay = sinon.spy(); + const sawLoadedalldata = sinon.spy(); + const sawAdloadstart = sinon.spy(); + const sawAdpause = sinon.spy(); + const sawAdended = sinon.spy(); + const sawAdfirstplay = sinon.spy(); + const sawAdloadedalldata = sinon.spy(); // play a preroll this.player.on('readyforpreroll', function() { @@ -486,19 +505,18 @@ QUnit.test('player events during prerolls are prefixed if tech is reused for ad' }); QUnit.test('player events during midrolls are prefixed if tech is reused for ad', function(assert) { - var prefixed, unprefixed; - assert.expect(2); - prefixed = sinon.spy(); - unprefixed = sinon.spy(); + const prefixed = sinon.spy(); + const unprefixed = sinon.spy(); // play a midroll this.player.trigger('play'); this.player.trigger('loadstart'); this.player.trigger('adsready'); this.player.trigger('adtimeout'); - this.player.trigger('playing'); // return to content + // return to content + this.player.trigger('playing'); this.player.ads.startLinearAdMode(); this.player.ads.snapshot = { @@ -519,19 +537,18 @@ QUnit.test('player events during midrolls are prefixed if tech is reused for ad' }); QUnit.test('player events during postrolls are prefixed if tech is reused for ad', function(assert) { - var prefixed, unprefixed; - assert.expect(2); - prefixed = sinon.spy(); - unprefixed = sinon.spy(); + const prefixed = sinon.spy(); + const unprefixed = sinon.spy(); // play a postroll this.player.trigger('play'); this.player.trigger('loadstart'); this.player.trigger('adsready'); this.player.trigger('adtimeout'); - this.player.trigger('playing'); // return to content + // return to content + this.player.trigger('playing'); this.player.trigger('ended'); this.player.ads.startLinearAdMode(); @@ -553,12 +570,10 @@ QUnit.test('player events during postrolls are prefixed if tech is reused for ad }); QUnit.test('player events during stitched ads are prefixed', function(assert) { - var prefixed, unprefixed; - assert.expect(2); - prefixed = sinon.spy(); - unprefixed = sinon.spy(); + const prefixed = sinon.spy(); + const unprefixed = sinon.spy(); this.player.ads.stitchedAds(true); @@ -584,12 +599,10 @@ QUnit.test('player events during stitched ads are prefixed', function(assert) { }); QUnit.test('player events during content playback are not prefixed', function(assert) { - var prefixed, unprefixed; - assert.expect(3); - prefixed = sinon.spy(); - unprefixed = sinon.spy(); + const prefixed = sinon.spy(); + const unprefixed = sinon.spy(); // play content this.player.trigger('loadstart'); @@ -615,7 +628,8 @@ QUnit.test('player events during content playback are not prefixed', function(as QUnit.test('startLinearAdMode should only trigger adstart from correct states', function(assert) { - var adstart = sinon.spy(); + const adstart = sinon.spy(); + this.player.on('adstart', adstart); this.player.ads.startLinearAdMode(); @@ -700,7 +714,7 @@ QUnit.test('ad impl can notify contrib-ads there is no preroll 4', function(asse QUnit.test('ended event is sent after nopostroll', function(assert) { - var ended = sinon.spy(); + const ended = sinon.spy(); this.player.on('ended', ended); @@ -724,7 +738,7 @@ QUnit.test('ended event is sent with postroll', function(assert) { this.player.ads.skipLinearAdMode(); this.player.trigger('playing'); - var ended = sinon.spy(); + const ended = sinon.spy(); this.player.on('ended', ended); @@ -740,27 +754,39 @@ QUnit.test('isLive', function(assert) { // Make videojs.browser writeable videojs.browser = Object.assign({}, videojs.browser); - this.player.duration = function() {return 0;}; + this.player.duration = function() { + return 0; + }; videojs.browser.IOS_VERSION = '8'; assert.strictEqual(this.player.ads.isLive(this.player), true); - this.player.duration = function() {return 5;}; + this.player.duration = function() { + return 5; + }; videojs.browser.IOS_VERSION = '8'; assert.strictEqual(this.player.ads.isLive(this.player), false); - this.player.duration = function() {return Infinity;}; + this.player.duration = function() { + return Infinity; + }; videojs.browser.IOS_VERSION = '8'; assert.strictEqual(this.player.ads.isLive(this.player), true); - this.player.duration = function() {return 0;}; + this.player.duration = function() { + return 0; + }; videojs.browser.IOS_VERSION = undefined; assert.strictEqual(this.player.ads.isLive(this.player), false); - this.player.duration = function() {return 5;}; + this.player.duration = function() { + return 5; + }; videojs.browser.IOS_VERSION = undefined; assert.strictEqual(this.player.ads.isLive(this.player), false); - this.player.duration = function() {return Infinity;}; + this.player.duration = function() { + return Infinity; + }; videojs.browser.IOS_VERSION = undefined; assert.strictEqual(this.player.ads.isLive(this.player), true); @@ -771,57 +797,79 @@ QUnit.test('shouldPlayContentBehindAd', function(assert) { // Make videojs.browser writeable videojs.browser = Object.assign({}, videojs.browser); - this.player.duration = function() {return Infinity;}; + this.player.duration = function() { + return Infinity; + }; videojs.browser.IS_IOS = true; videojs.browser.IS_ANDROID = true; assert.strictEqual(this.player.ads.shouldPlayContentBehindAd(this.player), false); - this.player.duration = function() {return Infinity;}; + this.player.duration = function() { + return Infinity; + }; videojs.browser.IS_IOS = true; videojs.browser.IS_ANDROID = false; assert.strictEqual(this.player.ads.shouldPlayContentBehindAd(this.player), false); - this.player.duration = function() {return Infinity;}; + this.player.duration = function() { + return Infinity; + }; videojs.browser.IS_IOS = false; videojs.browser.IS_ANDROID = true; assert.strictEqual(this.player.ads.shouldPlayContentBehindAd(this.player), false); - this.player.duration = function() {return Infinity;}; + this.player.duration = function() { + return Infinity; + }; videojs.browser.IS_IOS = false; videojs.browser.IS_ANDROID = false; assert.strictEqual(this.player.ads.shouldPlayContentBehindAd(this.player), true); - this.player.duration = function() {return 5;}; + this.player.duration = function() { + return 5; + }; videojs.browser.IS_IOS = true; videojs.browser.IS_ANDROID = true; assert.strictEqual(this.player.ads.shouldPlayContentBehindAd(this.player), false); - this.player.duration = function() {return 5;}; + this.player.duration = function() { + return 5; + }; videojs.browser.IS_IOS = true; videojs.browser.IS_ANDROID = false; assert.strictEqual(this.player.ads.shouldPlayContentBehindAd(this.player), false); - this.player.duration = function() {return 5;}; + this.player.duration = function() { + return 5; + }; videojs.browser.IS_IOS = false; videojs.browser.IS_ANDROID = true; assert.strictEqual(this.player.ads.shouldPlayContentBehindAd(this.player), false); - this.player.duration = function() {return 5;}; + this.player.duration = function() { + return 5; + }; videojs.browser.IS_IOS = false; videojs.browser.IS_ANDROID = false; assert.strictEqual(this.player.ads.shouldPlayContentBehindAd(this.player), false); - this.player.duration = function() {return Infinity;}; + this.player.duration = function() { + return Infinity; + }; videojs.browser.IS_IOS = false; videojs.browser.IS_ANDROID = false; try { this.player.ads.shouldPlayContentBehindAd(); } catch (error) { - assert.strictEqual(error.message, - 'shouldPlayContentBehindAd requires a player as a param'); + assert.strictEqual( + error.message, + 'shouldPlayContentBehindAd requires a player as a param' + ); } - this.player.duration = function() {return Infinity;}; + this.player.duration = function() { + return Infinity; + }; videojs.browser.IS_IOS = false; videojs.browser.IS_ANDROID = false; this.player.ads.settings.liveCuePoints = false; @@ -835,18 +883,22 @@ QUnit.test('Check incorrect addition of vjs-live during ad-playback', function(a }); -QUnit.test('Check for existence of vjs-live after ad-end for LIVE videos', +QUnit.test( + 'Check for existence of vjs-live after ad-end for LIVE videos', function(assert) { this.player.trigger('loadstart'); this.player.trigger('adsready'); this.player.trigger('play'); this.player.ads.startLinearAdMode(); - this.player.duration = function() {return Infinity;}; + this.player.duration = function() { + return Infinity; + }; this.player.ads.endLinearAdMode(); this.player.trigger('playing'); assert.strictEqual(this.player.ads.isLive(this.player), true, 'Content is LIVE'); assert.ok(this.player.hasClass('vjs-live'), 'We should be having vjs-live class here'); -}); + } +); QUnit.test('Plugin state resets after contentchanged', function(assert) { @@ -933,7 +985,7 @@ if (videojs.browser.IS_IOS) { // Confirm the track is added, set the mode to showing assert.equal(tracks.length, 1); tracks[0].mode = 'showing'; - assert.equal(tracks[0].mode, 'showing', 'Initial state is showing'); + assert.equal(tracks[0].mode, 'showing', 'Initial state is showing'); // Start the ad, confirm the track is disabled this.player.ads.startLinearAdMode(); diff --git a/test/integration/test.cancelContentPlay.js b/test/integration/test.cancelContentPlay.js index 6697a15d..9454bfa2 100644 --- a/test/integration/test.cancelContentPlay.js +++ b/test/integration/test.cancelContentPlay.js @@ -1,4 +1,11 @@ -const sharedHooks = window.sharedModuleHooks(); +import QUnit from 'qunit'; +import sinon from 'sinon'; +import videojs from 'video.js'; +import window from 'global/window'; +import sharedModuleHooks from './lib/shared-module-hooks.js'; +import _ from 'lodash'; + +const sharedHooks = sharedModuleHooks(); const timerExists = function(env, id) { return env.clock.timers.hasOwnProperty(id); @@ -31,7 +38,7 @@ QUnit.module('Cancel Content Play', { }); QUnit.test('pauses to wait for prerolls when the plugin loads BEFORE play', function(assert) { - var spy = sinon.spy(this.player, 'pause'); + const spy = sinon.spy(this.player, 'pause'); this.player.paused = function() { return false; @@ -47,7 +54,7 @@ QUnit.test('pauses to wait for prerolls when the plugin loads BEFORE play', func }); QUnit.test('pauses to wait for prerolls when the plugin loads AFTER play', function(assert) { - var pauseSpy = sinon.spy(this.player, 'pause'); + const pauseSpy = sinon.spy(this.player, 'pause'); this.player.paused = function() { return false; @@ -61,8 +68,8 @@ QUnit.test('pauses to wait for prerolls when the plugin loads AFTER play', funct }); QUnit.test('stops canceling play events when an ad is playing', function(assert) { - var setTimeoutSpy = sinon.spy(window, 'setTimeout'); - var pauseSpy = sinon.spy(this.player, 'pause'); + const setTimeoutSpy = sinon.spy(window, 'setTimeout'); + const pauseSpy = sinon.spy(this.player, 'pause'); // Throughout this test, we check both that the expected timeout is // populated on the `clock` _and_ that `setTimeout` has been called the @@ -71,7 +78,7 @@ QUnit.test('stops canceling play events when an ad is playing', function(assert) this.player.paused = () => { return false; - } + }; this.player.trigger('play'); assert.strictEqual(setTimeoutSpy.callCount, 1, 'one timer was created (`_prerollTimeout`)'); assert.ok(timerExists(this, this.player.ads._state._timeout), 'preroll timeout exists after play'); @@ -99,11 +106,13 @@ QUnit.test("cancelContentPlay doesn\'t block play in content playback", function this.player.trigger('adscanceled'); this.player.paused = () => { return false; - } + }; this.player.trigger('play'); assert.strictEqual(pauseSpy.callCount, 1, 'pause should have been called'); - assert.strictEqual(this.player.ads._cancelledPlay, true, - 'cancelContentPlay is called while resuming'); + assert.strictEqual( + this.player.ads._cancelledPlay, true, + 'cancelContentPlay is called while resuming' + ); // enters ContentPlayback this.player.trigger('playing'); @@ -114,13 +123,13 @@ QUnit.test("cancelContentPlay doesn\'t block play in content playback", function }); QUnit.test('content is resumed after ads if a user initiated play event is canceled', function(assert) { - var playSpy = sinon.spy(this.player, 'play'); - var setTimeoutSpy = sinon.spy(window, 'setTimeout'); - var pauseSpy = sinon.spy(this.player, 'pause'); + const playSpy = sinon.spy(this.player, 'play'); + const setTimeoutSpy = sinon.spy(window, 'setTimeout'); + const pauseSpy = sinon.spy(this.player, 'pause'); this.player.paused = () => { return false; - } + }; this.player.trigger('play'); this.player.trigger('adsready'); @@ -152,7 +161,7 @@ QUnit.module('Cancel Content Play (w/ Stitched Ads)', { }); QUnit.test('does not pause to wait for prerolls when the plugin loads BEFORE play', function(assert) { - var spy = sinon.spy(this.player, 'pause'); + const spy = sinon.spy(this.player, 'pause'); this.player.paused = function() { return false; @@ -168,7 +177,7 @@ QUnit.test('does not pause to wait for prerolls when the plugin loads BEFORE pla }); QUnit.test('does not pause to wait for prerolls when the plugin loads AFTER play', function(assert) { - var pauseSpy = sinon.spy(this.player, 'pause'); + const pauseSpy = sinon.spy(this.player, 'pause'); this.player.paused = function() { return false; diff --git a/test/integration/test.cueTextTracks.js b/test/integration/test.cueTextTracks.js index a8b60f21..03842bcf 100644 --- a/test/integration/test.cueTextTracks.js +++ b/test/integration/test.cueTextTracks.js @@ -1,6 +1,10 @@ -QUnit.module('Cue Metadata Text Tracks', window.sharedModuleHooks({ +import QUnit from 'qunit'; +import sinon from 'sinon'; +import sharedModuleHooks from './lib/shared-module-hooks.js'; - beforeEach: function() { +QUnit.module('Cue Metadata Text Tracks', sharedModuleHooks({ + + beforeEach() { this.tt = { player: this.player, kind: 'metadata', @@ -8,7 +12,7 @@ QUnit.module('Cue Metadata Text Tracks', window.sharedModuleHooks({ id: '1', startTime: 1, endTime: 2, - addEventListener: function(event, cb) { + addEventListener(event, cb) { if (event === 'cuechange') { cb.apply(this, [this]); } @@ -16,7 +20,7 @@ QUnit.module('Cue Metadata Text Tracks', window.sharedModuleHooks({ activeCues: [] }; }, - afterEach: function() { + afterEach() { this.player.ads.cueTextTracks.getSupportedAdCue = function(player, cue) { return cue; }; @@ -30,9 +34,9 @@ QUnit.module('Cue Metadata Text Tracks', window.sharedModuleHooks({ })); QUnit.test('runs processMetadataTrack callback as tracks are added', function(assert) { - var tt = this.tt; - var processMetadataTrackSpy = sinon.spy(); - var cueTextTracks = this.player.ads.cueTextTracks; + const tt = this.tt; + const processMetadataTrackSpy = sinon.spy(); + const cueTextTracks = this.player.ads.cueTextTracks; // Start by adding a text track before processing this.player.addRemoteTextTrack(tt); @@ -49,23 +53,24 @@ QUnit.test('runs processMetadataTrack callback as tracks are added', function(as }); QUnit.test('does not call processMetadataTrack callback until tracks available', function(assert) { - var processMetadataTrackSpy = sinon.spy(); - var cueTextTracks = this.player.ads.cueTextTracks; + const processMetadataTrackSpy = sinon.spy(); + const cueTextTracks = this.player.ads.cueTextTracks; cueTextTracks.processMetadataTracks(this.player, processMetadataTrackSpy); assert.strictEqual(processMetadataTrackSpy.callCount, 0); - var addTrackEvent = { + const addTrackEvent = { track: this.tt, type: 'addtrack' }; + this.player.textTracks().trigger(addTrackEvent); assert.strictEqual(processMetadataTrackSpy.callCount, 1); }); QUnit.test('setMetadataTrackMode should work when overriden', function(assert) { - var tt = this.tt; - var cueTextTracks = this.player.ads.cueTextTracks; + const tt = this.tt; + const cueTextTracks = this.player.ads.cueTextTracks; cueTextTracks.setMetadataTrackMode(tt); assert.strictEqual(tt.mode, 'hidden'); @@ -78,16 +83,17 @@ QUnit.test('setMetadataTrackMode should work when overriden', function(assert) { }); QUnit.test('getSupportedAdCue should work when overriden', function(assert) { - var cue = { + const cue = { startTime: 0, endTime: 1 }; - var cueTextTracks = this.player.ads.cueTextTracks; - var supportedCue = cueTextTracks.getSupportedAdCue(this.player, cue); + const cueTextTracks = this.player.ads.cueTextTracks; + let supportedCue = cueTextTracks.getSupportedAdCue(this.player, cue); + assert.strictEqual(supportedCue, cue); - cueTextTracks.getSupportedAdCue = function(player, cue) { + cueTextTracks.getSupportedAdCue = function(player, subcue) { return -1; }; supportedCue = cueTextTracks.getSupportedAdCue(this.player, cue); @@ -95,8 +101,8 @@ QUnit.test('getSupportedAdCue should work when overriden', function(assert) { }); QUnit.test('getCueId should work when overriden', function(assert) { - var originalTextTracks = this.player.textTracks; - var cue = { + const originalTextTracks = this.player.textTracks; + const cue = { startTime: 0, endTime: 1, id: 1, @@ -104,7 +110,8 @@ QUnit.test('getCueId should work when overriden', function(assert) { id: 2 } }; - var tt = this.tt; + const tt = this.tt; + tt.activeCues = [cue]; this.player.textTracks = function() { @@ -114,12 +121,13 @@ QUnit.test('getCueId should work when overriden', function(assert) { }; }; - var cueTextTracks = this.player.ads.cueTextTracks; - var cueId = cueTextTracks.getCueId(cue); + const cueTextTracks = this.player.ads.cueTextTracks; + let cueId = cueTextTracks.getCueId(cue); + assert.strictEqual(cueId, 1); - cueTextTracks.getCueId = function(cue) { - return cue.inner.id; + cueTextTracks.getCueId = function(subcue) { + return subcue.inner.id; }; cueId = cueTextTracks.getCueId(cue); assert.strictEqual(cueId, 2); @@ -129,9 +137,9 @@ QUnit.test('getCueId should work when overriden', function(assert) { }); QUnit.test('processAdTrack runs processCue callback', function(assert) { - var processCueSpy = sinon.spy(); - var cueTextTracks = this.player.ads.cueTextTracks; - var cues = [{ + const processCueSpy = sinon.spy(); + const cueTextTracks = this.player.ads.cueTextTracks; + const cues = [{ startTime: 0, endTime: 1, id: 1, @@ -141,26 +149,27 @@ QUnit.test('processAdTrack runs processCue callback', function(assert) { cueTextTracks.processAdTrack(this.player, cues, processCueSpy); assert.strictEqual(processCueSpy.callCount, 1); - var processCue = function(player, cueData, cueId, startTime) { + const processCue = function(player, cueData, cueId, startTime) { cueData.callCount += 1; }; + cueTextTracks.processAdTrack(this.player, cues, processCue); assert.strictEqual(cues[0].callCount, 1); }); QUnit.test('processAdTrack runs cancelAds callback', function(assert) { - var cancelAdsSpy = sinon.spy(); - var cueTextTracks = this.player.ads.cueTextTracks; - var cues = [{ + const cancelAdsSpy = sinon.spy(); + const cueTextTracks = this.player.ads.cueTextTracks; + const cues = [{ startTime: 0, endTime: 1, id: 1, callCount: 0 }]; - var processCue = function(player, cueData, cueId, startTime) { + const processCue = function(player, cueData, cueId, startTime) { return; }; - var cancelAds = function(player, cueData, cueId, startTime) { + const cancelAds = function(player, cueData, cueId, startTime) { cueData.callCount += 1; }; diff --git a/test/integration/test.events-midroll.js b/test/integration/test.events-midroll.js index 0e6ee67d..7482122a 100644 --- a/test/integration/test.events-midroll.js +++ b/test/integration/test.events-midroll.js @@ -9,9 +9,11 @@ TODO: import videojs from 'video.js'; import '../../examples/basic-ad-plugin/example-plugin.js'; +import document from 'global/document'; +import QUnit from 'qunit'; QUnit.module('Events and Midrolls', { - beforeEach: function() { + beforeEach() { this.video = document.createElement('video'); this.fixture = document.querySelector('#qunit-fixture'); @@ -20,9 +22,9 @@ QUnit.module('Events and Midrolls', { this.player = videojs(this.video); this.player.exampleAds({ - 'adServerUrl': '/base/test/integration/lib/inventory.json', - 'playPreroll': false, - 'midrollPoint': 1 + adServerUrl: '/base/test/integration/lib/inventory.json', + playPreroll: false, + midrollPoint: 1 }); this.player.src({ @@ -31,25 +33,25 @@ QUnit.module('Events and Midrolls', { }); }, - afterEach: function() { + afterEach() { this.player.dispose(); } }); QUnit.test('Midrolls', function(assert) { - var done = assert.async(); + const done = assert.async(); - var beforeMidroll = true; - var seenInAdMode = []; - var seenInContentResuming = []; - var seenOutsideAdModeBefore = []; - var seenOutsideAdModeAfter = []; + let beforeMidroll = true; + const seenInAdMode = []; + const seenInContentResuming = []; + const seenOutsideAdModeBefore = []; + const seenOutsideAdModeAfter = []; this.player.on('adend', () => { beforeMidroll = false; }); - var events = [ + let events = [ 'suspend', 'abort', 'error', @@ -79,19 +81,18 @@ QUnit.test('Midrolls', function(assert) { })); this.player.on(events, (e) => { - var str = e.type; + const str = e.type; + if (this.player.ads.isInAdMode()) { if (this.player.ads.isContentResuming()) { seenInContentResuming.push(str); } else { seenInAdMode.push(str); } + } else if (beforeMidroll) { + seenOutsideAdModeBefore.push(str); } else { - if (beforeMidroll) { - seenOutsideAdModeBefore.push(str); - } else { - seenOutsideAdModeAfter.push(str); - } + seenOutsideAdModeAfter.push(str); } }); @@ -128,7 +129,7 @@ QUnit.test('Midrolls', function(assert) { // Seek to right before the midroll this.player.one('playing', () => { - this.player.currentTime(.9); + this.player.currentTime(0.9); }); this.player.ready(this.player.play); diff --git a/test/integration/test.events-no-postroll.js b/test/integration/test.events-no-postroll.js index 31b48288..e824a27b 100644 --- a/test/integration/test.events-no-postroll.js +++ b/test/integration/test.events-no-postroll.js @@ -1,8 +1,10 @@ import videojs from 'video.js'; import '../../examples/basic-ad-plugin/example-plugin.js'; +import QUnit from 'qunit'; +import document from 'global/document'; QUnit.module('Final Events With No Postroll', { - beforeEach: function() { + beforeEach() { this.video = document.createElement('video'); this.fixture = document.querySelector('#qunit-fixture'); @@ -11,10 +13,10 @@ QUnit.module('Final Events With No Postroll', { this.player = videojs(this.video); this.player.exampleAds({ - 'adServerUrl': '/base/test/integration/lib/inventory.json', - 'playPreroll': false, - 'playMidroll': false, - 'playPostroll': false + adServerUrl: '/base/test/integration/lib/inventory.json', + playPreroll: false, + playMidroll: false, + playPostroll: false }); this.player.src({ @@ -23,14 +25,14 @@ QUnit.module('Final Events With No Postroll', { }); }, - afterEach: function() { + afterEach() { this.player.dispose(); } }); QUnit.test('final ended event with no postroll: just 1', function(assert) { - var done = assert.async(); - var endedEvents = 0; + const done = assert.async(); + let endedEvents = 0; // Prevent the test from timing out by making it run faster this.player.ads.settings.postrollTimeout = 1; diff --git a/test/integration/test.events-no-preroll.js b/test/integration/test.events-no-preroll.js index b58b53cd..76a3a134 100644 --- a/test/integration/test.events-no-preroll.js +++ b/test/integration/test.events-no-preroll.js @@ -1,8 +1,10 @@ import videojs from 'video.js'; import '../../examples/basic-ad-plugin/example-plugin.js'; +import QUnit from 'qunit'; +import document from 'global/document'; QUnit.module('Initial Events With No Preroll', { - beforeEach: function() { + beforeEach() { this.video = document.createElement('video'); this.fixture = document.querySelector('#qunit-fixture'); @@ -11,9 +13,9 @@ QUnit.module('Initial Events With No Preroll', { this.player = videojs(this.video); this.player.exampleAds({ - 'adServerUrl': '/base/test/integration/lib/inventory.json', - 'playPreroll': false, - 'playMidroll': false + adServerUrl: '/base/test/integration/lib/inventory.json', + playPreroll: false, + playMidroll: false }); this.player.src({ @@ -22,15 +24,15 @@ QUnit.module('Initial Events With No Preroll', { }); }, - afterEach: function() { + afterEach() { this.player.dispose(); } }); QUnit.test('initial play event with no preroll: one please', function(assert) { - var done = assert.async(); + const done = assert.async(); - var playEvents = 0; + let playEvents = 0; this.player.on('play', () => { playEvents++; @@ -53,9 +55,9 @@ QUnit.test('initial play event with no preroll: one please', function(assert) { }); QUnit.test('initial playing event with no preroll: 1+', function(assert) { - var done = assert.async(); + const done = assert.async(); - var playingEvents = 0; + let playingEvents = 0; this.player.on('playing', () => { playingEvents++; @@ -77,11 +79,10 @@ QUnit.test('initial playing event with no preroll: 1+', function(assert) { }); - QUnit.test('no ended event at start if video with no preroll', function(assert) { - var done = assert.async(); + const done = assert.async(); - var endedEvents = 0; + let endedEvents = 0; this.player.on('ended', () => { endedEvents++; @@ -104,9 +105,9 @@ QUnit.test('no ended event at start if video with no preroll', function(assert) }); QUnit.test('initial loadstart event with no preroll: one please', function(assert) { - var done = assert.async(); + const done = assert.async(); - var loadstartEvents = 0; + let loadstartEvents = 0; this.player.on('loadstart', () => { loadstartEvents++; diff --git a/test/integration/test.events-postroll.js b/test/integration/test.events-postroll.js index 20ca1038..5075d42b 100644 --- a/test/integration/test.events-postroll.js +++ b/test/integration/test.events-postroll.js @@ -10,9 +10,11 @@ TODO: import videojs from 'video.js'; import '../../examples/basic-ad-plugin/example-plugin.js'; +import document from 'global/document'; +import QUnit from 'qunit'; QUnit.module('Events and Postrolls', { - beforeEach: function() { + beforeEach() { this.video = document.createElement('video'); this.fixture = document.querySelector('#qunit-fixture'); @@ -21,9 +23,9 @@ QUnit.module('Events and Postrolls', { this.player = videojs(this.video); this.player.exampleAds({ - 'adServerUrl': '/base/test/integration/lib/inventory.json', - 'playPreroll': false, - 'playMidroll': false + adServerUrl: '/base/test/integration/lib/inventory.json', + playPreroll: false, + playMidroll: false }); this.player.src({ @@ -33,17 +35,17 @@ QUnit.module('Events and Postrolls', { }, - afterEach: function() { + afterEach() { this.player.dispose(); } }); QUnit.test('ended event and postrolls: 0 before postroll, 1 after', function(assert) { - var done = assert.async(); + const done = assert.async(); - var beforePostroll = true; - var endedBeforePostroll = 0; - var endedAfterPostroll = 0; + let beforePostroll = true; + let endedBeforePostroll = 0; + let endedAfterPostroll = 0; this.player.on('adend', () => { beforePostroll = false; @@ -82,19 +84,19 @@ QUnit.test('ended event and postrolls: 0 before postroll, 1 after', function(ass }); QUnit.test('Event prefixing and postrolls', function(assert) { - var done = assert.async(); + const done = assert.async(); - var beforePostroll = true; - var seenInAdMode = []; - var seenInContentResuming = []; - var seenOutsideAdModeBefore = []; - var seenOutsideAdModeAfter = []; + let beforePostroll = true; + const seenInAdMode = []; + const seenInContentResuming = []; + const seenOutsideAdModeBefore = []; + const seenOutsideAdModeAfter = []; this.player.on('adend', () => { beforePostroll = false; }); - var events = [ + let events = [ 'suspend', 'abort', 'error', @@ -127,19 +129,18 @@ QUnit.test('Event prefixing and postrolls', function(assert) { if (e.type === 'contentended') { return; } - var str = e.type; + const str = e.type; + if (this.player.ads.isInAdMode()) { if (this.player.ads.isContentResuming()) { seenInContentResuming.push(str); } else { seenInAdMode.push(str); } + } else if (beforePostroll) { + seenOutsideAdModeBefore.push(str); } else { - if (beforePostroll) { - seenOutsideAdModeBefore.push(str); - } else { - seenOutsideAdModeAfter.push(str); - } + seenOutsideAdModeAfter.push(str); } }); diff --git a/test/integration/test.events-preroll.js b/test/integration/test.events-preroll.js index 800be913..10bc6b3d 100644 --- a/test/integration/test.events-preroll.js +++ b/test/integration/test.events-preroll.js @@ -10,9 +10,11 @@ TODO: import videojs from 'video.js'; import '../../examples/basic-ad-plugin/example-plugin.js'; +import QUnit from 'qunit'; +import document from 'global/document'; QUnit.module('Events and Prerolls', { - beforeEach: function() { + beforeEach() { this.video = document.createElement('video'); this.fixture = document.querySelector('#qunit-fixture'); @@ -21,7 +23,7 @@ QUnit.module('Events and Prerolls', { this.player = videojs(this.video); this.player.exampleAds({ - 'adServerUrl': '/base/test/integration/lib/inventory.json' + adServerUrl: '/base/test/integration/lib/inventory.json' }); this.player.src({ @@ -31,17 +33,17 @@ QUnit.module('Events and Prerolls', { }, - afterEach: function() { + afterEach() { this.player.dispose(); } }); QUnit.test('playing event and prerolls: 0 before preroll, 1+ after', function(assert) { - var done = assert.async(); + const done = assert.async(); - var beforePreroll = true; - var playingBeforePreroll = 0; - var playingAfterPreroll = 0; + let beforePreroll = true; + let playingBeforePreroll = 0; + let playingAfterPreroll = 0; this.player.on('adend', () => { beforePreroll = false; @@ -73,9 +75,9 @@ QUnit.test('playing event and prerolls: 0 before preroll, 1+ after', function(as }); QUnit.test('ended event and prerolls: not even once', function(assert) { - var done = assert.async(); + const done = assert.async(); - var ended = 0; + let ended = 0; this.player.on('ended', () => { ended++; @@ -98,11 +100,11 @@ QUnit.test('ended event and prerolls: not even once', function(assert) { }); QUnit.test('loadstart event and prerolls: 1 before preroll, 0 after', function(assert) { - var done = assert.async(); + const done = assert.async(); - var beforePreroll = true; - var loadstartBeforePreroll = 0; - var loadstartAfterPreroll = 0; + let beforePreroll = true; + let loadstartBeforePreroll = 0; + let loadstartAfterPreroll = 0; this.player.on('adend', () => { beforePreroll = false; @@ -134,11 +136,11 @@ QUnit.test('loadstart event and prerolls: 1 before preroll, 0 after', function(a }); QUnit.test('loadedmetadata event and prerolls: 1 before preroll, 0 after', function(assert) { - var done = assert.async(); + const done = assert.async(); - var beforePreroll = true; - var loadedmetadataBeforePreroll = 0; - var loadedmetadataAfterPreroll = 0; + let beforePreroll = true; + let loadedmetadataBeforePreroll = 0; + let loadedmetadataAfterPreroll = 0; this.player.on('adend', () => { beforePreroll = false; @@ -170,11 +172,11 @@ QUnit.test('loadedmetadata event and prerolls: 1 before preroll, 0 after', funct }); QUnit.test('loadeddata event and prerolls: 1 before preroll, 0 after', function(assert) { - var done = assert.async(); + const done = assert.async(); - var beforePreroll = true; - var loadeddataBeforePreroll = 0; - var loadeddataAfterPreroll = 0; + let beforePreroll = true; + let loadeddataBeforePreroll = 0; + let loadeddataAfterPreroll = 0; this.player.on('adend', () => { beforePreroll = false; @@ -206,11 +208,11 @@ QUnit.test('loadeddata event and prerolls: 1 before preroll, 0 after', function( }); QUnit.test('play event and prerolls: 1 before preroll, 0 after', function(assert) { - var done = assert.async(); + const done = assert.async(); - var beforePreroll = true; - var playBeforePreroll = 0; - var playAfterPreroll = 0; + let beforePreroll = true; + let playBeforePreroll = 0; + let playAfterPreroll = 0; this.player.on('adend', () => { beforePreroll = false; @@ -231,7 +233,8 @@ QUnit.test('play event and prerolls: 1 before preroll, 0 after', function(assert this.player.on('timeupdate', () => { if (this.player.currentTime() > 1) { - assert.equal(playBeforePreroll, 1, 'play before preroll'); // 2 + // 2 + assert.equal(playBeforePreroll, 1, 'play before preroll'); assert.equal(playAfterPreroll, 0, 'play after preroll'); done(); } @@ -242,19 +245,19 @@ QUnit.test('play event and prerolls: 1 before preroll, 0 after', function(assert }); QUnit.test('Event prefixing and prerolls', function(assert) { - var done = assert.async(); + const done = assert.async(); - var beforePreroll = true; - var seenInAdMode = []; - var seenInContentResuming = []; - var seenOutsideAdModeBefore = []; - var seenOutsideAdModeAfter = []; + let beforePreroll = true; + const seenInAdMode = []; + const seenInContentResuming = []; + const seenOutsideAdModeBefore = []; + const seenOutsideAdModeAfter = []; this.player.on('adend', () => { beforePreroll = false; }); - var events = [ + let events = [ 'suspend', 'abort', 'error', @@ -283,19 +286,18 @@ QUnit.test('Event prefixing and prerolls', function(assert) { })); this.player.on(events, (e) => { - var str = e.type; + const str = e.type; + if (this.player.ads.isInAdMode()) { if (this.player.ads.isContentResuming()) { seenInContentResuming.push(str); } else { seenInAdMode.push(str); } + } else if (beforePreroll) { + seenOutsideAdModeBefore.push(str); } else { - if (beforePreroll) { - seenOutsideAdModeBefore.push(str); - } else { - seenOutsideAdModeAfter.push(str); - } + seenOutsideAdModeAfter.push(str); } }); diff --git a/test/integration/test.macros.js b/test/integration/test.macros.js index 052fd61c..fda66f69 100644 --- a/test/integration/test.macros.js +++ b/test/integration/test.macros.js @@ -1,13 +1,19 @@ -QUnit.module('Ad Macros', window.sharedModuleHooks({})); +import QUnit from 'qunit'; +import window from 'global/window'; +import document from 'global/document'; +import sharedModuleHooks from './lib/shared-module-hooks.js'; + +QUnit.module('Ad Macros', sharedModuleHooks({})); QUnit.test('player.id', function(assert) { this.player.options_['data-player'] = '12345'; - var result = this.player.ads.adMacroReplacement('{player.id}'); + const result = this.player.ads.adMacroReplacement('{player.id}'); assert.equal(result, '12345'); }); QUnit.test('mediainfo', function(assert) { + /* eslint-disable camelcase */ this.player.mediainfo = { id: 1, name: 2, @@ -17,58 +23,64 @@ QUnit.test('mediainfo', function(assert) { duration: 6, ad_keys: 7 }; - var result = this.player.ads.adMacroReplacement( - '{mediainfo.id}' + + /* eslint-enable camelcase */ + const result = this.player.ads.adMacroReplacement('{mediainfo.id}' + '{mediainfo.name}' + '{mediainfo.description}' + '{mediainfo.tags}' + '{mediainfo.reference_id}' + '{mediainfo.duration}' + - '{mediainfo.ad_keys}' - ); + '{mediainfo.ad_keys}'); assert.equal(result, '1234567'); }); QUnit.test('player.duration', function(assert) { - this.player.duration = function() {return 5;}; - var result = this.player.ads.adMacroReplacement('{player.duration}'); + this.player.duration = function() { + return 5; + }; + const result = this.player.ads.adMacroReplacement('{player.duration}'); assert.equal(result, 5); }); QUnit.test('timestamp', function(assert) { - this.player.duration = function() {return 5;}; - var result = this.player.ads.adMacroReplacement('{timestamp}'); + this.player.duration = function() { + return 5; + }; + const result = this.player.ads.adMacroReplacement('{timestamp}'); assert.equal(result, new Date().getTime()); }); QUnit.test('document.referrer', function(assert) { - var result = this.player.ads.adMacroReplacement('{document.referrer}'); + const result = this.player.ads.adMacroReplacement('{document.referrer}'); assert.equal( result, document.referrer, - '"' + result + '" was the document.referrer'); + '"' + result + '" was the document.referrer' + ); }); QUnit.test('window.location.href', function(assert) { - var result = this.player.ads.adMacroReplacement('{window.location.href}'); + const result = this.player.ads.adMacroReplacement('{window.location.href}'); assert.equal( result, window.location.href, - '"' + result + '" was the window.location.href'); + '"' + result + '" was the window.location.href' + ); }); QUnit.test('random', function(assert) { - var result = this.player.ads.adMacroReplacement('{random}'); + const result = this.player.ads.adMacroReplacement('{random}'); assert.ok(result.match(/^\d+$/), '"' + result + '" is a random number'); }); QUnit.test('mediainfo.custom_fields', function(assert) { + /* eslint-disable camelcase */ this.player.mediainfo = { custom_fields: { dog: 1, @@ -81,14 +93,13 @@ QUnit.test('mediainfo.custom_fields', function(assert) { guinea_pig: 3 } }; - var result = this.player.ads.adMacroReplacement( - '{mediainfo.custom_fields.dog}' + + /* eslint-enable camelcase */ + const result = this.player.ads.adMacroReplacement('{mediainfo.custom_fields.dog}' + '{mediainfo.custom_fields.cat}' + '{mediainfo.custom_fields.guinea_pig}' + '{mediainfo.customFields.dog}' + '{mediainfo.customFields.cat}' + - '{mediainfo.customFields.guinea_pig}' - ); + '{mediainfo.customFields.guinea_pig}'); assert.equal(result, '123123'); }); @@ -109,8 +120,7 @@ QUnit.test('pageVariables', function(assert) { window.foo = function() {}; window.bar = {}; - var result = this.player.ads.adMacroReplacement( - 'Number: {pageVariable.scrollX}, ' + + const result = this.player.ads.adMacroReplacement('Number: {pageVariable.scrollX}, ' + 'Boolean: {pageVariable.isAwesome}, ' + 'Null: {pageVariable.bird}, ' + 'Undefined: {pageVariable.thisDoesNotExist}, ' + @@ -118,10 +128,10 @@ QUnit.test('pageVariables', function(assert) { 'Object: {pageVariable.bar}, ' + 'Nested 2x: {pageVariable.animal.dog}, ' + 'Nested 3x: {pageVariable.animal.cat.maineCoon}, ' + - 'Nested 4x: {pageVariable.animal.cat.champion.name}' - ); + 'Nested 4x: {pageVariable.animal.cat.champion.name}'); - assert.equal(result, + assert.equal( + result, 'Number: 0, ' + 'Boolean: true, ' + 'Null: null, ' + @@ -135,37 +145,37 @@ QUnit.test('pageVariables', function(assert) { }); QUnit.test('uriEncode', function(assert) { + /* eslint-disable camelcase */ this.player.mediainfo = { custom_fields: { urlParam: '? &' } }; + /* eslint-enable camelcase */ window.foo = '& ?'; - var result = this.player.ads.adMacroReplacement( - '{mediainfo.custom_fields.urlParam}{pageVariable.foo}', true - ); + const result = this.player.ads.adMacroReplacement('{mediainfo.custom_fields.urlParam}{pageVariable.foo}', true); assert.equal(result, '%3F%20%26%26%20%3F'); }); QUnit.test('customMacros', function(assert) { - var result = this.player.ads.adMacroReplacement( - 'The sky is {skyColor}. {exclamation}!', false, { - '{skyColor}': 'blue', - '{exclamation}': 'Hooray' - } - ); + const result = this.player.ads.adMacroReplacement('The sky is {skyColor}. {exclamation}!', false, { + '{skyColor}': 'blue', + '{exclamation}': 'Hooray' + }); assert.equal(result, 'The sky is blue. Hooray!'); }); QUnit.test('default values', function(assert) { + /* eslint-disable camelcase */ this.player.mediainfo = { customFields: { set: 1 }, reference_id: 'abc' }; + /* eslint-enable camelcase */ window.testvar1 = 'a'; assert.equal( diff --git a/test/integration/test.playMiddleware.js b/test/integration/test.playMiddleware.js index 3478fb7e..2c844721 100644 --- a/test/integration/test.playMiddleware.js +++ b/test/integration/test.playMiddleware.js @@ -1,8 +1,11 @@ import videojs from 'video.js'; import '../../examples/basic-ad-plugin/example-plugin.js'; +import QUnit from 'qunit'; +import document from 'global/document'; +import sinon from 'sinon'; QUnit.module('Integration: play middleware', { - beforeEach: function() { + beforeEach() { this.video = document.createElement('video'); this.fixture = document.querySelector('#qunit-fixture'); @@ -11,11 +14,11 @@ QUnit.module('Integration: play middleware', { this.player = videojs(this.video); this.player.exampleAds({ - 'adServerUrl': '/base/test/integration/lib/inventory.json' + adServerUrl: '/base/test/integration/lib/inventory.json' }); }, - afterEach: function() { + afterEach() { this.player.dispose(); } }); @@ -30,16 +33,20 @@ QUnit.test('the `_playRequested` flag is set on the first play request', functio // When the preroll starts this.player.on('adstart', () => { - assert.strictEqual(this.player.ads._playRequested, true, - '_playRequested is true when the play method is used'); + assert.strictEqual( + this.player.ads._playRequested, true, + '_playRequested is true when the play method is used' + ); done(); }); // If there wasn't an ad this.player.on('timeupdate', () => { if (this.player.currentTime() > 0) { - assert.strictEqual(this.player.ads._playRequested, true, - '_playRequested is true when the play method is used'); + assert.strictEqual( + this.player.ads._playRequested, true, + '_playRequested is true when the play method is used' + ); done(); } }); @@ -60,20 +67,28 @@ QUnit.test('blocks calls to play to wait for prerolls if adsready BEFORE play', // When the preroll starts this.player.on('adstart', () => { - assert.strictEqual(techPlaySpy.callCount, 0, - "tech play shouldn't be called while waiting for prerolls"); - assert.strictEqual(playEventSpy.callCount, 1, - 'play event should be triggered'); + assert.strictEqual( + techPlaySpy.callCount, 0, + "tech play shouldn't be called while waiting for prerolls" + ); + assert.strictEqual( + playEventSpy.callCount, 1, + 'play event should be triggered' + ); done(); }); // Once we are in content this.player.on('timeupdate', () => { if (this.player.currentTime() > 0) { - assert.strictEqual(techPlaySpy.callCount, 0, - "tech play shouldn't be called while waiting for prerolls"); - assert.strictEqual(playEventSpy.callCount, 1, - 'play event should be triggered'); + assert.strictEqual( + techPlaySpy.callCount, 0, + "tech play shouldn't be called while waiting for prerolls" + ); + assert.strictEqual( + playEventSpy.callCount, 1, + 'play event should be triggered' + ); done(); } }); @@ -107,8 +122,10 @@ QUnit.test('stops blocking play when an ad is playing', function(assert) { // Wait for the ad to start playing this.player.on('ads-ad-started', () => { - assert.strictEqual(this.player.ads._shouldBlockPlay, false, - 'should stop blocking once in an adbreak'); + assert.strictEqual( + this.player.ads._shouldBlockPlay, false, + 'should stop blocking once in an adbreak' + ); done(); }); @@ -130,8 +147,10 @@ QUnit.test("playMiddleware doesn\'t block play in content playback", function(as // Wait for the ad to start playing this.player.on('timeupdate', () => { if (this.player.currentTime() > 0) { - assert.strictEqual(this.player.ads._shouldBlockPlay, false, - 'should stop blocking in content'); + assert.strictEqual( + this.player.ads._shouldBlockPlay, false, + 'should stop blocking in content' + ); done(); } }); @@ -151,7 +170,7 @@ QUnit.test("don't trigger play event if another middleware terminates", function const playSpy = sinon.spy(); let shouldTerminate = true; - let anotherMiddleware = function(player) { + const anotherMiddleware = function(player) { return { setSource(srcObj, next) { next(null, srcObj); @@ -166,14 +185,13 @@ QUnit.test("don't trigger play event if another middleware terminates", function } }; }; - let localPlayer; // Register the other middleware videojs.use('video/webm', anotherMiddleware); // Don't use the shared player, setup new localPlayer fixture.appendChild(vid); - localPlayer = videojs(vid); + const localPlayer = videojs(vid); // Setup before example integration localPlayer.on('nopreroll', () => { @@ -182,7 +200,7 @@ QUnit.test("don't trigger play event if another middleware terminates", function // Don't play preroll ads localPlayer.exampleAds({ - 'adServerUrl': '/base/test/integration/lib/inventory.json', + adServerUrl: '/base/test/integration/lib/inventory.json', playPreroll: false }); @@ -190,10 +208,14 @@ QUnit.test("don't trigger play event if another middleware terminates", function // Wait for the middleware to run localPlayer.setTimeout(() => { - assert.strictEqual(localPlayer.ads._playBlocked, false, - 'play should not have been blocked'); - assert.strictEqual(playSpy.callCount, 0, - 'play event should not be triggered'); + assert.strictEqual( + localPlayer.ads._playBlocked, false, + 'play should not have been blocked' + ); + assert.strictEqual( + playSpy.callCount, 0, + 'play event should not be triggered' + ); done(); }, 1); @@ -201,4 +223,4 @@ QUnit.test("don't trigger play event if another middleware terminates", function src: 'http://vjs.zencdn.net/v/oceans.webm', type: 'video/webm' }); -}); \ No newline at end of file +}); diff --git a/test/integration/test.snapshot.js b/test/integration/test.snapshot.js index ad6410df..59ce06fe 100644 --- a/test/integration/test.snapshot.js +++ b/test/integration/test.snapshot.js @@ -1,11 +1,16 @@ import videojs from 'video.js'; import * as snapshot from '../../src/snapshot.js'; +import QUnit from 'qunit'; +import document from 'global/document'; +import window from 'global/window'; +import sinon from 'sinon'; +import sharedModuleHooks from './lib/shared-module-hooks.js'; -QUnit.module('Video Snapshot', window.sharedModuleHooks({ +QUnit.module('Video Snapshot', sharedModuleHooks({ - beforeEach: function() { - var captionTrack = document.createElement('track'); - var otherTrack = document.createElement('track'); + beforeEach() { + const captionTrack = document.createElement('track'); + const otherTrack = document.createElement('track'); captionTrack.setAttribute('kind', 'captions'); captionTrack.setAttribute('src', '/base/test/integration/lib/testcaption.vtt'); @@ -20,7 +25,7 @@ QUnit.module('Video Snapshot', window.sharedModuleHooks({ })); QUnit.test('restores the original video src after ads', function(assert) { - var originalSrc = { + const originalSrc = { src: 'http://vjs.zencdn.net/v/oceans.webm', type: 'video/webm' }; @@ -39,7 +44,6 @@ QUnit.test('restores the original video src after ads', function(assert) { }); QUnit.test('waits for the video to become seekable before restoring the time', function(assert) { - var setTimeoutSpy; assert.expect(2); @@ -47,7 +51,8 @@ QUnit.test('waits for the video to become seekable before restoring the time', f this.player.trigger('play'); // the video plays to time 100 - setTimeoutSpy = sinon.spy(window, 'setTimeout'); + const setTimeoutSpy = sinon.spy(window, 'setTimeout'); + this.video.currentTime = 100; this.player.ads.startLinearAdMode(); this.player.src({ @@ -58,7 +63,8 @@ QUnit.test('waits for the video to become seekable before restoring the time', f // the ad resets the current time this.video.currentTime = 0; this.player.ads.endLinearAdMode(); - setTimeoutSpy.reset(); // we call setTimeout an extra time restorePlayerSnapshot + // we call setTimeout an extra time restorePlayerSnapshot + setTimeoutSpy.reset(); this.player.trigger('canplay'); assert.strictEqual(setTimeoutSpy.callCount, 1, 'restoring the time should be delayed'); assert.strictEqual(this.video.currentTime, 0, 'currentTime is not modified'); @@ -88,13 +94,11 @@ QUnit.test('the current time is restored at the end of an ad', function(assert) }); QUnit.test('only restores the player snapshot if the src changed', function(assert) { - var playSpy, srcSpy, currentTimeSpy; - this.player.trigger('adsready'); this.player.trigger('play'); - playSpy = sinon.spy(this.player, 'play'); - srcSpy = sinon.spy(this.player, 'src'); - currentTimeSpy = sinon.spy(this.player, 'currentTime'); + const playSpy = sinon.spy(this.player, 'play'); + const srcSpy = sinon.spy(this.player, 'src'); + const currentTimeSpy = sinon.spy(this.player, 'currentTime'); // with a separate video display or server-side ad insertion, ads play but // the src never changes. Modifying the src or currentTime would introduce @@ -113,7 +117,7 @@ QUnit.test('only restores the player snapshot if the src changed', function(asse }); QUnit.test('snapshot does not resume playback after post-rolls', function(assert) { - var playSpy = sinon.spy(this.player, 'play'); + const playSpy = sinon.spy(this.player, 'play'); // start playback this.player.src({ @@ -176,12 +180,11 @@ QUnit.test('snapshot does not resume playback after post-rolls', function(assert }); QUnit.test('snapshot does not resume playback after a burned-in post-roll', function(assert) { - var playSpy, loadSpy; - this.player.trigger('adsready'); this.player.trigger('play'); - playSpy = sinon.spy(this.player, 'play'); - loadSpy = sinon.spy(this.player, 'load'); + const playSpy = sinon.spy(this.player, 'play'); + const loadSpy = sinon.spy(this.player, 'load'); + this.player.ads.startLinearAdMode(); this.player.ads.endLinearAdMode(); this.player.trigger('playing'); @@ -209,8 +212,6 @@ QUnit.test('snapshot does not resume playback after a burned-in post-roll', func }); QUnit.test('snapshot does not resume playback after multiple post-rolls', function(assert) { - var playSpy; - this.player.src({ src: 'http://vjs.zencdn.net/v/oceans.webm', type: 'video/webm' @@ -218,7 +219,7 @@ QUnit.test('snapshot does not resume playback after multiple post-rolls', functi this.player.trigger('loadstart'); this.player.trigger('adsready'); this.player.trigger('play'); - playSpy = sinon.spy(this.player, 'play'); + const playSpy = sinon.spy(this.player, 'play'); // with a separate video display or server-side ad insertion, ads play but // the src never changes. Modifying the src or currentTime would introduce @@ -264,7 +265,7 @@ QUnit.test('changing the source and then timing out does not restore a snapshot' // load and play the initial video this.player.src({ - src:'http://example.com/movie.webm', + src: 'http://example.com/movie.webm', type: 'video/webm' }); this.player.trigger('loadstart'); @@ -290,7 +291,7 @@ QUnit.test('changing the source and then timing out does not restore a snapshot' // doesn't update currentSrc, so when restoring the snapshot we // should check for src attribute modifications as well QUnit.test('checks for a src attribute change that isn\'t reflected in currentSrc', function(assert) { - var updatedSrc; + let updatedSrc; this.player.currentSource = function() { return {src: 'content.webm', type: 'video/webm'}; @@ -317,7 +318,6 @@ QUnit.test('checks for a src attribute change that isn\'t reflected in currentSr updatedSrc = source; }; - this.player.ads.endLinearAdMode(); this.player.trigger('playing'); assert.deepEqual(updatedSrc, [this.player.currentSource()], 'restored src attribute'); @@ -325,20 +325,19 @@ QUnit.test('checks for a src attribute change that isn\'t reflected in currentSr QUnit.test('When captions are enabled, the content\'s tracks will be disabled during the ad', function(assert) { const trackSrc = '/base/test/integration/lib/testcaption.vtt'; - let remoteTrack; // Add a text track - remoteTrack = this.player.addRemoteTextTrack({ + const remoteTrack = this.player.addRemoteTextTrack({ kind: 'captions', language: 'fr', label: 'French', src: trackSrc }); - var tracks = this.player.textTracks ? this.player.textTracks() : []; - var showing = 0; - var disabled = 0; - var i; + const tracks = this.player.textTracks ? this.player.textTracks() : []; + let showing = 0; + let disabled = 0; + let i; if (tracks.length <= 0) { assert.expect(0); @@ -388,8 +387,8 @@ QUnit.test('When captions are enabled, the content\'s tracks will be disabled du }); QUnit.test('No snapshot if duration is Infinity', function(assert) { - var originalSrc = 'foobar'; - var newSrc = 'barbaz'; + const originalSrc = 'foobar'; + const newSrc = 'barbaz'; this.player.duration(Infinity); @@ -412,7 +411,6 @@ QUnit.test('Snapshot and text tracks', function(assert) { const trackSrc = '/base/test/integration/lib/testcaption.vtt'; const originalAddTrack = this.player.addTextTrack; const originalTextTracks = this.player.textTracks; - let remoteTrack; // No text tracks at start assert.equal(this.player.textTracks().length, 0); @@ -420,7 +418,7 @@ QUnit.test('Snapshot and text tracks', function(assert) { this.player.addTextTrack('captions', 'Spanish', 'es'); // Add a text track - remoteTrack = this.player.addRemoteTextTrack({ + const remoteTrack = this.player.addRemoteTextTrack({ kind: 'captions', language: 'fr', label: 'French', diff --git a/test/integration/test.stitchedAds.js b/test/integration/test.stitchedAds.js index 3989ccfe..3eedee04 100644 --- a/test/integration/test.stitchedAds.js +++ b/test/integration/test.stitchedAds.js @@ -8,9 +8,11 @@ TODO: */ import videojs from 'video.js'; +import QUnit from 'qunit'; +import document from 'global/document'; import '../../examples/stitched-ad-plugin/plugin.js'; -let originalTestTimeout = QUnit.config.testTimeout; +const originalTestTimeout = QUnit.config.testTimeout; QUnit.module('Events and Stitched Ads', { diff --git a/test/karma.conf.js b/test/karma.conf.js index c8fd5eb3..b9374e35 100644 --- a/test/karma.conf.js +++ b/test/karma.conf.js @@ -1,8 +1,8 @@ module.exports = function(config) { - var detectBrowsers = { + const detectBrowsers = { enabled: false, usePhantomJS: false, - postDetection: function(browsers) { + postDetection(browsers) { const toKeep = ['Firefox', 'Chrome']; const filteredBrowsers = []; @@ -40,7 +40,6 @@ module.exports = function(config) { 'node_modules/video.js/dist/video.js', {pattern: 'dist/videojs-contrib-ads.js', nocache: true}, {pattern: 'dist/videojs-contrib-ads.css', nocache: true}, - {pattern: 'test/integration/lib/shared-module-hooks.js', nocache: true}, {pattern: 'test/dist/bundle.js', nocache: true}, // Test Data @@ -58,7 +57,7 @@ module.exports = function(config) { flags: ['--autoplay-policy=no-user-gesture-required'] } }, - detectBrowsers: detectBrowsers, + detectBrowsers, reporters: ['dots'], port: 9876, colors: true, diff --git a/test/unit/states/abstract/test.AdState.js b/test/unit/states/abstract/test.AdState.js index b815bee9..c1e4158a 100644 --- a/test/unit/states/abstract/test.AdState.js +++ b/test/unit/states/abstract/test.AdState.js @@ -1,3 +1,4 @@ +import QUnit from 'qunit'; import {AdState} from '../../../../src/states.js'; /* @@ -5,7 +6,7 @@ import {AdState} from '../../../../src/states.js'; * other modules mocked. */ QUnit.module('AdState', { - beforeEach: function() { + beforeEach() { this.player = { ads: {} }; @@ -57,4 +58,4 @@ QUnit.test('can check if in ad break', function(assert) { assert.equal(this.adState.inAdBreak(), false, 'not in ad break'); this.player.ads._inLinearAdMode = true; assert.equal(this.adState.inAdBreak(), true, 'in ad break'); -}); \ No newline at end of file +}); diff --git a/test/unit/states/abstract/test.ContentState.js b/test/unit/states/abstract/test.ContentState.js index 6dc5c600..83349c5d 100644 --- a/test/unit/states/abstract/test.ContentState.js +++ b/test/unit/states/abstract/test.ContentState.js @@ -1,3 +1,5 @@ +import QUnit from 'qunit'; +import sinon from 'sinon'; import {ContentState} from '../../../../src/states.js'; /* @@ -5,7 +7,7 @@ import {ContentState} from '../../../../src/states.js'; * other modules mocked. */ QUnit.module('ContentState', { - beforeEach: function() { + beforeEach() { this.player = { ads: { debug: () => {} diff --git a/test/unit/states/abstract/test.State.js b/test/unit/states/abstract/test.State.js index 5a5d39f5..e0d24a2b 100644 --- a/test/unit/states/abstract/test.State.js +++ b/test/unit/states/abstract/test.State.js @@ -1,3 +1,5 @@ +import QUnit from 'qunit'; +import sinon from 'sinon'; import {State} from '../../../../src/states.js'; /* @@ -5,7 +7,7 @@ import {State} from '../../../../src/states.js'; * other modules mocked. */ QUnit.module('State', { - beforeEach: function() { + beforeEach() { this.player = { ads: { debug: () => {} @@ -45,7 +47,7 @@ QUnit.test('throws error if isAdState is not implemented', function(assert) { try { this.state.isAdState(); - } catch(e) { + } catch (e) { error = e; } assert.equal(error.message, 'isAdState unimplemented for Anonymous State'); diff --git a/test/unit/states/test.AdsDone.js b/test/unit/states/test.AdsDone.js index 54d89dee..e81877a3 100644 --- a/test/unit/states/test.AdsDone.js +++ b/test/unit/states/test.AdsDone.js @@ -1,4 +1,5 @@ - +import QUnit from 'qunit'; +import sinon from 'sinon'; import {AdsDone} from '../../../src/states.js'; /* @@ -6,7 +7,7 @@ import {AdsDone} from '../../../src/states.js'; * other modules mocked. */ QUnit.module('AdsDone', { - beforeEach: function() { + beforeEach() { this.events = []; this.player = { trigger: (event) => { diff --git a/test/unit/states/test.BeforePreroll.js b/test/unit/states/test.BeforePreroll.js index 9b37d74e..0c58207c 100644 --- a/test/unit/states/test.BeforePreroll.js +++ b/test/unit/states/test.BeforePreroll.js @@ -1,3 +1,6 @@ +import QUnit from 'qunit'; +import sinon from 'sinon'; + import {BeforePreroll} from '../../../src/states.js'; import * as CancelContentPlay from '../../../src/cancelContentPlay.js'; @@ -6,7 +9,7 @@ import * as CancelContentPlay from '../../../src/cancelContentPlay.js'; * other modules mocked. */ QUnit.module('BeforePreroll', { - beforeEach: function() { + beforeEach() { this.events = []; this.player = { @@ -30,7 +33,7 @@ QUnit.module('BeforePreroll', { this.cancelContentPlayStub = sinon.stub(CancelContentPlay, 'cancelContentPlay'); }, - afterEach: function() { + afterEach() { this.cancelContentPlayStub.restore(); } }); @@ -95,7 +98,7 @@ QUnit.test('skips the preroll', function(assert) { }); QUnit.test('handles content change', function(assert) { - sinon.spy(this.beforePreroll, "init"); + sinon.spy(this.beforePreroll, 'init'); this.beforePreroll.onContentChanged(this.player); assert.equal(this.beforePreroll.init.calledOnce, true); }); diff --git a/test/unit/states/test.ContentPlayback.js b/test/unit/states/test.ContentPlayback.js index 674bd1aa..e114fe8d 100644 --- a/test/unit/states/test.ContentPlayback.js +++ b/test/unit/states/test.ContentPlayback.js @@ -1,3 +1,4 @@ +import QUnit from 'qunit'; import {ContentPlayback} from '../../../src/states.js'; /* @@ -5,7 +6,7 @@ import {ContentPlayback} from '../../../src/states.js'; * other modules mocked. */ QUnit.module('ContentPlayback', { - beforeEach: function() { + beforeEach() { this.events = []; this.playTriggered = false; diff --git a/test/unit/states/test.Midroll.js b/test/unit/states/test.Midroll.js index c695651b..db33f336 100644 --- a/test/unit/states/test.Midroll.js +++ b/test/unit/states/test.Midroll.js @@ -1,3 +1,5 @@ +import QUnit from 'qunit'; +import sinon from 'sinon'; import {Midroll} from '../../../src/states.js'; import adBreak from '../../../src/adBreak.js'; @@ -6,7 +8,7 @@ import adBreak from '../../../src/adBreak.js'; * other modules mocked. */ QUnit.module('Midroll', { - beforeEach: function() { + beforeEach() { this.player = { addClass: () => {}, removeClass: () => {}, @@ -46,4 +48,4 @@ QUnit.test('adserror during ad break ends ad break', function(assert) { this.midroll.init(this.player); this.midroll.onAdsError(this.player); assert.equal(this.calledEndLinearAdMode, true, 'linear ad mode ended'); -}); \ No newline at end of file +}); diff --git a/test/unit/states/test.Postroll.js b/test/unit/states/test.Postroll.js index 9070b52e..21e38e47 100644 --- a/test/unit/states/test.Postroll.js +++ b/test/unit/states/test.Postroll.js @@ -1,3 +1,5 @@ +import QUnit from 'qunit'; +import sinon from 'sinon'; import {Postroll} from '../../../src/states.js'; import adBreak from '../../../src/adBreak.js'; @@ -6,7 +8,7 @@ import adBreak from '../../../src/adBreak.js'; * other modules mocked. */ QUnit.module('Postroll', { - beforeEach: function() { + beforeEach() { this.events = []; this.player = { diff --git a/test/unit/states/test.Preroll.js b/test/unit/states/test.Preroll.js index d518007d..fc756546 100644 --- a/test/unit/states/test.Preroll.js +++ b/test/unit/states/test.Preroll.js @@ -1,5 +1,6 @@ +import QUnit from 'qunit'; +import sinon from 'sinon'; import {Preroll} from '../../../src/states.js'; -import * as CancelContentPlay from '../../../src/cancelContentPlay.js'; import adBreak from '../../../src/adBreak.js'; /* @@ -7,7 +8,7 @@ import adBreak from '../../../src/adBreak.js'; * other modules mocked. */ QUnit.module('Preroll', { - beforeEach: function() { + beforeEach() { this.events = []; this.playTriggered = false; @@ -163,43 +164,55 @@ QUnit.test('only plays after no ad in correct conditions', function(assert) { this.player.ads._pausedOnContentupdate = false; this.player.paused = () => false; this.preroll.resumeAfterNoPreroll(this.player); - assert.equal(this.playTriggered, false, - 'should not call play when playing already'); + assert.equal( + this.playTriggered, false, + 'should not call play when playing already' + ); this.player.ads._playRequested = true; this.player.ads._pausedOnContentupdate = false; this.player.paused = () => false; this.preroll.resumeAfterNoPreroll(this.player); - assert.equal(this.playTriggered, false, - 'should not call play when playing already 2'); + assert.equal( + this.playTriggered, false, + 'should not call play when playing already 2' + ); this.player.ads._playRequested = false; this.player.ads._pausedOnContentupdate = true; this.player.paused = () => false; this.preroll.resumeAfterNoPreroll(this.player); - assert.equal(this.playTriggered, false, - 'should not call play when playing already 3'); + assert.equal( + this.playTriggered, false, + 'should not call play when playing already 3' + ); this.player.ads._playRequested = false; this.player.ads._pausedOnContentupdate = false; this.player.paused = () => true; this.preroll.resumeAfterNoPreroll(this.player); - assert.equal(this.playTriggered, false, - 'should not call play when playback has never started'); + assert.equal( + this.playTriggered, false, + 'should not call play when playback has never started' + ); this.player.ads._playRequested = true; this.player.ads._pausedOnContentupdate = false; this.player.paused = () => true; this.preroll.resumeAfterNoPreroll(this.player); - assert.equal(this.playTriggered, true, - 'should call play when playback had been started and the player is paused'); + assert.equal( + this.playTriggered, true, + 'should call play when playback had been started and the player is paused' + ); this.player.ads._playRequested = false; this.player.ads._pausedOnContentupdate = true; this.player.paused = () => true; this.preroll.resumeAfterNoPreroll(this.player); - assert.equal(this.playTriggered, true, - 'should call play when playback had been started on the last source and the player is paused'); + assert.equal( + this.playTriggered, true, + 'should call play when playback had been started on the last source and the player is paused' + ); }); QUnit.test('remove ad loading class on cleanup', function(assert) { @@ -221,4 +234,4 @@ QUnit.test('resets _shouldBlockPlay to false when no preroll', function(assert) this.preroll.init(this.player, true, false); this.preroll.resumeAfterNoPreroll(this.player); assert.equal(this.player.ads._shouldBlockPlay, false); -}); \ No newline at end of file +}); diff --git a/test/unit/states/test.StitchedAdRoll.js b/test/unit/states/test.StitchedAdRoll.js index 00a17319..6aa36bcb 100644 --- a/test/unit/states/test.StitchedAdRoll.js +++ b/test/unit/states/test.StitchedAdRoll.js @@ -1,3 +1,5 @@ +import QUnit from 'qunit'; +import sinon from 'sinon'; import {StitchedAdRoll} from '../../../src/states.js'; import adBreak from '../../../src/adBreak.js'; @@ -6,7 +8,7 @@ import adBreak from '../../../src/adBreak.js'; * other modules mocked. */ QUnit.module('StitchedAdRoll', { - beforeEach: function() { + beforeEach() { this.player = { addClass: () => {}, removeClass: () => {}, diff --git a/test/unit/states/test.StitchedContentPlayback.js b/test/unit/states/test.StitchedContentPlayback.js index 63ebb759..b0f3d064 100644 --- a/test/unit/states/test.StitchedContentPlayback.js +++ b/test/unit/states/test.StitchedContentPlayback.js @@ -1,11 +1,12 @@ import {StitchedContentPlayback} from '../../../src/states.js'; +import QUnit from 'qunit'; /* * These tests are intended to be isolated unit tests for one state with all * other modules mocked. */ QUnit.module('StitchedContentPlayback', { - beforeEach: function() { + beforeEach() { this.events = []; this.playTriggered = false; diff --git a/test/unit/test.ads.js b/test/unit/test.ads.js index b3b2f8a4..74b1f8c7 100644 --- a/test/unit/test.ads.js +++ b/test/unit/test.ads.js @@ -1,8 +1,10 @@ import videojs from 'video.js'; import getAds from '../../src/ads.js'; +import QUnit from 'qunit'; +import sinon from 'sinon'; QUnit.module('Ads Object', { - beforeEach: function() { + beforeEach() { this.player = { currentSrc: () => {}, duration: () => {}, diff --git a/test/unit/test.playMiddleware.js b/test/unit/test.playMiddleware.js index ca703a1a..b4629191 100644 --- a/test/unit/test.playMiddleware.js +++ b/test/unit/test.playMiddleware.js @@ -1,4 +1,7 @@ import pm from '../../src/playMiddleware.js'; +import QUnit from 'qunit'; +import sinon from 'sinon'; +import videojs from 'video.js'; QUnit.module('Play Middleware', {}, function() { const baseMockedVjsNotSupported = { @@ -16,15 +19,15 @@ QUnit.module('Play Middleware', {}, function() { IS_ANDROID: false }, middleware: { - TERMINATOR: new Object('fake terminator') + TERMINATOR: {fake: 'terminator'} } }; QUnit.module('Not supported unit tests', { - beforeEach: function() { + beforeEach() { this.videojs = videojs.mergeOptions({}, baseMockedVjsNotSupported); }, - afterEach: function() { + afterEach() { this.videojs = null; } }, function() { @@ -32,8 +35,10 @@ QUnit.module('Play Middleware', {}, function() { // Mock videojs.browser to mock an older videojs version pm.testHook(this.videojs); - assert.equal(pm.isMiddlewareMediatorSupported(), false, - 'old video.js does not support middleware mediators'); + assert.equal( + pm.isMiddlewareMediatorSupported(), false, + 'old video.js does not support middleware mediators' + ); }); QUnit.test('isMiddlewareMediatorSupported is false if on mobile', function(assert) { @@ -42,21 +47,25 @@ QUnit.module('Play Middleware', {}, function() { this.videojs.browser.IS_IOS = false; pm.testHook(this.videojs); - assert.equal(pm.isMiddlewareMediatorSupported(), false, - 'is not supported on Android'); + assert.equal( + pm.isMiddlewareMediatorSupported(), false, + 'is not supported on Android' + ); // Mock videojs.browser to fake being on iOS this.videojs.browser.IS_ANDROID = false; this.videojs.browser.IS_IOS = true; pm.testHook(this.videojs); - assert.equal(pm.isMiddlewareMediatorSupported(), false, - 'is not supported on iOS'); + assert.equal( + pm.isMiddlewareMediatorSupported(), false, + 'is not supported on iOS' + ); }); }); QUnit.module('Supported unit tests', { - beforeEach: function() { + beforeEach() { // Stub videojs to force playMiddleware to be used this.videojs = videojs.mergeOptions({}, baseMockedVjsIsSupported); pm.testHook(this.videojs); @@ -77,11 +86,11 @@ QUnit.module('Play Middleware', {}, function() { addClass: (className) => { this.addedClass = className; } - } + }; this.sandbox = sinon.sandbox.create(); }, - afterEach: function() { + afterEach() { // Reset variables this.videojs = null; this.sandbox.restore(); @@ -89,8 +98,10 @@ QUnit.module('Play Middleware', {}, function() { }); QUnit.test('isMiddlewareMediatorSupported is true if middleware mediators exist on desktop', function(assert) { - assert.equal(pm.isMiddlewareMediatorSupported(), true, - 'is supported if middleware mediators exist and not mobile'); + assert.equal( + pm.isMiddlewareMediatorSupported(), true, + 'is supported if middleware mediators exist and not mobile' + ); }); QUnit.test('playMiddleware returns with a setSource, callPlay and play method', function(assert) { @@ -107,11 +118,15 @@ QUnit.module('Play Middleware', {}, function() { const m = pm.playMiddleware(this.player); this.sandbox.stub(pm, 'isMiddlewareMediatorSupported').returns(true); - this.player.ads._shouldBlockPlay = true - assert.equal(m.callPlay(), this.videojs.middleware.TERMINATOR, - 'callPlay returns terminator'); - assert.strictEqual(this.player.ads._playBlocked, true, - '_playBlocked is set'); + this.player.ads._shouldBlockPlay = true; + assert.equal( + m.callPlay(), this.videojs.middleware.TERMINATOR, + 'callPlay returns terminator' + ); + assert.strictEqual( + this.player.ads._playBlocked, true, + '_playBlocked is set' + ); }); QUnit.test('playMiddleware callPlay will not terminate if _shouldBlockPlay is false', function(assert) { @@ -120,12 +135,18 @@ QUnit.module('Play Middleware', {}, function() { this.sandbox.stub(pm, 'isMiddlewareMediatorSupported').returns(true); this.player.ads._shouldBlockPlay = false; - assert.equal(m.callPlay(), undefined, - 'callPlay should not return an object'); - assert.notEqual(m.callPlay(), this.videojs.middleware.TERMINATOR, - 'callPlay should not return the terminator'); - assert.strictEqual(this.player.ads._playBlocked, false, - '_playBlocked should not be set'); + assert.equal( + m.callPlay(), undefined, + 'callPlay should not return an object' + ); + assert.notEqual( + m.callPlay(), this.videojs.middleware.TERMINATOR, + 'callPlay should not return the terminator' + ); + assert.strictEqual( + this.player.ads._playBlocked, false, + '_playBlocked should not be set' + ); }); QUnit.test("playMiddleware callPlay will not terminate if the player doesn't have this plugin", function(assert) { @@ -142,10 +163,14 @@ QUnit.module('Play Middleware', {}, function() { this.sandbox.stub(pm, 'isMiddlewareMediatorSupported').returns(true); this.player.ads._shouldBlockPlay = true; - assert.equal(m.callPlay(), undefined, - 'callPlay should not return an object'); - assert.strictEqual(this.player.ads._playBlocked, false, - '_playBlocked should not be set'); + assert.equal( + m.callPlay(), undefined, + 'callPlay should not return an object' + ); + assert.strictEqual( + this.player.ads._playBlocked, false, + '_playBlocked should not be set' + ); }); QUnit.test('playMiddleware play will trigger play event if callPlay terminates', function(assert) { @@ -160,11 +185,13 @@ QUnit.module('Play Middleware', {}, function() { m.play(true, null); assert.equal(this.triggeredEvent, 'play'); assert.equal(this.addedClass, 'vjs-has-started'); - assert.equal(this.player.ads._playBlocked, false, - '_playBlocked is reset'); + assert.equal( + this.player.ads._playBlocked, false, + '_playBlocked is reset' + ); }); - QUnit.test("playMiddleware play will not trigger play event if another middleware terminated", function(assert) { + QUnit.test('playMiddleware play will not trigger play event if another middleware terminated', function(assert) { const m = pm.playMiddleware(this.player); this.sandbox.stub(pm, 'isMiddlewareMediatorSupported').returns(true); @@ -208,11 +235,11 @@ QUnit.module('Play Middleware', {}, function() { m.play(false, {}); assert.equal(this.triggeredEvent, null, 'no events should be triggered'); assert.equal(this.addedClass, null, 'no classes should be added'); - assert.strictEqual(this.player.ads._playBlocked, originalPlayBlocked, - '_playBlocked remains unchanged'); + assert.strictEqual( + this.player.ads._playBlocked, originalPlayBlocked, + '_playBlocked remains unchanged' + ); }); }); - - diff --git a/test/unit/test.redispatch.js b/test/unit/test.redispatch.js index edf59042..3f7bffc2 100644 --- a/test/unit/test.redispatch.js +++ b/test/unit/test.redispatch.js @@ -1,5 +1,5 @@ -import videojs from 'video.js'; import redispatch from '../../src/redispatch.js'; +import QUnit from 'qunit'; QUnit.module('Redispatch', { @@ -53,11 +53,10 @@ QUnit.module('Redispatch', { return 'cancelled'; } else if (eventBuffer.length === 0) { return 'ignored'; - } else { - throw new Error('Event buffer has more than 1 event'); } + throw new Error('Event buffer has more than 1 event'); - } + }; }, afterEach(assert) { @@ -88,34 +87,44 @@ QUnit.test('play events in different states', function(assert) { this.player.ads.inAdBreak = () => false; this.player.ads.isInAdMode = () => true; this.player.ads.isContentResuming = () => true; - assert.equal(this.redispatch('play'), 'contentplay', - 'should be contentplay when content is resuming'); + assert.equal( + this.redispatch('play'), 'contentplay', + 'should be contentplay when content is resuming' + ); this.player.ads.inAdBreak = () => false; this.player.ads.isInAdMode = () => false; this.player.ads.isContentResuming = () => false; this.player.ads._playRequested = false; - assert.strictEqual(this.redispatch('play'), 'ignored', - "should not be redispatched if play hasn't been requested yet"); + assert.strictEqual( + this.redispatch('play'), 'ignored', + "should not be redispatched if play hasn't been requested yet" + ); this.player.ads.inAdBreak = () => false; this.player.ads.isInAdMode = () => false; this.player.ads.isContentResuming = () => false; this.player.ads._playRequested = true; - assert.strictEqual(this.redispatch('play'), 'ignored', - 'should not be redispatched if in content state'); + assert.strictEqual( + this.redispatch('play'), 'ignored', + 'should not be redispatched if in content state' + ); this.player.ads.inAdBreak = () => false; this.player.ads.isInAdMode = () => true; this.player.ads.isContentResuming = () => false; this.player.ads._playRequested = true; - assert.strictEqual(this.redispatch('play'), 'ignored', - 'should not prefix when not in an ad break'); + assert.strictEqual( + this.redispatch('play'), 'ignored', + 'should not prefix when not in an ad break' + ); this.player.ads.inAdBreak = () => true; this.player.ads.isInAdMode = () => true; this.player.ads.isContentResuming = () => false; this.player.ads._playRequested = true; - assert.strictEqual(this.redispatch('play'), 'adplay', - 'should be adplay when in an ad break'); + assert.strictEqual( + this.redispatch('play'), 'adplay', + 'should be adplay when in an ad break' + ); }); diff --git a/test/unit/test.register.js b/test/unit/test.register.js index 5ee23c9b..4b590452 100644 --- a/test/unit/test.register.js +++ b/test/unit/test.register.js @@ -2,6 +2,7 @@ import videojs from 'video.js'; import contribAdsPlugin from '../../src/plugin.js'; import register from '../../src/register.js'; import { hasAdsPlugin} from '../../src/register.js'; +import QUnit from 'qunit'; // Cross-compatible plugin de-registration. const deregister = () => {