1
0
mirror of https://github.com/videojs/video.js.git synced 2025-02-04 11:43:27 +02:00

Close GH-850: Use qunitjs through npm.

This commit is contained in:
David LaPalomento 2013-12-02 15:34:00 -08:00 committed by Steve Heffernan
parent 3248bc1258
commit 75b2171051
38 changed files with 12 additions and 5253 deletions

View File

@ -57,7 +57,7 @@ module.exports = function(grunt) {
},
tests: {
src: ['build/files/combined.video.js', 'build/compiler/goog.base.js', 'src/js/exports.js', 'test/unit/*.js', '!test/unit/api.js'],
externs: ['src/js/media/flash.externs.js', 'test/qunit/qunit-externs.js'],
externs: ['src/js/media/flash.externs.js', 'test/qunit-externs.js'],
dest: 'build/files/test.minified.video.js'
}
},

View File

@ -36,7 +36,8 @@
"grunt-contrib-less": "~0.6.4",
"grunt-karma": "~0.4.4",
"karma-qunit": "~0.0.2",
"videojs-doc-generator": "0.0.1"
"videojs-doc-generator": "0.0.1",
"qunitjs": "~1.12.0"
},
"testling": {
"browsers": [

View File

@ -8,8 +8,8 @@
<!--<![endif]-->
<!-- QUnit -->
<link rel="stylesheet" href="../test/qunit/qunit/qunit.css" />
<script src="../test/qunit/qunit/qunit.js"></script>
<link rel="stylesheet" href="../node_modules/qunitjs/qunit/qunit.css" />
<script src="../node_modules/qunitjs/qunit/qunit.js"></script>
<!-- Video.js CSS -->
<link rel="stylesheet" href="../build/files/video-js.css" type="text/css">
@ -67,6 +67,7 @@
<div>
<h1 id="qunit-header">Video.js Test Suite</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture"></div>

View File

@ -4,8 +4,8 @@
<title>Video.js Test Suite</title>
<!-- QUnit -->
<link rel="stylesheet" href="../test/qunit/qunit/qunit.css" />
<script src="../test/qunit/qunit/qunit.js"></script>
<link rel="stylesheet" href="../node_modules/qunitjs/qunit/qunit.css" />
<script src="../node_modules/qunitjs/qunit/qunit.js"></script>
<!-- Video.js CSS -->
<link rel="stylesheet" href="../build/files/video-js.css" type="text/css">
@ -38,6 +38,7 @@
<div>
<h1 id="qunit-header">Video.js Test Suite</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture"></div>

View File

@ -4,8 +4,8 @@
<title>Video.js Test Suite</title>
<!-- QUnit -->
<link rel="stylesheet" href="../test/qunit/qunit/qunit.css" />
<script src="../test/qunit/qunit/qunit.js"></script>
<link rel="stylesheet" href="../node_modules/qunitjs/qunit/qunit.css" />
<script src="../node_modules/qunitjs/qunit/qunit.js"></script>
<!-- Video.js CSS -->
<link rel="stylesheet" href="../build/files/video-js.css" type="text/css">
@ -22,6 +22,7 @@
<div>
<h1 id="qunit-header">Video.js Test Suite</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture"></div>

View File

@ -1,7 +0,0 @@
.project
*~
*.diff
*.patch
.DS_Store
.settings

View File

@ -1,27 +0,0 @@
[QUnit](http://docs.jquery.com/QUnit) - A JavaScript Unit Testing framework.
================================
QUnit is a powerful, easy-to-use, JavaScript test suite. It's used by the jQuery
project to test its code and plugins but is capable of testing any generic
JavaScript code (and even capable of testing JavaScript code on the server-side).
QUnit is especially useful for regression testing: Whenever a bug is reported,
write a test that asserts the existence of that particular bug. Then fix it and
commit both. Every time you work on the code again, run the tests. If the bug
comes up again - a regression - you'll spot it immediately and know how to fix
it, because you know what code you just changed.
Having good unit test coverage makes safe refactoring easy and cheap. You can
run the tests after each small refactoring step and always know what change
broke something.
QUnit is similar to other unit testing frameworks like JUnit, but makes use of
the features JavaScript provides and helps with testing code in the browser, eg.
with it's stop/start facilities for testing asynchronous code.
If you are interested in helping developing QUnit, you are in the right place.
For related discussions, visit the
[QUnit and Testing forum](http://forum.jquery.com/qunit-and-testing).
Planning for a qunitjs.com site and other testing tools related work now happens
on the [jQuery Testing Team planning wiki](http://jquerytesting.pbworks.com/w/page/41556026/FrontPage).

View File

@ -1,16 +0,0 @@
Canvas - A QUnit Addon For Testing Canvas Rendering
================================
This addon for QUnit adds a pixelEqual method that allows you to assert
individual pixel values in a given canvas.
Usage:
pixelEqual(canvas, x, y, r, g, b, a, message)
Where:
* canvas: Reference to a canvas element
* x, y: Coordinates of the pixel to test
* r, g, b, a: The color and opacity value of the pixel that you except
* message: Optional message, same as for other assertions

View File

@ -1,76 +0,0 @@
test("Canvas pixels", function () {
var canvas = document.getElementById('qunit-canvas'), context;
try {
context = canvas.getContext('2d');
} catch(e) {
// propably no canvas support, just exit
return;
}
context.fillStyle = 'rgba(0, 0, 0, 0)';
context.fillRect(0, 0, 5, 5);
QUnit.pixelEqual(canvas, 0, 0, 0, 0, 0, 0);
context.clearRect(0,0,5,5);
context.fillStyle = 'rgba(255, 0, 0, 0)';
context.fillRect(0, 0, 5, 5);
QUnit.pixelEqual(canvas, 0, 0, 0, 0, 0, 0);
context.clearRect(0,0,5,5);
context.fillStyle = 'rgba(0, 255, 0, 0)';
context.fillRect(0, 0, 5, 5);
QUnit.pixelEqual(canvas, 0, 0, 0, 0, 0, 0);
context.clearRect(0,0,5,5);
context.fillStyle = 'rgba(0, 0, 255, 0)';
context.fillRect(0, 0, 5, 5);
QUnit.pixelEqual(canvas, 0, 0, 0, 0, 0, 0);
context.clearRect(0,0,5,5);
context.fillStyle = 'rgba(0, 0, 0, 0.5)';
context.fillRect(0, 0, 5, 5);
QUnit.pixelEqual(canvas, 0, 0, 0, 0, 0, 127);
context.clearRect(0,0,5,5);
context.fillStyle = 'rgba(255, 0, 0, 0.5)';
context.fillRect(0, 0, 5, 5);
QUnit.pixelEqual(canvas, 0, 0, 255, 0, 0, 127);
context.clearRect(0,0,5,5);
context.fillStyle = 'rgba(0, 255, 0, 0.5)';
context.fillRect(0, 0, 5, 5);
QUnit.pixelEqual(canvas, 0, 0, 0, 255, 0, 127);
context.clearRect(0,0,5,5);
context.fillStyle = 'rgba(0, 0, 255, 0.5)';
context.fillRect(0, 0, 5, 5);
QUnit.pixelEqual(canvas, 0, 0, 0, 0, 255, 127);
context.clearRect(0,0,5,5);
context.fillStyle = 'rgba(0, 0, 0, 0.5)';
context.fillRect(0, 0, 5, 5);
QUnit.pixelEqual(canvas, 2, 2, 0, 0, 0, 127);
context.clearRect(0,0,5,5);
context.fillStyle = 'rgba(255, 0, 0, 0.5)';
context.fillRect(0, 0, 5, 5);
QUnit.pixelEqual(canvas, 2, 2, 255, 0, 0, 127);
context.clearRect(0,0,5,5);
context.fillStyle = 'rgba(0, 255, 0, 0.5)';
context.fillRect(0, 0, 5, 5);
QUnit.pixelEqual(canvas, 2, 2, 0, 255, 0, 127);
context.clearRect(0,0,5,5);
context.fillStyle = 'rgba(0, 0, 255, 0.5)';
context.fillRect(0, 0, 5, 5);
QUnit.pixelEqual(canvas, 2, 2, 0, 0, 255, 127);
context.clearRect(0,0,5,5);
context.fillStyle = 'rgba(0, 0, 0, 1)';
context.fillRect(0, 0, 5, 5);
QUnit.pixelEqual(canvas, 4, 4, 0, 0, 0, 255);
context.clearRect(0,0,5,5);
context.fillStyle = 'rgba(255, 0, 0, 1)';
context.fillRect(0, 0, 5, 5);
QUnit.pixelEqual(canvas, 4, 4, 255, 0, 0, 255);
context.clearRect(0,0,5,5);
context.fillStyle = 'rgba(0, 255, 0, 1)';
context.fillRect(0, 0, 5, 5);
QUnit.pixelEqual(canvas, 4, 4, 0, 255, 0, 255);
context.clearRect(0,0,5,5);
context.fillStyle = 'rgba(0, 0, 255, 1)';
context.fillRect(0, 0, 5, 5);
QUnit.pixelEqual(canvas, 4, 4, 0, 0, 255, 255);
context.clearRect(0,0,5,5);
});

View File

@ -1,19 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>QUnit Test Suite - Canvas Addon</title>
<link rel="stylesheet" href="../../qunit/qunit.css" type="text/css" media="screen">
<script type="text/javascript" src="../../qunit/qunit.js"></script>
<script type="text/javascript" src="qunit-canvas.js"></script>
<script type="text/javascript" src="canvas-test.js"></script>
</head>
<body>
<h1 id="qunit-header">QUnit Test Suite - Canvas Addon</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<canvas id="qunit-canvas" width="5" height="5"></canvas>
</body>
</html>

View File

@ -1,6 +0,0 @@
QUnit.extend( QUnit, {
pixelEqual: function(canvas, x, y, r, g, b, a, message) {
var actual = Array.prototype.slice.apply(canvas.getContext('2d').getImageData(x, y, 1, 1).data), expected = [r, g, b, a];
QUnit.push(QUnit.equiv(actual, expected), actual, expected, message);
}
});

View File

@ -1,17 +0,0 @@
Close-Enough - A QUnit Addon For Number Approximations
================================
This addon for QUnit adds close and notClose assertion methods, to test that
numbers are close enough (or different enough) from an expected number, with
a specified accuracy.
Usage:
close(actual, expected, maxDifference, message)
notClose(actual, expected, minDifference, message)
Where:
* maxDifference: the maximum inclusive difference allowed between the actual and expected numbers
* minDifference: the minimum exclusive difference allowed between the actual and expected numbers
* actual, expected, message: The usual

View File

@ -1,37 +0,0 @@
test("Close Numbers", function () {
QUnit.close(7, 7, 0);
QUnit.close(7, 7.1, 0.1);
QUnit.close(7, 7.1, 0.2);
QUnit.close(3.141, Math.PI, 0.001);
QUnit.close(3.1, Math.PI, 0.1);
var halfPi = Math.PI / 2;
QUnit.close(halfPi, 1.57, 0.001);
var sqrt2 = Math.sqrt(2);
QUnit.close(sqrt2, 1.4142, 0.0001);
QUnit.close(Infinity, Infinity, 1);
});
test("Distant Numbers", function () {
QUnit.notClose(6, 7, 0);
QUnit.notClose(7, 7.2, 0.1);
QUnit.notClose(7, 7.2, 0.19999999999);
QUnit.notClose(3.141, Math.PI, 0.0001);
QUnit.notClose(3.1, Math.PI, 0.001);
var halfPi = Math.PI / 2;
QUnit.notClose(halfPi, 1.57, 0.0001);
var sqrt2 = Math.sqrt(2);
QUnit.notClose(sqrt2, 1.4142, 0.00001);
QUnit.notClose(Infinity, -Infinity, 5);
});

View File

@ -1,18 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>QUnit Test Suite - Close Enough Addon</title>
<link rel="stylesheet" href="../../qunit/qunit.css" type="text/css" media="screen">
<script type="text/javascript" src="../../qunit/qunit.js"></script>
<script type="text/javascript" src="qunit-close-enough.js"></script>
<script type="text/javascript" src="close-enough-test.js"></script>
</head>
<body>
<h1 id="qunit-header">QUnit Test Suite - Close Enough</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
</body>
</html>

View File

@ -1,32 +0,0 @@
QUnit.extend( QUnit, {
/**
* Checks that the first two arguments are equal, or are numbers close enough to be considered equal
* based on a specified maximum allowable difference.
*
* @example close(3.141, Math.PI, 0.001);
*
* @param Number actual
* @param Number expected
* @param Number maxDifference (the maximum inclusive difference allowed between the actual and expected numbers)
* @param String message (optional)
*/
close: function(actual, expected, maxDifference, message) {
var passes = (actual === expected) || Math.abs(actual - expected) <= maxDifference;
QUnit.push(passes, actual, expected, message);
},
/**
* Checks that the first two arguments are numbers with differences greater than the specified
* minimum difference.
*
* @example notClose(3.1, Math.PI, 0.001);
*
* @param Number actual
* @param Number expected
* @param Number minDifference (the minimum exclusive difference allowed between the actual and expected numbers)
* @param String message (optional)
*/
notClose: function(actual, expected, minDifference, message) {
QUnit.push(Math.abs(actual - expected) > minDifference, actual, expected, message);
}
});

View File

@ -1,7 +0,0 @@
Composite - A QUnit Addon For Running Multiple Test Files
================================
Composite is a QUnit addon that, when handed an array of files, will
open each of those files inside of an iframe, run the tests and
display the results as a single suite of QUnit tests.

View File

@ -1,33 +0,0 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>QUnit SubsuiteRunner Test Suite</title>
<link rel="stylesheet" href="../../qunit/qunit.css" type="text/css" media="screen">
<link rel="stylesheet" href="qunit-composite.css">
<script src="../../qunit/qunit.js"></script>
<script src="qunit-composite.js"></script>
<script>
QUnit.testSuites([
"../../test/index.html",
"../canvas/canvas.html",
"../close-enough/close-enough.html",
"../step/step.html",
"composite-test.html"
]);
</script>
</head>
<body>
<h1 id="qunit-header">QUnit SubsuiteRunner Test Suite</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">
</div>
</body>
</html>

View File

@ -1,20 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>QUnit Core Test Suite</title>
<link rel="stylesheet" href="../../qunit/qunit.css" type="text/css" media="screen">
<script src="../../qunit/qunit.js"></script>
<script src="qunit-composite.js"></script>
<script src="composite-test.js"></script>
</head>
<body>
<h1 id="qunit-header">QUnit Core Test Suite</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">test markup</div>
</body>
</html>

View File

@ -1,159 +0,0 @@
module( "testSuites tests", (function(){
var asyncTest = QUnit.asyncTest,
runSuite = QUnit.runSuite;
return {
setup: function(){
//proxy asyncTest and runSuite
QUnit.asyncTest = window.asyncTest = function( name, callback ){
ok( true, "asyncTestCalled for each suite" );
callback(); //don't acutally create tests, just call callback
};
QUnit.runSuite = window.runSuite = function(){
ok( true, "runSuite called for each suite" );
};
//ensure that subsuite's done doesn't run
this.oldDone = QUnit.done;
},
teardown: function(){
//restore
QUnit.asyncTest = window.asyncTest = asyncTest;
QUnit.runSuite = window.runSuite = runSuite;
QUnit.done = this.oldDone;
}
};
})());
test( "proper number of asyncTest and runSuite calls", function(){
expect( 6 );
QUnit.testSuites( ["one.html", "two.html", "three.html"] );
});
test( "done callback changed", function(){
QUnit.testSuites( ["dummy.html"] );
notEqual( this.oldDone, QUnit.done, "done callback should be set" );
});
module( "testStart tests", (function(){
var id = QUnit.id;
return {
setup: function(){
//proxy id
var fakeElem = this.fakeElem = document.createElement( "div" );
QUnit.id = function(){
return fakeElem;
}
},
teardown: function(){
QUnit.id = id;
}
};
})());
test( "running message printed", function(){
var hello = "hello world",
expected = "Running " + hello + "...<br>&nbsp;";
QUnit.testStart( {name: hello} );
equal( this.fakeElem.innerHTML, expected, "innerHTML was set correctly by testStart" );
});
module( "testDone tests", (function(){
var id = QUnit.id;
return {
setup: function(){
//proxy id
var fakeElem = this.fakeElem = document.createElement( "div" );
fakeElem.appendChild( document.createElement( "ol" ) );
fakeElem.appendChild( document.createElement( "ol" ) );
QUnit.id = function(){
return fakeElem;
}
},
teardown: function(){
QUnit.id = id;
}
};
})());
test( "test expansions are hidden", function(){
QUnit.testDone();
equal( this.fakeElem.children[0].style.display, "none", "first ol display is none" );
equal( this.fakeElem.children[1].style.display, "none", "second ol display is none" );
});
test( "non-ol elements aren't hidden", function(){
this.fakeElem.appendChild( document.createElement( "span" ) );
QUnit.testDone();
notEqual( this.fakeElem.children[2].style.display, "none", "first ol display is none" );
});
module( "runSuite tests", (function(){
var getElementsByTagName = document.getElementsByTagName,
createElement = document.createElement,
runSuite = QUnit.runSuite;
return {
setup: function(){
//proxy getElementsByTagName and createElement
var setAttributeCall = this.setAttributeCall = {},
appendChildCall = this.appendChildCall = {called: 0},
iframeLoad = this.iframeLoad = {},
iframeQUnitObject = this.iframeQUnitObject = {},
fakeElement = {
appendChild: function(){appendChildCall.called++},
setAttribute: function(){setAttributeCall.args = arguments},
addEventListener: function( type, callback ){iframeLoad.callback = callback;},
contentWindow: {QUnit: iframeQUnitObject},
className: "",
};
document.getElementsByTagName = function(){
return [fakeElement];
};
document.createElement = function(){
return fakeElement;
}
},
teardown: function(){
document.getElementsByTagName = getElementsByTagName;
document.createElement = createElement;
//must restore even though we didn't proxy; the runner overwrites upon first call
QUnit.runSuite = runSuite;
}
};
})());
test( "runSuite different after first run", function(){
var before = QUnit.runSuite,
after;
QUnit.runSuite();
after = QUnit.runSuite;
notEqual( before, after, "runSuite changed after initial run" );
});
test( "iframe only created once", function(){
QUnit.runSuite();
equal( this.appendChildCall.called, 1, "append child called once" );
QUnit.runSuite();
equal( this.appendChildCall.called, 1, "append child only ever called once" );
});
test( "iframe's QUnit object is modified when iframe source loads", function(){
var before = this.iframeQUnitObject,
after;
QUnit.runSuite();
this.iframeLoad.callback();
notEqual( before, after, "iframe's qunit object is modified upon load");
});
test( "iframe src set to suite passed", function(){
var pages = ["testing.html", "subsuiteRunner.html"];
QUnit.runSuite( pages[0] );
equal( this.setAttributeCall.args[0], "src", "src attribute set" );
equal( this.setAttributeCall.args[1], pages[0], "src attribute set" );
QUnit.runSuite( pages[1] );
equal( this.setAttributeCall.args[1], pages[1], "src attribute set" );
});

View File

@ -1,19 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>QUnit Core Test Suite</title>
<link rel="stylesheet" href="../../qunit/qunit.css" type="text/css" media="screen">
<script src="../../qunit/qunit.js"></script>
<script src="../../test/test.js"></script>
</head>
<body>
<h1 id="qunit-header">QUnit Core Test Suite</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">test markup</div>
</body>
</html>

View File

@ -1,19 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>QUnit Same Test Suite</title>
<link rel="stylesheet" href="../../qunit/qunit.css" type="text/css" media="screen">
<script src="../../qunit/qunit.js"></script>
<script src="../../test/same.js"></script>
</head>
<body>
<h1 id="qunit-header">QUnit Same Test Suite</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">test markup</div>
</body>
</html>

View File

@ -1,35 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Composite</title>
</head>
<body>
<h1>Composite</h1>
<h3>A QUnit Addon For Running Multiple Test Files</h3>
<p>Composite is a QUnit addon that, when handed an array of
files, will open each of those files inside of an iframe, run
the tests and display the results as a single suite of QUnit
tests.</p>
<h4>Using Composite</h4>
<p>To use Composite, setup a standard QUnit html page as you
would with other QUnit tests. Remember to include composite.js
and composite.css. Then, inside of either an external js file,
or a script block call the only new method that Composite
exposes, QUnit.testSuites().</p><p>QUnit.testSuites() is
passed an array of test files to run as follows:</p>
<pre>
QUnit.testSuites([
"test-file-1.html",
"test-file-2.html",
"test-file-3.html"
]);
</pre>
<h4>Tests</h4>
<p>Composite has tests of it's own.</p>
<p>
<a href="composite-test.html">Composite Test</a>: A suite which tests the implementation of composite.<br>
<a href="composite-demo-test.html">Composite Demo</a>: A suite which demoes how Compisite is bootstrapped and run.
</p>
</body>
</html>

View File

@ -1,13 +0,0 @@
iframe.qunit-subsuite{
position: fixed;
bottom: 0;
left: 0;
margin: 0;
padding: 0;
border-width: 1px 0 0;
height: 45%;
width: 100%;
background: #fff;
}

View File

@ -1,82 +0,0 @@
(function( QUnit ) {
var subsuiteFrame;
QUnit.extend( QUnit, {
testSuites: function( suites ) {
for ( var i = 0; i < suites.length; i++ ) {
(function( suite ) {
asyncTest( suite, function() {
QUnit.runSuite( suite );
});
}( suites[i] ) );
}
QUnit.done = function() {
subsuiteFrame.style.display = "none";
};
},
testStart: function( data ) {
// update the test status to show which test suite is running
QUnit.id( "qunit-testresult" ).innerHTML = "Running " + data.name + "...<br>&nbsp;";
},
testDone: function() {
var current = QUnit.id( this.config.current.id ),
children = current.children;
// undo the auto-expansion of failed tests
for ( var i = 0; i < children.length; i++ ) {
if ( children[i].nodeName === "OL" ) {
children[i].style.display = "none";
}
}
},
runSuite: function( suite ) {
var body = document.getElementsByTagName( "body" )[0],
iframe = subsuiteFrame = document.createElement( "iframe" ),
iframeWin;
iframe.className = "qunit-subsuite";
body.appendChild( iframe );
function onIframeLoad() {
var module, test,
count = 0;
QUnit.extend( iframeWin.QUnit, {
moduleStart: function( data ) {
// capture module name for messages
module = data.name;
},
testStart: function( data ) {
// capture test name for messages
test = data.name;
},
log: function( data ) {
// pass all test details through to the main page
var message = module + ": " + test + ": " + data.message;
expect( ++count );
QUnit.push( data.result, data.actual, data.expected, message );
},
done: function() {
// start the wrapper test from the main page
start();
}
});
}
QUnit.addEvent( iframe, "load", onIframeLoad );
iframeWin = iframe.contentWindow;
iframe.setAttribute( "src", suite );
this.runSuite = function( suite ) {
iframe.setAttribute( "src", suite );
};
}
});
}( QUnit ) );

View File

@ -1,18 +0,0 @@
QUnit.step() - A QUnit Addon For Testing execution in order
============================================================
This addon for QUnit adds a step method that allows you to assert
the proper sequence in which the code should execute.
Example:
test("example test", function () {
function x() {
QUnit.step(2, "function y should be called first");
}
function y() {
QUnit.step(1);
}
y();
x();
});

View File

@ -1,25 +0,0 @@
QUnit.extend( QUnit, {
/**
* Check the sequence/order
*
* @example step(1); setTimeout(function () { step(3); }, 100); step(2);
* @param Number expected The excepted step within the test()
* @param String message (optional)
*/
step: function (expected, message) {
this.config.current.step++; // increment internal step counter.
if (typeof message == "undefined") {
message = "step " + expected;
}
var actual = this.config.current.step;
QUnit.push(QUnit.equiv(actual, expected), actual, expected, message);
}
});
/**
* Reset the step counter for every test()
*/
QUnit.testStart(function () {
this.config.current.step = 0;
});

View File

@ -1,13 +0,0 @@
module('Step Addon');
test("step", 3, function () {
QUnit.step(1, "step starts at 1");
setTimeout(function () {
start();
QUnit.step(3);
}, 100);
QUnit.step(2, "before the setTimeout callback is run");
stop();
});
test("step counter", 1, function () {
QUnit.step(1, "each test has its own step counter");
});

View File

@ -1,19 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>QUnit Test Suite - Step Addon</title>
<link rel="stylesheet" href="../../qunit/qunit.css" type="text/css" media="screen">
<script type="text/javascript" src="../../qunit/qunit.js"></script>
<script type="text/javascript" src="qunit-step.js"></script>
<script type="text/javascript" src="step-test.js"></script>
</head>
<body>
<h1 id="qunit-header">QUnit Test Suite - Step Addon</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<canvas id="qunit-canvas" width="5" height="5"></canvas>
</body>
</html>

View File

@ -1,27 +0,0 @@
{
"name": "qunit",
"author": "The jQuery Project",
"contributors": [
{
"name": "John Resig",
"email": "jeresig@gmail.com",
"url": "http://ejohn.org/"
},
{
"name": "Jörn Zaefferer",
"email": "joern.zaefferer@googlemail.com",
"url": "http://bassistance.de/"
}],
"url": "http://docs.jquery.com/QUnit",
"repositories" : [{
"type": "git",
"url": "https://github.com/jquery/qunit.git"
}],
"license": {
"name": "MIT",
"url": "http://www.opensource.org/licenses/mit-license.php"
},
"description": "An easy-to-use JavaScript Unit Testing framework.",
"keywords": [ "testing", "unit", "jquery" ],
"main": "qunit/qunit.js"
}

View File

@ -1,244 +0,0 @@
/**
* QUnit v1.11.0 - A JavaScript Unit Testing Framework
*
* http://qunitjs.com
*
* Copyright 2012 jQuery Foundation and other contributors
* Released under the MIT license.
* http://jquery.org/license
*/
/** Font Family and Sizes */
#qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult {
font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial, sans-serif;
}
#qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; }
#qunit-tests { font-size: smaller; }
/** Resets */
#qunit-tests, #qunit-header, #qunit-banner, #qunit-userAgent, #qunit-testresult, #qunit-modulefilter {
margin: 0;
padding: 0;
}
/** Header */
#qunit-header {
padding: 0.5em 0 0.5em 1em;
color: #8699a4;
background-color: #0d3349;
font-size: 1.5em;
line-height: 1em;
font-weight: normal;
border-radius: 5px 5px 0 0;
-moz-border-radius: 5px 5px 0 0;
-webkit-border-top-right-radius: 5px;
-webkit-border-top-left-radius: 5px;
}
#qunit-header a {
text-decoration: none;
color: #c2ccd1;
}
#qunit-header a:hover,
#qunit-header a:focus {
color: #fff;
}
#qunit-testrunner-toolbar label {
display: inline-block;
padding: 0 .5em 0 .1em;
}
#qunit-banner {
height: 5px;
}
#qunit-testrunner-toolbar {
padding: 0.5em 0 0.5em 2em;
color: #5E740B;
background-color: #eee;
overflow: hidden;
}
#qunit-userAgent {
padding: 0.5em 0 0.5em 2.5em;
background-color: #2b81af;
color: #fff;
text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px;
}
#qunit-modulefilter-container {
float: right;
}
/** Tests: Pass/Fail */
#qunit-tests {
list-style-position: inside;
}
#qunit-tests li {
padding: 0.4em 0.5em 0.4em 2.5em;
border-bottom: 1px solid #fff;
list-style-position: inside;
}
#qunit-tests.hidepass li.pass, #qunit-tests.hidepass li.running {
display: none;
}
#qunit-tests li strong {
cursor: pointer;
}
#qunit-tests li a {
padding: 0.5em;
color: #c2ccd1;
text-decoration: none;
}
#qunit-tests li a:hover,
#qunit-tests li a:focus {
color: #000;
}
#qunit-tests li .runtime {
float: right;
font-size: smaller;
}
.qunit-assert-list {
margin-top: 0.5em;
padding: 0.5em;
background-color: #fff;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
}
.qunit-collapsed {
display: none;
}
#qunit-tests table {
border-collapse: collapse;
margin-top: .2em;
}
#qunit-tests th {
text-align: right;
vertical-align: top;
padding: 0 .5em 0 0;
}
#qunit-tests td {
vertical-align: top;
}
#qunit-tests pre {
margin: 0;
white-space: pre-wrap;
word-wrap: break-word;
}
#qunit-tests del {
background-color: #e0f2be;
color: #374e0c;
text-decoration: none;
}
#qunit-tests ins {
background-color: #ffcaca;
color: #500;
text-decoration: none;
}
/*** Test Counts */
#qunit-tests b.counts { color: black; }
#qunit-tests b.passed { color: #5E740B; }
#qunit-tests b.failed { color: #710909; }
#qunit-tests li li {
padding: 5px;
background-color: #fff;
border-bottom: none;
list-style-position: inside;
}
/*** Passing Styles */
#qunit-tests li li.pass {
color: #3c510c;
background-color: #fff;
border-left: 10px solid #C6E746;
}
#qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; }
#qunit-tests .pass .test-name { color: #366097; }
#qunit-tests .pass .test-actual,
#qunit-tests .pass .test-expected { color: #999999; }
#qunit-banner.qunit-pass { background-color: #C6E746; }
/*** Failing Styles */
#qunit-tests li li.fail {
color: #710909;
background-color: #fff;
border-left: 10px solid #EE5757;
white-space: pre;
}
#qunit-tests > li:last-child {
border-radius: 0 0 5px 5px;
-moz-border-radius: 0 0 5px 5px;
-webkit-border-bottom-right-radius: 5px;
-webkit-border-bottom-left-radius: 5px;
}
#qunit-tests .fail { color: #000000; background-color: #EE5757; }
#qunit-tests .fail .test-name,
#qunit-tests .fail .module-name { color: #000000; }
#qunit-tests .fail .test-actual { color: #EE5757; }
#qunit-tests .fail .test-expected { color: green; }
#qunit-banner.qunit-fail { background-color: #EE5757; }
/** Result */
#qunit-testresult {
padding: 0.5em 0.5em 0.5em 2.5em;
color: #2b81af;
background-color: #D2E0E6;
border-bottom: 1px solid white;
}
#qunit-testresult .module-name {
font-weight: bold;
}
/** Fixture */
#qunit-fixture {
position: absolute;
top: -10000px;
left: -10000px;
width: 1000px;
height: 1000px;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,24 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>QUnit Test Suite</title>
<link rel="stylesheet" href="../qunit/qunit.css" type="text/css" media="screen">
<script type="text/javascript" src="../qunit/qunit.js"></script>
<script type="text/javascript" src="test.js"></script>
<script type="text/javascript" src="same.js"></script>
<script>
var logs = ["begin", "testStart", "testDone", "log", "moduleStart", "moduleDone", "done"];
for (var i = 0; i < logs.length; i++) {
(function() {
var log = logs[i];
QUnit[log] = function() {
console.log(log, arguments);
};
})();
}
</script>
</head>
<body>
<div id="qunit-fixture">test markup</div>
</body>
</html>

View File

@ -1,19 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>QUnit Test Suite</title>
<link rel="stylesheet" href="../qunit/qunit.css" type="text/css" media="screen">
<script type="text/javascript" src="../qunit/qunit.js"></script>
<script type="text/javascript" src="test.js"></script>
<script type="text/javascript" src="same.js"></script>
</head>
<body>
<h1 id="qunit-header">QUnit Test Suite</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">test markup</div>
</body>
</html>

View File

@ -1,17 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>QUnit Test Suite</title>
<link rel="stylesheet" href="../qunit/qunit.css" type="text/css" media="screen">
<script type="text/javascript" src="../qunit/qunit.js"></script>
<script type="text/javascript" src="logs.js"></script>
</head>
<body>
<h1 id="qunit-header">QUnit Test Suite</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">test markup</div>
</body>
</html>

View File

@ -1,153 +0,0 @@
// TODO disable reordering for this suite!
var begin = 0,
moduleStart = 0,
moduleDone = 0,
testStart = 0,
testDone = 0,
log = 0,
moduleContext,
moduleDoneContext,
testContext,
testDoneContext,
logContext;
QUnit.begin(function() {
begin++;
});
QUnit.done(function() {
});
QUnit.moduleStart(function(context) {
moduleStart++;
moduleContext = context;
});
QUnit.moduleDone(function(context) {
moduleDone++;
moduleDoneContext = context;
});
QUnit.testStart(function(context) {
testStart++;
testContext = context;
});
QUnit.testDone(function(context) {
testDone++;
testDoneContext = context;
});
QUnit.log(function(context) {
log++;
logContext = context;
});
var logs = ["begin", "testStart", "testDone", "log", "moduleStart", "moduleDone", "done"];
for (var i = 0; i < logs.length; i++) {
(function() {
var log = logs[i];
QUnit[log](function() {
console.log(log, arguments);
});
})();
}
module("logs1");
test("test1", 13, function() {
equal(begin, 1);
equal(moduleStart, 1);
equal(testStart, 1);
equal(testDone, 0);
equal(moduleDone, 0);
deepEqual(logContext, {
result: true,
message: undefined,
actual: 0,
expected: 0
});
equal("foo", "foo", "msg");
deepEqual(logContext, {
result: true,
message: "msg",
actual: "foo",
expected: "foo"
});
strictEqual(testDoneContext, undefined);
deepEqual(testContext, {
module: "logs1",
name: "test1"
});
strictEqual(moduleDoneContext, undefined);
deepEqual(moduleContext, {
name: "logs1"
});
equal(log, 12);
});
test("test2", 10, function() {
equal(begin, 1);
equal(moduleStart, 1);
equal(testStart, 2);
equal(testDone, 1);
equal(moduleDone, 0);
deepEqual(testDoneContext, {
module: "logs1",
name: "test1",
failed: 0,
passed: 13,
total: 13
});
deepEqual(testContext, {
module: "logs1",
name: "test2"
});
strictEqual(moduleDoneContext, undefined);
deepEqual(moduleContext, {
name: "logs1"
});
equal(log, 22);
});
module("logs2");
test("test1", 9, function() {
equal(begin, 1);
equal(moduleStart, 2);
equal(testStart, 3);
equal(testDone, 2);
equal(moduleDone, 1);
deepEqual(testContext, {
module: "logs2",
name: "test1"
});
deepEqual(moduleDoneContext, {
name: "logs1",
failed: 0,
passed: 23,
total: 23
});
deepEqual(moduleContext, {
name: "logs2"
});
equal(log, 31);
});
test("test2", 8, function() {
equal(begin, 1);
equal(moduleStart, 2);
equal(testStart, 4);
equal(testDone, 3);
equal(moduleDone, 1);
deepEqual(testContext, {
module: "logs2",
name: "test2"
});
deepEqual(moduleContext, {
name: "logs2"
});
equal(log, 39);
});

File diff suppressed because it is too large Load Diff

View File

@ -1,471 +0,0 @@
test("module without setup/teardown (default)", function() {
expect(1);
ok(true);
});
test("expect in test", 3, function() {
ok(true);
ok(true);
ok(true);
});
test("expect in test", 1, function() {
ok(true);
});
module("setup test", {
setup: function() {
ok(true);
}
});
test("module with setup", function() {
expect(2);
ok(true);
});
test("module with setup, expect in test call", 2, function() {
ok(true);
});
var state;
module("setup/teardown test", {
setup: function() {
state = true;
ok(true);
},
teardown: function() {
ok(true);
}
});
test("module with setup/teardown", function() {
expect(3);
ok(true);
});
module("setup/teardown test 2");
test("module without setup/teardown", function() {
expect(1);
ok(true);
});
if (typeof setTimeout !== 'undefined') {
state = 'fail';
module("teardown and stop", {
teardown: function() {
equal(state, "done", "Test teardown.");
}
});
test("teardown must be called after test ended", function() {
expect(1);
stop();
setTimeout(function() {
state = "done";
start();
}, 13);
});
test("parameter passed to stop increments semaphore n times", function() {
expect(1);
stop(3);
setTimeout(function() {
state = "not enough starts";
start(), start();
}, 13);
setTimeout(function() {
state = "done";
start();
}, 15);
});
test("parameter passed to start decrements semaphore n times", function() {
expect(1);
stop(), stop(), stop();
setTimeout(function() {
state = "done";
start(3);
}, 18);
});
module("async setup test", {
setup: function() {
stop();
setTimeout(function(){
ok(true);
start();
}, 500);
}
});
asyncTest("module with async setup", function() {
expect(2);
ok(true);
start();
});
module("async teardown test", {
teardown: function() {
stop();
setTimeout(function(){
ok(true);
start();
}, 500);
}
});
asyncTest("module with async teardown", function() {
expect(2);
ok(true);
start();
});
module("asyncTest");
asyncTest("asyncTest", function() {
expect(2);
ok(true);
setTimeout(function() {
state = "done";
ok(true);
start();
}, 13);
});
asyncTest("asyncTest", 2, function() {
ok(true);
setTimeout(function() {
state = "done";
ok(true);
start();
}, 13);
});
test("sync", 2, function() {
stop();
setTimeout(function() {
ok(true);
start();
}, 13);
stop();
setTimeout(function() {
ok(true);
start();
}, 125);
});
test("test synchronous calls to stop", 2, function() {
stop();
setTimeout(function(){
ok(true, 'first');
start();
stop();
setTimeout(function(){
ok(true, 'second');
start();
}, 150);
}, 150);
});
}
module("save scope", {
setup: function() {
this.foo = "bar";
},
teardown: function() {
deepEqual(this.foo, "bar");
}
});
test("scope check", function() {
expect(2);
deepEqual(this.foo, "bar");
});
module("simple testEnvironment setup", {
foo: "bar",
bugid: "#5311" // example of meta-data
});
test("scope check", function() {
deepEqual(this.foo, "bar");
});
test("modify testEnvironment",function() {
this.foo="hamster";
});
test("testEnvironment reset for next test",function() {
deepEqual(this.foo, "bar");
});
module("testEnvironment with object", {
options:{
recipe:"soup",
ingredients:["hamster","onions"]
}
});
test("scope check", function() {
deepEqual(this.options, {recipe:"soup",ingredients:["hamster","onions"]}) ;
});
test("modify testEnvironment",function() {
// since we do a shallow copy, the testEnvironment can be modified
this.options.ingredients.push("carrots");
});
test("testEnvironment reset for next test",function() {
deepEqual(this.options, {recipe:"soup",ingredients:["hamster","onions","carrots"]}, "Is this a bug or a feature? Could do a deep copy") ;
});
module("testEnvironment tests");
function makeurl() {
var testEnv = QUnit.current_testEnvironment;
var url = testEnv.url || 'http://example.com/search';
var q = testEnv.q || 'a search test';
return url + '?q='+encodeURIComponent(q);
}
test("makeurl working",function() {
equal( QUnit.current_testEnvironment, this, 'The current testEnvironment is global');
equal( makeurl(), 'http://example.com/search?q=a%20search%20test', 'makeurl returns a default url if nothing specified in the testEnvironment');
});
module("testEnvironment with makeurl settings", {
url: 'http://google.com/',
q: 'another_search_test'
});
test("makeurl working with settings from testEnvironment", function() {
equal( makeurl(), 'http://google.com/?q=another_search_test', 'rather than passing arguments, we use test metadata to form the url');
});
test("each test can extend the module testEnvironment", {
q:'hamstersoup'
}, function() {
equal( makeurl(), 'http://google.com/?q=hamstersoup', 'url from module, q from test');
});
module("jsDump");
test("jsDump output", function() {
equals( QUnit.jsDump.parse([1, 2]), "[\n 1,\n 2\n]" );
equals( QUnit.jsDump.parse({top: 5, left: 0}), "{\n \"top\": 5,\n \"left\": 0\n}" );
if (typeof document !== 'undefined' && document.getElementById("qunit-header")) {
equals( QUnit.jsDump.parse(document.getElementById("qunit-header")), "<h1 id=\"qunit-header\"></h1>" );
equals( QUnit.jsDump.parse(document.getElementsByTagName("h1")), "[\n <h1 id=\"qunit-header\"></h1>\n]" );
}
});
module("assertions");
test("raises",function() {
function CustomError( message ) {
this.message = message;
}
CustomError.prototype.toString = function() {
return this.message;
};
raises(
function() {
throw "error"
}
);
raises(
function() {
throw "error"
},
'raises with just a message, no expected'
);
raises(
function() {
throw new CustomError();
},
CustomError,
'raised error is an instance of CustomError'
);
raises(
function() {
throw new CustomError("some error description");
},
/description/,
"raised error message contains 'description'"
);
raises(
function() {
throw new CustomError("some error description");
},
function( err ) {
if ( (err instanceof CustomError) && /description/.test(err) ) {
return true;
}
},
"custom validation function"
);
});
if (typeof document !== "undefined") {
module("fixture");
test("setup", function() {
document.getElementById("qunit-fixture").innerHTML = "foobar";
});
test("basics", function() {
equal( document.getElementById("qunit-fixture").innerHTML, "test markup", "automatically reset" );
});
}
module("custom assertions");
(function() {
function mod2(value, expected, message) {
var actual = value % 2;
QUnit.push(actual == expected, actual, expected, message);
}
test("mod2", function() {
mod2(2, 0, "2 % 2 == 0");
mod2(3, 1, "3 % 2 == 1");
})
})();
module("recursions");
function Wrap(x) {
this.wrap = x;
if (x == undefined) this.first = true;
}
function chainwrap(depth, first, prev) {
depth = depth || 0;
var last = prev || new Wrap();
first = first || last;
if (depth == 1) {
first.wrap = last;
}
if (depth > 1) {
last = chainwrap(depth-1, first, new Wrap(last));
}
return last;
}
test("check jsDump recursion", function() {
expect(4);
var noref = chainwrap(0);
var nodump = QUnit.jsDump.parse(noref);
equal(nodump, '{\n "wrap": undefined,\n "first": true\n}');
var selfref = chainwrap(1);
var selfdump = QUnit.jsDump.parse(selfref);
equal(selfdump, '{\n "wrap": recursion(-1),\n "first": true\n}');
var parentref = chainwrap(2);
var parentdump = QUnit.jsDump.parse(parentref);
equal(parentdump, '{\n "wrap": {\n "wrap": recursion(-2),\n "first": true\n }\n}');
var circref = chainwrap(10);
var circdump = QUnit.jsDump.parse(circref);
ok(new RegExp("recursion\\(-10\\)").test(circdump), "(" +circdump + ") should show -10 recursion level");
});
test("check (deep-)equal recursion", function() {
var noRecursion = chainwrap(0);
equal(noRecursion, noRecursion, "I should be equal to me.");
deepEqual(noRecursion, noRecursion, "... and so in depth.");
var selfref = chainwrap(1);
equal(selfref, selfref, "Even so if I nest myself.");
deepEqual(selfref, selfref, "... into the depth.");
var circref = chainwrap(10);
equal(circref, circref, "Or hide that through some levels of indirection.");
deepEqual(circref, circref, "... and checked on all levels!");
});
test('Circular reference with arrays', function() {
// pure array self-ref
var arr = [];
arr.push(arr);
var arrdump = QUnit.jsDump.parse(arr);
equal(arrdump, '[\n recursion(-1)\n]');
equal(arr, arr[0], 'no endless stack when trying to dump arrays with circular ref');
// mix obj-arr circular ref
var obj = {};
var childarr = [obj];
obj.childarr = childarr;
var objdump = QUnit.jsDump.parse(obj);
var childarrdump = QUnit.jsDump.parse(childarr);
equal(objdump, '{\n "childarr": [\n recursion(-2)\n ]\n}');
equal(childarrdump, '[\n {\n "childarr": recursion(-2)\n }\n]');
equal(obj.childarr, childarr, 'no endless stack when trying to dump array/object mix with circular ref');
equal(childarr[0], obj, 'no endless stack when trying to dump array/object mix with circular ref');
});
test('Circular reference - test reported by soniciq in #105', function() {
var MyObject = function() {};
MyObject.prototype.parent = function(obj) {
if (obj === undefined) { return this._parent; }
this._parent = obj;
};
MyObject.prototype.children = function(obj) {
if (obj === undefined) { return this._children; }
this._children = obj;
};
var a = new MyObject(),
b = new MyObject();
var barr = [b];
a.children(barr);
b.parent(a);
equal(a.children(), barr);
deepEqual(a.children(), [b]);
});
(function() {
var reset = QUnit.reset;
function afterTest() {
ok( false, "reset should not modify test status" );
}
module("reset");
test("reset runs assertions", function() {
QUnit.reset = function() {
afterTest();
reset.apply( this, arguments );
};
});
test("reset runs assertions2", function() {
QUnit.reset = reset;
});
})();
module("noglobals", {
teardown: function() {
delete window.badGlobalVariableIntroducedInTest;
}
});
test("let teardown clean up globals", function() {
// this test will always pass if run without ?noglobals=true
window.badGlobalVariableIntroducedInTest = true;
});