Skip to content

Commit

Permalink
FLUID-4913: Updated to latest QUnit. Fixed an issue with missing addE…
Browse files Browse the repository at this point in the history
…ventListener stub in node.
  • Loading branch information
yzen committed Mar 5, 2013
1 parent 1648bda commit c28e48b
Show file tree
Hide file tree
Showing 7 changed files with 340 additions and 258 deletions.
3 changes: 3 additions & 0 deletions src/webapp/module/fluid.js
Expand Up @@ -52,6 +52,9 @@ https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
loadIncludes("includes.json");

var fluid = context.fluid;
// FLUID-4913: QUnit calls window.addEventListener on load. We need to add
// it to the context it will be loaded in.
context.addEventListener = fluid.identity;

fluid.loadInContext = loadInContext;
fluid.loadIncludes = loadIncludes;
Expand Down
75 changes: 63 additions & 12 deletions src/webapp/tests/lib/README
@@ -1,12 +1,63 @@
Attribution:
* This is the unit testing suite from jQuery dual-licensed under the GPL and
MIT licenses. This code is redistributed in Infusion under the MIT license.
* The original is available at http://docs.jquery.com/Qunit

Instructions:
* To run the unit test suite, simply open any of the *-test.html pages in
your web browser.

Note on jquery.simulate.js:
* This version of simulate shipped with jQuery UI 1.5.1,
downloaded July 2, 2008.
[QUnit](http://qunitjs.com) - A JavaScript Unit Testing Framework.
================================

QUnit is a powerful, easy-to-use, JavaScript unit testing framework. 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, e.g.
with its 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).

Development
-----------

To submit patches, fork the repository, create a branch for the change. Then implement
the change, run `grunt` to lint and test it, then commit, push and create a pull request.

Include some background for the change in the commit message and `Fixes #nnn`, referring
to the issue number you're addressing.

To run `grunt`, you need `node` and `npm`, then `npm install grunt -g`. That gives you a global
grunt binary. For additional grunt tasks, also run `npm install`.

Releases
--------

Install git-extras and run `git changelog` to update History.md. Clean up the
changelog, removing merge commits or whitespace cleanups.

Update qunit/qunit.js|css and package.json to the release version, commit and
tag (Put the 'v' in front of the tag, e.g. `v1.8.0`), update them again to
the next version, commit and push commits and tags:

git push --tags origin master

To upload to code.jquery.com (replace $version accordingly), ssh to code.origin.jquery.com:

cp qunit/qunit.js /var/www/html/code.jquery.com/qunit/qunit-$version.js
cp qunit/qunit.css /var/www/html/code.jquery.com/qunit/qunit-$version.css

Then update /var/www/html/code.jquery.com/index.html and purge it with:

curl -s http://code.origin.jquery.com/?reload

Update web-base-template to link to those files for qunitjs.com.

Publish to npm via

npm publish
4 changes: 2 additions & 2 deletions src/webapp/tests/lib/qunit/VERSION
@@ -1,2 +1,2 @@
jQuery doesn't formally release versions of QUnit. This version of qunit.js and qunit.css were taken from revision f2497114fa
https://github.com/jquery/qunit at 16/01/13
jQuery doesn't formally release versions of QUnit. This version of qunit.js and qunit.css were taken from revision 67585c7d98
https://github.com/jquery/qunit at 04/03/13
57 changes: 29 additions & 28 deletions src/webapp/tests/lib/qunit/addons/composite/index.html
@@ -1,33 +1,34 @@
<!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>
<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"
"test-file-1.html",
"test-file-2.html",
// optionally provide a name and path
{ name: "Test File 3", path: "test-file-3.html" }
]);
</pre>
<h4>Tests</h4>
<p>
<a href="composite-demo-test.html">Composite Demo</a>: A suite which demoes how Composite is bootstrapped and run.
</p>
</body>
</pre>
<h4>Tests</h4>
<p>
<a href="composite-demo-test.html">Composite Demo</a>: A suite which demoes how Composite is bootstrapped and run.
</p>
</body>
</html>
200 changes: 100 additions & 100 deletions src/webapp/tests/lib/qunit/addons/composite/qunit-composite.js
@@ -1,112 +1,112 @@
(function( QUnit ) {

QUnit.extend( QUnit, {
testSuites: function( suites ) {
QUnit.begin(function() {
QUnit.initIframe();
});

for ( var i = 0; i < suites.length; i++ ) {
QUnit.runSuite( suites[i] );
}

QUnit.done(function() {
this.iframe.style.display = "none";
});
},

runSuite: function( suite ) {
var path = suite;

if ( QUnit.is( 'object', suite ) ) {
path = suite.path;
suite = suite.name;
}

asyncTest( suite, function() {
QUnit.iframe.setAttribute( "src", path );
});
},

initIframe: function() {
var body = document.body,
iframe = this.iframe = document.createElement( "iframe" ),
iframeWin;

iframe.className = "qunit-subsuite";
body.appendChild( iframe );

function onIframeLoad() {
var module, test,
count = 0;

if (iframe.src === "") {
return;
}

iframeWin.QUnit.moduleStart(function( data ) {
// capture module name for messages
module = data.name;
});

iframeWin.QUnit.testStart(function( data ) {
// capture test name for messages
test = data.name;
});
iframeWin.QUnit.testDone(function() {
test = null;
});

iframeWin.QUnit.log(function( data ) {
if (test === null) {
return;
}
// 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 );
});

iframeWin.QUnit.done(function() {
// start the wrapper test from the main page
start();
});
}
QUnit.addEvent( iframe, "load", onIframeLoad );

iframeWin = iframe.contentWindow;
}
testSuites: function( suites ) {
QUnit.begin(function() {
QUnit.initIframe();
});

for ( var i = 0; i < suites.length; i++ ) {
QUnit.runSuite( suites[i] );
}

QUnit.done(function() {
this.iframe.style.display = "none";
});
},

runSuite: function( suite ) {
var path = suite;

if ( QUnit.is( 'object', suite ) ) {
path = suite.path;
suite = suite.name;
}

asyncTest( suite, function() {
QUnit.iframe.setAttribute( "src", path );
});
},

initIframe: function() {
var body = document.body,
iframe = this.iframe = document.createElement( "iframe" ),
iframeWin;

iframe.className = "qunit-subsuite";
body.appendChild( iframe );

function onIframeLoad() {
var module, test,
count = 0;

if (iframe.src === "") {
return;
}

iframeWin.QUnit.moduleStart(function( data ) {
// capture module name for messages
module = data.name;
});

iframeWin.QUnit.testStart(function( data ) {
// capture test name for messages
test = data.name;
});
iframeWin.QUnit.testDone(function() {
test = null;
});

iframeWin.QUnit.log(function( data ) {
if (test === null) {
return;
}
// 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 );
});

iframeWin.QUnit.done(function() {
// start the wrapper test from the main page
start();
});
}
QUnit.addEvent( iframe, "load", onIframeLoad );

iframeWin = iframe.contentWindow;
}
});

QUnit.testStart(function( data ) {
// update the test status to show which test suite is running
QUnit.id( "qunit-testresult" ).innerHTML = "Running " + data.name + "...<br>&nbsp;";
// update the test status to show which test suite is running
QUnit.id( "qunit-testresult" ).innerHTML = "Running " + data.name + "...<br>&nbsp;";
});

QUnit.testDone(function() {
var i,
current = QUnit.id( this.config.current.id ),
children = current.children,
src = this.iframe.src;

// undo the auto-expansion of failed tests
for ( i = 0; i < children.length; i++ ) {
if ( children[i].nodeName === "OL" ) {
children[i].style.display = "none";
}
}

QUnit.addEvent(current, "dblclick", function( e ) {
var target = e && e.target ? e.target : window.event.srcElement;
if ( target.nodeName.toLowerCase() === "span" || target.nodeName.toLowerCase() === "b" ) {
target = target.parentNode;
}
if ( window.location && target.nodeName.toLowerCase() === "strong" ) {
window.location = src;
}
});

current.getElementsByTagName('a')[0].href = src;
var i,
current = QUnit.id( this.config.current.id ),
children = current.children,
src = this.iframe.src;

// undo the auto-expansion of failed tests
for ( i = 0; i < children.length; i++ ) {
if ( children[i].nodeName === "OL" ) {
children[i].style.display = "none";
}
}

QUnit.addEvent(current, "dblclick", function( e ) {
var target = e && e.target ? e.target : window.event.srcElement;
if ( target.nodeName.toLowerCase() === "span" || target.nodeName.toLowerCase() === "b" ) {
target = target.parentNode;
}
if ( window.location && target.nodeName.toLowerCase() === "strong" ) {
window.location = src;
}
});

current.getElementsByTagName('a')[0].href = src;
});

}( QUnit ) );

0 comments on commit c28e48b

Please sign in to comment.