Skip to content

Commit

Permalink
chore: Cross-compatibility between Video.js 5 and 6 (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey authored and misteroneill committed Apr 4, 2017
1 parent cfc84ce commit eec856a
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 39 deletions.
29 changes: 22 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
2 changes: 1 addition & 1 deletion src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};
Expand Down
51 changes: 23 additions & 28 deletions test/karma.conf.js
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -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,
Expand All @@ -60,3 +54,4 @@ module.exports = function(config) {
concurrency: Infinity
});
};

13 changes: 11 additions & 2 deletions test/test.snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -273,13 +274,21 @@ 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';
}
updatedSrc = source;
};


this.player.ads.endLinearAdMode();
this.player.trigger('playing');
assert.deepEqual(updatedSrc, {src: 'content.mp4', type: 'video/mp4'}, 'restored src attribute');
Expand Down

0 comments on commit eec856a

Please sign in to comment.