]> source.dussan.org Git - jquery-ui.git/commitdiff
Tests: Modified testsuites.js into a subsuiteRunner extension for QUnit.
authorWesley Walser <wwalser@atlassian.com>
Tue, 2 Aug 2011 16:30:29 +0000 (12:30 -0400)
committerScott González <scott.gonzalez@gmail.com>
Tue, 2 Aug 2011 16:30:29 +0000 (12:30 -0400)
external/qunit.js
tests/unit/all.html
tests/unit/subsuiteRunner.css [new file with mode: 0644]
tests/unit/subsuiteRunner.js [new file with mode: 0644]
tests/unit/testsuites.js [deleted file]

index d56936ee25392d7b44b405d71f8418dc8b83a5d7..a1b3fa5e9d4dd24fbf378f78d729561521a2a699 100644 (file)
@@ -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;
        }
index 284885dbc6b0e34989f72e8133661ce13c2691eb..41d3795343ea5b0048388bb30c368067534c3fb7 100644 (file)
@@ -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 (file)
index 0000000..bca30a7
--- /dev/null
@@ -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 (file)
index 0000000..ddfccc7
--- /dev/null
@@ -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>&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 ) );
diff --git a/tests/unit/testsuites.js b/tests/unit/testsuites.js
deleted file mode 100644 (file)
index ffe2d3c..0000000
+++ /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>&nbsp;" );
-       },
-
-       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 ) );