diff options
-rw-r--r-- | external/qunit.js | 8 | ||||
-rw-r--r-- | tests/unit/all.html | 3 | ||||
-rw-r--r-- | tests/unit/subsuiteRunner.css | 8 | ||||
-rw-r--r-- | tests/unit/subsuiteRunner.js | 82 | ||||
-rw-r--r-- | tests/unit/testsuites.js | 76 |
5 files changed, 98 insertions, 79 deletions
diff --git a/external/qunit.js b/external/qunit.js index d56936ee2..a1b3fa5e9 100644 --- a/external/qunit.js +++ b/external/qunit.js @@ -625,7 +625,7 @@ extend(QUnit, { var source = sourceFromStacktrace(); if (source) { details.source = source; - output += '<tr class="test-source"><th>Source: </th><td><pre>' + source +'</pre></td></tr>'; + output += '<tr class="test-source"><th>Source: </th><td><pre>' + escapeHtml(source) + '</pre></td></tr>'; } } output += "</table>"; @@ -649,6 +649,10 @@ extend(QUnit, { return window.location.pathname + querystring.slice( 0, -1 ); }, + extend: extend, + id: id, + addEvent: addEvent, + // Logging callbacks; all receive a single argument with the listed properties // run test/logs.html for any related changes begin: function() {}, @@ -779,7 +783,7 @@ function done() { } if ( typeof document !== "undefined" && document.title ) { - // show ✖ for good, ✔ for bad suite result in title + // show ✖ for bad, ✔ for good suite result in title // use escape sequences in case file gets loaded with non-utf-8-charset document.title = (config.stats.bad ? "\u2716" : "\u2714") + " " + document.title; } diff --git a/tests/unit/all.html b/tests/unit/all.html index 284885dbc..41d379534 100644 --- a/tests/unit/all.html +++ b/tests/unit/all.html @@ -7,8 +7,9 @@ <script src="../../jquery-1.6.2.js"></script> <link rel="stylesheet" href="../../external/qunit.css"> + <link rel="stylesheet" href="subsuiteRunner.css"> <script src="../../external/qunit.js"></script> - <script src="testsuites.js"></script> + <script src="subsuiteRunner.js"></script> <script> (function() { diff --git a/tests/unit/subsuiteRunner.css b/tests/unit/subsuiteRunner.css new file mode 100644 index 000000000..bca30a75e --- /dev/null +++ b/tests/unit/subsuiteRunner.css @@ -0,0 +1,8 @@ +iframe.qunit-subsuite { + margin: 0; + padding: 0; + border-width: 1px 0 0; + height: 600px; + width: 100%; + background: #fff; +}
\ No newline at end of file diff --git a/tests/unit/subsuiteRunner.js b/tests/unit/subsuiteRunner.js new file mode 100644 index 000000000..ddfccc7c1 --- /dev/null +++ b/tests/unit/subsuiteRunner.js @@ -0,0 +1,82 @@ +(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> "; + }, + + 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 ) ); diff --git a/tests/unit/testsuites.js b/tests/unit/testsuites.js deleted file mode 100644 index ffe2d3cc0..000000000 --- a/tests/unit/testsuites.js +++ /dev/null @@ -1,76 +0,0 @@ -(function( $, QUnit ) { - -$.extend( QUnit, { - testSuites: function( suites ) { - $.each( suites, function( i, suite ) { - asyncTest( suite, function() { - runSuite( suite ); - }); - }); - }, - - testStart: function( data ) { - // update the test status to show which test suite is running - $( "#qunit-testresult" ).html( "Running " + data.name + "...<br> " ); - }, - - testDone: function() { - // undo the auto-expansion of failed tests - $( "#qunit-tests > li.fail" ).each(function() { - var test = $( this ); - // avoid collapsing test results that the user manually opened - if ( test.data( "auto-collapsed" ) ) { - return; - } - test.data( "auto-collapsed", true ) - .children( "ol" ).hide(); - }); - } -}); - -// generate an iframe to run the test suite and proxy the iframe's QUnit -// to pass all test info to the main page -function runSuite( suite ) { - var body = $( "body" ), - iframe = $( "<iframe>", { src: suite } ) - .css({ - width: 1000, - height: 1000 - }) - .appendTo( body ) - [0], - iframeWin = iframe.contentWindow; - - $( iframeWin ).bind( "load", function() { - var module, test, - count = 0; - - $.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() { - // hide the iframe from the main page once the tests are done - // and start the wrapper test from the main page - $( iframe ).hide(); - start(); - } - }); - }); -} - -}( jQuery, QUnit ) ); |