diff options
author | Wesley Walser <wwalser@atlassian.com> | 2011-08-02 12:30:29 -0400 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2011-08-02 12:30:29 -0400 |
commit | 8fe87e288544204925265a4e7f19b7dfa24deed6 (patch) | |
tree | 0280ab19f817daacbc2a41a5f8ac65d87635bbe3 /tests/unit | |
parent | 70687f7955cb2471ad6df3a7806031245e5979cd (diff) | |
download | jquery-ui-8fe87e288544204925265a4e7f19b7dfa24deed6.tar.gz jquery-ui-8fe87e288544204925265a4e7f19b7dfa24deed6.zip |
Tests: Modified testsuites.js into a subsuiteRunner extension for QUnit.
Diffstat (limited to 'tests/unit')
-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 |
4 files changed, 92 insertions, 77 deletions
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 ) ); |