1
0
mirror of https://github.com/videojs/video.js.git synced 2024-12-27 02:43:45 +02:00

Merge pull request #325 from gkatsev/jshint

Add gruntfile and tests to Jshint linting
This commit is contained in:
Steve Heffernan 2013-02-11 12:36:56 -08:00
commit d096a7d33e
10 changed files with 119 additions and 100 deletions

View File

@ -16,6 +16,25 @@
"videojs",
"vjs",
"goog",
"console"
"console",
"require",
"PlayerTest",
"asyncTest",
"deepEqual",
"equal",
"expect",
"module",
"notDeepEqual",
"notEqual",
"notStrictEqual",
"ok",
"QUnit",
"raises",
"start",
"stop",
"strictEqual",
"test"
]
}

View File

@ -14,9 +14,9 @@ module.exports = function(grunt) {
// npm install https://github.com/gruntjs/grunt-contrib-jshint/archive/7fd70e86c5a8d489095fa81589d95dccb8eb3a46.tar.gz
jshint: {
src: {
src: ["src/js/*.js"],
src: ['src/js/*.js', 'Gruntfile.js', 'test/unit/*.js'],
options: {
jshintrc: ".jshintrc"
jshintrc: '.jshintrc'
}
}
},
@ -39,8 +39,8 @@ module.exports = function(grunt) {
minified: ['test/minified.html']
},
watch: {
files: [ "src/**/*.js", "test/unit/*.js" ],
tasks: "dev"
files: [ 'src/**/*.js', 'test/unit/*.js' ],
tasks: 'dev'
}
// Copy is broken. Waiting for an update to use.
// copy: {
@ -55,11 +55,11 @@ module.exports = function(grunt) {
// },
});
grunt.loadNpmTasks("grunt-contrib-jshint");
grunt.loadNpmTasks("grunt-contrib-qunit");
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.loadNpmTasks("grunt-contrib-clean");
grunt.loadNpmTasks("grunt-contrib-copy");
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-copy');
// Default task.
grunt.registerTask('default', ['jshint', 'build', 'minify', 'dist']);
@ -86,10 +86,10 @@ module.exports = function(grunt) {
path:['src/js/'],
dep:[],
exclude:[],
output_mode:'list',
output_mode:'list'
}, function(err,results){
if (err) {
grunt.warn({ message: err })
grunt.warn({ message: err });
grunt.log.writeln(err);
done(false);
}
@ -122,7 +122,7 @@ module.exports = function(grunt) {
grunt.file.write(dest, '');
if (this.data.sourcelist) {
files = files.concat(grunt.file.read(this.data.sourcelist).split(','))
files = files.concat(grunt.file.read(this.data.sourcelist).split(','));
}
if (this.file.src) {
files = files.concat(this.file.src);

View File

@ -1,10 +1,10 @@
module("Component");
module('Component');
var getFakePlayer = function(){
return {
// Fake player requries an ID
id: function(){ return 'player_1'; }
}
};
};
test('should create an element', function(){
@ -16,7 +16,7 @@ test('should create an element', function(){
test('should add a child component', function(){
var comp = new vjs.Component(getFakePlayer());
var child = comp.addChild("component");
var child = comp.addChild('component');
ok(comp.children().length === 1);
ok(comp.children()[0] === child);
@ -44,7 +44,7 @@ test('should do a deep merge of child options', function(){
'childTwo': {},
'childThree': {}
}
}
};
var comp = new vjs.Component(getFakePlayer(), {
'example': {
@ -74,7 +74,7 @@ test('should dispose of component and children', function(){
var comp = new vjs.Component(getFakePlayer());
// Add a child
var child = comp.addChild("Component");
var child = comp.addChild('Component');
ok(comp.children().length === 1);
// Add a listener
@ -88,8 +88,8 @@ test('should dispose of component and children', function(){
ok(!comp.el(), 'component element was deleted');
ok(!child.children(), 'child children were deleted');
ok(!child.el(), 'child element was deleted');
ok(!vjs.cache[id], 'listener cache nulled')
ok(vjs.isEmpty(data), 'original listener cache object was emptied')
ok(!vjs.cache[id], 'listener cache nulled');
ok(vjs.isEmpty(data), 'original listener cache object was emptied');
});
test('should add and remove event listeners to element', function(){
@ -129,10 +129,10 @@ test('should trigger a listener when ready', function(){
expect(2);
var optionsReadyListener = function(){
ok(true, 'options listener fired')
ok(true, 'options listener fired');
};
var methodReadyListener = function(){
ok(true, 'ready method listener fired')
ok(true, 'ready method listener fired');
};
var comp = new vjs.Component(getFakePlayer(), {}, optionsReadyListener);
@ -172,8 +172,8 @@ test('should change the width and height of a component', function(){
fixture.appendChild(container);
container.appendChild(el);
// Container of el needs dimensions or the component won't have dimensions
container.style.width = '1000px'
container.style.height = '1000px'
container.style.width = '1000px';
container.style.height = '1000px';
comp.width('50%');
comp.height('123px');

View File

@ -1,9 +1,9 @@
module("Core");
module('Core');
test('should create a video tag and have access children in old IE', function(){
var fixture = document.getElementById('qunit-fixture');
fixture.innerHTML += "<video id='test_vid_id'><source type='video/mp4'></video>";
fixture.innerHTML += '<video id="test_vid_id"><source type="video/mp4"></video>';
var vid = document.getElementById('test_vid_id');
@ -13,12 +13,12 @@ test('should create a video tag and have access children in old IE', function(){
test('should return a video player instance', function(){
var fixture = document.getElementById('qunit-fixture');
fixture.innerHTML += "<video id='test_vid_id'></video><video id='test_vid_id2'></video>";
fixture.innerHTML += '<video id="test_vid_id"></video><video id="test_vid_id2"></video>';
var player = videojs('test_vid_id');
ok(player, 'created player from tag');
ok(player.id() === 'test_vid_id');
ok(videojs.players['test_vid_id'] === player, 'added player to global reference')
ok(videojs.players['test_vid_id'] === player, 'added player to global reference');
var playerAgain = videojs('test_vid_id');
ok(player === playerAgain, 'did not create a second player from same tag');

View File

@ -1,4 +1,4 @@
module("Events");
module('Events');
test('should add and remove an event listener to an element', function(){
expect(1);
@ -10,7 +10,7 @@ test('should add and remove an event listener to an element', function(){
vjs.on(el, 'click', listener);
vjs.trigger(el, 'click'); // 1 click
vjs.off(el, 'click', listener)
vjs.off(el, 'click', listener);
vjs.trigger(el, 'click'); // No click should happen.
});
@ -28,12 +28,12 @@ test('should remove all listeners of a type', function(){
vjs.on(el, 'click', listener2);
vjs.trigger(el, 'click'); // 2 clicks
ok(clicks === 2, 'both click listeners fired')
ok(clicks === 2, 'both click listeners fired');
vjs.off(el, 'click')
vjs.off(el, 'click');
vjs.trigger(el, 'click'); // No click should happen.
ok(clicks === 2, 'no click listeners fired')
ok(clicks === 2, 'no click listeners fired');
});
test('should remove all listeners from an element', function(){

View File

@ -1,16 +1,16 @@
module("Lib");
module('Lib');
test('should create an element', function(){
var div = vjs.createEl();
var span = vjs.createEl('span', { "data-test": "asdf", innerHTML:'fdsa' })
var span = vjs.createEl('span', { 'data-test': 'asdf', innerHTML:'fdsa' });
ok(div.nodeName === 'DIV');
ok(span.nodeName === 'SPAN');
ok(span['data-test'] === 'asdf');
ok(span.innerHTML === "fdsa");
ok(span.innerHTML === 'fdsa');
});
test('should make a string start with an uppercase letter', function(){
var foo = vjs.capitalize('bar')
var foo = vjs.capitalize('bar');
ok(foo === 'Bar');
});
@ -19,14 +19,14 @@ test('should loop through each property on an object', function(){
a: 1,
b: 2,
'c': 3
}
};
// Add 3 to each value
vjs.obj.each(asdf, function(key, value){
asdf[key] = value + 3;
});
deepEqual(asdf,{a:4,b:5,'c':6})
deepEqual(asdf,{a:4,b:5,'c':6});
});
test('should copy an object', function(){
@ -34,18 +34,18 @@ test('should copy an object', function(){
a: 1,
b: 2,
'c': 3
}
};
var fdsa = vjs.obj.copy(asdf);
deepEqual(asdf,fdsa)
deepEqual(asdf,fdsa);
});
test('should add context to a function', function(){
var newContext = { test: 'obj'};
var asdf = function(){
ok(this === newContext);
}
};
var fdsa = vjs.bind(newContext, asdf);
fdsa();
@ -53,13 +53,13 @@ test('should add context to a function', function(){
test('should add and remove a class name on an element', function(){
var el = document.createElement('div');
vjs.addClass(el, 'test-class')
vjs.addClass(el, 'test-class');
ok(el.className === 'test-class', 'class added');
vjs.addClass(el, 'test-class')
vjs.addClass(el, 'test-class');
ok(el.className === 'test-class', 'same class not duplicated');
vjs.addClass(el, 'test-class2')
vjs.addClass(el, 'test-class2');
ok(el.className === 'test-class test-class2', 'added second class');
vjs.removeClass(el, 'test-class')
vjs.removeClass(el, 'test-class');
ok(el.className === 'test-class2', 'removed first class');
});
@ -78,8 +78,8 @@ test('should get and remove data from an element', function(){
// Remove all data
vjs.removeData(el);
ok(!vjs.cache[id], 'cached item nulled')
ok(el[vjs.expando] === null || el[vjs.expando] === undefined, 'element data id removed')
ok(!vjs.cache[id], 'cached item nulled');
ok(el[vjs.expando] === null || el[vjs.expando] === undefined, 'element data id removed');
});
test('should read tag attributes from elements, including HTML5 in all browsers', function(){
@ -100,25 +100,25 @@ test('should read tag attributes from elements, including HTML5 in all browsers'
var sourceVals = vjs.getAttributeValues(document.getElementById('source'));
var trackVals = vjs.getAttributeValues(document.getElementById('track'));
deepEqual(vid1Vals, { 'autoplay': true, 'controls': true, 'data-test': "asdf", 'data-empty-string': "", 'id': "vid1", 'loop': true, 'muted': true, 'poster': "http://www2.videojs.com/img/video-js-html5-video-player.png", 'preload': "none", 'src': "http://google.com" });
deepEqual(vid2Vals, { 'id': "vid2" });
deepEqual(sourceVals, {'title': "test", 'media': "fdsa", 'type': "video/mp4", 'src': "http://google.com", 'id': "source" });
deepEqual(trackVals, { "default": true, /* IE no likey default key */ 'id': "track", 'kind': "captions", 'label': "testlabel", 'src': "http://google.com", 'srclang': "en", 'title': "test" });
deepEqual(vid1Vals, { 'autoplay': true, 'controls': true, 'data-test': 'asdf', 'data-empty-string': '', 'id': 'vid1', 'loop': true, 'muted': true, 'poster': 'http://www2.videojs.com/img/video-js-html5-video-player.png', 'preload': 'none', 'src': 'http://google.com' });
deepEqual(vid2Vals, { 'id': 'vid2' });
deepEqual(sourceVals, {'title': 'test', 'media': 'fdsa', 'type': 'video/mp4', 'src': 'http://google.com', 'id': 'source' });
deepEqual(trackVals, { 'default': true, /* IE no likey default key */ 'id': 'track', 'kind': 'captions', 'label': 'testlabel', 'src': 'http://google.com', 'srclang': 'en', 'title': 'test' });
});
test('should get the right style values for an element', function(){
var el = document.createElement('div');
var container = document.createElement('div');
var fixture = document.getElementById('qunit-fixture')
var fixture = document.getElementById('qunit-fixture');
container.appendChild(el);
fixture.appendChild(container);
container.style.width = "1000px";
container.style.height = "1000px";
container.style.width = '1000px';
container.style.height = '1000px';
el.style.height = "100%";
el.style.width = "123px";
el.style.height = '100%';
el.style.width = '123px';
ok(vjs.getComputedStyleValue(el, 'height') === '1000px');
ok(vjs.getComputedStyleValue(el, 'width') === '123px');
@ -129,10 +129,10 @@ test('should insert an element first in another', function(){
var el2 = document.createElement('div');
var parent = document.createElement('div');
vjs.insertFirst(el1, parent)
vjs.insertFirst(el1, parent);
ok(parent.firstChild === el1, 'inserts first into empty parent');
vjs.insertFirst(el2, parent)
vjs.insertFirst(el2, parent);
ok(parent.firstChild === el2, 'inserts first into parent with child');
});
@ -147,8 +147,8 @@ test('should return the element with the ID', function(){
el1.id = 'test_id1';
el2.id = 'test_id2';
ok(vjs.el("test_id1") === el1, 'found element for ID');
ok(vjs.el("#test_id2") === el2, 'found element for CSS ID');
ok(vjs.el('test_id1') === el1, 'found element for ID');
ok(vjs.el('#test_id2') === el2, 'found element for CSS ID');
});
test('should trim whitespace from a string', function(){
@ -163,23 +163,23 @@ test('should round a number', function(){
});
test('should format time as a string', function(){
ok(vjs.formatTime(1) === "0:01");
ok(vjs.formatTime(10) === "0:10");
ok(vjs.formatTime(60) === "1:00");
ok(vjs.formatTime(600) === "10:00");
ok(vjs.formatTime(3600) === "1:00:00");
ok(vjs.formatTime(36000) === "10:00:00");
ok(vjs.formatTime(360000) === "100:00:00");
ok(vjs.formatTime(1) === '0:01');
ok(vjs.formatTime(10) === '0:10');
ok(vjs.formatTime(60) === '1:00');
ok(vjs.formatTime(600) === '10:00');
ok(vjs.formatTime(3600) === '1:00:00');
ok(vjs.formatTime(36000) === '10:00:00');
ok(vjs.formatTime(360000) === '100:00:00');
// Using guide should provide extra leading zeros
ok(vjs.formatTime(1,1) === "0:01");
ok(vjs.formatTime(1,10) === "0:01");
ok(vjs.formatTime(1,60) === "0:01");
ok(vjs.formatTime(1,600) === "00:01");
ok(vjs.formatTime(1,3600) === "0:00:01");
ok(vjs.formatTime(1,1) === '0:01');
ok(vjs.formatTime(1,10) === '0:01');
ok(vjs.formatTime(1,60) === '0:01');
ok(vjs.formatTime(1,600) === '00:01');
ok(vjs.formatTime(1,3600) === '0:00:01');
// Don't do extra leading zeros for hours
ok(vjs.formatTime(1,36000) === "0:00:01");
ok(vjs.formatTime(1,360000) === "0:00:01");
ok(vjs.formatTime(1,36000) === '0:00:01');
ok(vjs.formatTime(1,360000) === '0:00:01');
});
test('should create a fake timerange', function(){
@ -191,6 +191,6 @@ test('should create a fake timerange', function(){
test('should get an absolute URL', function(){
// Errors on compiled tests that don't use unit.html. Need a better solution.
// ok(vjs.getAbsoluteURL('unit.html') === window.location.href);
ok(vjs.getAbsoluteURL('http://asdf.com') === "http://asdf.com");
ok(vjs.getAbsoluteURL('https://asdf.com/index.html') === "https://asdf.com/index.html");
ok(vjs.getAbsoluteURL('http://asdf.com') === 'http://asdf.com');
ok(vjs.getAbsoluteURL('https://asdf.com/index.html') === 'https://asdf.com/index.html');
});

View File

@ -1 +1 @@
module("HTML5");
module('HTML5');

View File

@ -1,4 +1,4 @@
module("Player");
module('Player');
var PlayerTest = {
makeTag: function(){
@ -74,7 +74,7 @@ test('should accept options from multiple sources and override in correct order'
var tag0 = PlayerTest.makeTag();
var player0 = new vjs.Player(tag0);
ok(player0.options_['attr'] === 1, 'global option was set')
ok(player0.options_['attr'] === 1, 'global option was set');
player0.dispose();
// Set a tag level option
@ -99,7 +99,7 @@ test('should get tag, source, and track settings', function(){
var fixture = document.getElementById('qunit-fixture');
var html = '<video id="example_1" class="video-js" autoplay preload="metadata">'
var html = '<video id="example_1" class="video-js" autoplay preload="metadata">';
html += '<source src="http://google.com" type="video/mp4">';
html += '<source src="http://google.com" type="video/webm">';
html += '<track src="http://google.com" kind="captions" default>';
@ -131,16 +131,16 @@ test('should get tag, source, and track settings', function(){
player.dispose();
ok(tag['player'] === null, 'tag player ref killed')
ok(!vjs.players['example_1'], 'global player ref killed')
ok(player.el() === null, 'player el killed')
ok(tag['player'] === null, 'tag player ref killed');
ok(!vjs.players['example_1'], 'global player ref killed');
ok(player.el() === null, 'player el killed');
});
test('should set the width and height of the player', function(){
var player = PlayerTest.makePlayer({ width: 123, height: '100%' });
ok(player.width() === 123)
ok(player.el().style.width === '123px')
ok(player.width() === 123);
ok(player.el().style.width === '123px');
var fixture = document.getElementById('qunit-fixture');
var container = document.createElement('div');
@ -149,7 +149,7 @@ test('should set the width and height of the player', function(){
// Player container needs to have height in order to have height
// Don't want to mess with the fixture itself
container.appendChild(player.el());
container.style.height = "1000px";
container.style.height = '1000px';
ok(player.height() === 1000);
player.dispose();
@ -166,9 +166,9 @@ test('should accept options from multiple sources and override in correct order'
var player = new vjs.Player(tag);
var el = player.el();
ok(el.parentNode === container, 'player placed at same level as tag')
ok(el.parentNode === container, 'player placed at same level as tag');
// Tag may be placed inside the player element or it may be removed from the DOM
ok(tag.parentNode !== container, 'tag removed from original place')
ok(tag.parentNode !== container, 'tag removed from original place');
player.dispose();
});
@ -177,12 +177,12 @@ test('should load a media controller', function(){
var player = PlayerTest.makePlayer({
preload: 'none',
sources: [
{ src: "http://google.com", type: 'video/mp4' },
{ src: "http://google.com", type: 'video/webm' }
{ src: 'http://google.com', type: 'video/mp4' },
{ src: 'http://google.com', type: 'video/webm' }
]
});
ok(player.el().children[0].className.indexOf('vjs-tech') !== -1, 'media controller loaded')
ok(player.el().children[0].className.indexOf('vjs-tech') !== -1, 'media controller loaded');
player.dispose();
});
@ -193,8 +193,8 @@ test('should not play if firstplay event prevents default', function(){
'preload': 'none',
'autoplay': false,
'sources': [
{ 'src': "http://google.com", 'type': 'video/mp4' },
{ 'src': "http://google.com", 'type': 'video/webm' }
{ 'src': 'http://google.com', 'type': 'video/mp4' },
{ 'src': 'http://google.com', 'type': 'video/webm' }
]
});
@ -205,7 +205,7 @@ test('should not play if firstplay event prevents default', function(){
});
player.on('play', function(){
ok(false, 'play triggered anyway')
ok(false, 'play triggered anyway');
});
player.play();

View File

@ -1,4 +1,4 @@
module("Plugins");
module('Plugins');
test('Plugin should get initialized and receive options', function(){
expect(2);
@ -9,7 +9,7 @@ test('Plugin should get initialized and receive options', function(){
});
vjs.plugin('myPlugin2', function(options){
ok(false, 'Plugin initialized and should not have been')
ok(false, 'Plugin initialized and should not have been');
});
var player = PlayerTest.makePlayer({
@ -62,8 +62,8 @@ test('Plugin should be able to add a UI component', function(){
});
test('Plugin should overwrite plugin of same name', function(){
var v1Called = 0,
v2Called = 0,
var v1Called = 0,
v2Called = 0,
v3Called = 0;
// Create initial plugin

View File

@ -1 +1 @@
module("Setup");
module('Setup');