Skip to content

Commit

Permalink
chore: lint to code to vjs 7 standards (#433)
Browse files Browse the repository at this point in the history
* chore: lint to code to vjs 7 standards

* travis

* update vjsstandard to disable jsdoc rules

* update to vjs standard 8
  • Loading branch information
brandonocasey authored and incompl committed Sep 28, 2018
1 parent fc5bf22 commit df10d45
Show file tree
Hide file tree
Showing 39 changed files with 736 additions and 567 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ dist/
docs/api/
test/dist/
examples/module-import/bundle.js
.eslintcache
32 changes: 8 additions & 24 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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

22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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\"}' .",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion scripts/modules.rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 4 additions & 2 deletions scripts/test.rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
1 change: 0 additions & 1 deletion scripts/version.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down
3 changes: 1 addition & 2 deletions src/ads.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions src/cancelContentPlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ 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.
return;
}

// 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;
}
3 changes: 2 additions & 1 deletion src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
7 changes: 4 additions & 3 deletions src/states/abstract/State.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
139 changes: 72 additions & 67 deletions test/integration/lib/shared-module-hooks.js
Original file line number Diff line number Diff line change
@@ -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;
Loading

0 comments on commit df10d45

Please sign in to comment.