Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: lint to code to vjs 7 standards #433

Merged
merged 4 commits into from
Sep 28, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
23 changes: 12 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,23 @@
"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": "^7.0.1"
},
"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
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;
}
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