From eec856a7261f330cd96fb55934d92f495b44db06 Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Tue, 4 Apr 2017 12:10:20 -0400 Subject: [PATCH] chore: Cross-compatibility between Video.js 5 and 6 (#241) --- .travis.yml | 29 ++++++++++++++++++------ src/plugin.js | 2 +- src/snapshot.js | 2 +- test/karma.conf.js | 51 +++++++++++++++++++------------------------ test/test.snapshot.js | 13 +++++++++-- 5 files changed, 58 insertions(+), 39 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4eeb286f..b83e3333 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,26 @@ sudo: false +dist: trusty language: node_js node_js: - 'node' - - '4.4' - + - 'lts/argon' before_script: - - # Set up a virtual screen for Firefox. + # check if the current version is equal to the version for the env + - 'export IS_INSTALLED="$(npm list video.js | grep "video.js@$VJS")"' + # we have to add semi colons 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 notifications: hipchat: rooms: @@ -18,6 +29,10 @@ notifications: channels: - "chat.freenode.net#videojs" use_notice: true - addons: - firefox: "latest-esr" + firefox: latest-esr + apt: + sources: + - google-chrome + packages: + - google-chrome-stable diff --git a/src/plugin.js b/src/plugin.js index 43327dcf..2d577e1b 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -187,7 +187,7 @@ const contribAdsPlugin = function(options) { 'You cannot use videoElementRecycled while there is no snapshot.'); } - const srcChanged = player.src() !== this.snapshot.src; + const srcChanged = player.tech_.src() !== this.snapshot.src; const currentSrcChanged = player.currentSrc() !== this.snapshot.currentSrc; return srcChanged || currentSrcChanged; diff --git a/src/snapshot.js b/src/snapshot.js index fbf05d86..c505fc90 100644 --- a/src/snapshot.js +++ b/src/snapshot.js @@ -37,7 +37,7 @@ export function getPlayerSnapshot(player) { const snapshotObject = { ended: player.ended(), currentSrc: player.currentSrc(), - src: player.src(), + src: player.tech_.src(), currentTime, type: player.currentType() }; diff --git a/test/karma.conf.js b/test/karma.conf.js index 78355735..456ac697 100644 --- a/test/karma.conf.js +++ b/test/karma.conf.js @@ -1,38 +1,27 @@ module.exports = function(config) { - var - plugins = [], - detectBrowsers = { - enabled: false, - usePhantomJS: false - }, - addBrowserLauncher = function(browser) { - plugins.push('karma-' + browser.toLowerCase() + '-launcher'); - }; - - if (process.env.TRAVIS) { - // Travis needs to run them in Firefox. - // Additionally, the tests don't pass in Safari. - config.browsers = ['Firefox']; - - } else { - // If no browsers are specified, we enable `karma-detect-browsers` - // This detects all browsers available for testing - plugins.push('karma-detect-browsers'); - config.browsers = ['Chrome', 'Firefox', 'IE']; - - detectBrowsers.enabled = true; - detectBrowsers.postDetection = function(browsers) { + var detectBrowsers = { + enabled: false, + usePhantomJS: false, + postDetection: function(browsers) { var i = browsers.indexOf('Safari'); + if (i !== -1) { browsers.splice(i, 1); } return browsers; - }; + } + }; - config.browsers.forEach(addBrowserLauncher); - plugins.push('karma-qunit'); - config.plugins = plugins; + // On Travis CI, we can only run in Firefox. + if (process.env.TRAVIS) { + config.browsers = ['Firefox', 'travisChrome']; + } + + // If no browsers are specified, we enable `karma-detect-browsers` + // this will detect all browsers that are available for testing + if (!config.browsers.length) { + detectBrowsers.enabled = true; } config.set({ @@ -50,7 +39,12 @@ module.exports = function(config) { 'test/shared-module-hooks.js', 'test/dist/bundle.js' ], - + customLaunchers: { + travisChrome: { + base: 'Chrome', + flags: ['--no-sandbox'] + } + }, detectBrowsers: detectBrowsers, reporters: ['dots'], port: 9876, @@ -60,3 +54,4 @@ module.exports = function(config) { concurrency: Infinity }); }; + diff --git a/test/test.snapshot.js b/test/test.snapshot.js index 3c7cc85b..eaf4b99a 100644 --- a/test/test.snapshot.js +++ b/test/test.snapshot.js @@ -20,11 +20,12 @@ QUnit.module('Video Snapshot', window.sharedModuleHooks({ })); QUnit.test('restores the original video src after ads', function(assert) { - var originalSrc; + var originalSrc = 'http://example.com/original.mp4'; assert.expect(1); - originalSrc = this.player.currentSrc(); + this.player.src(originalSrc); + this.player.trigger('adsready'); this.player.trigger('play'); this.player.ads.startLinearAdMode(); @@ -273,6 +274,13 @@ QUnit.test('checks for a src attribute change that isn\'t reflected in currentSr // `src` gets called internally to set the source back to its original // value when the player snapshot is restored when `endLinearAdMode` // is called. + this.player.tech_.src = function(source) { + if (source === undefined) { + return 'ad.mp4'; + } + updatedSrc = source; + }; + this.player.src = function(source) { if (source === undefined) { return 'ad.mp4'; @@ -280,6 +288,7 @@ 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, {src: 'content.mp4', type: 'video/mp4'}, 'restored src attribute');