|
| 1 | +(function( $, QUnit ) { |
| 2 | + |
| 3 | +$.extend( QUnit, { |
| 4 | + testSuites: function( suites ) { |
| 5 | + $.each( suites, function( i, suite ) { |
| 6 | + asyncTest( suite, function() { |
| 7 | + runSuite( suite ); |
| 8 | + }); |
| 9 | + }); |
| 10 | + }, |
| 11 | + |
| 12 | + testStart: function( data ) { |
| 13 | + // update the test status to show which test suite is running |
| 14 | + $( "#qunit-testresult" ).html( "Running " + data.name + "...<br> " ); |
| 15 | + }, |
| 16 | + |
| 17 | + testDone: function() { |
| 18 | + // undo the auto-expansion of failed tests |
| 19 | + $( "#qunit-tests > li.fail" ).each(function() { |
| 20 | + var test = $( this ); |
| 21 | + // avoid collapsing test results that the user manually opened |
| 22 | + if ( test.data( "auto-collapsed" ) ) { |
| 23 | + return; |
| 24 | + } |
| 25 | + test.data( "auto-collapsed", true ) |
| 26 | + .children( "ol" ).hide(); |
| 27 | + }); |
| 28 | + } |
| 29 | +}); |
| 30 | + |
| 31 | +// generate an iframe to run the test suite and proxy the iframe's QUnit |
| 32 | +// to pass all test info to the main page |
| 33 | +function runSuite( suite ) { |
| 34 | + var body = $( "body" ), |
| 35 | + iframe = $( "<iframe>", { src: suite } ) |
| 36 | + .css({ |
| 37 | + width: 1000, |
| 38 | + height: 1000 |
| 39 | + }) |
| 40 | + .appendTo( body ) |
| 41 | + [0], |
| 42 | + iframeWin = iframe.contentWindow; |
| 43 | + |
| 44 | + $( iframeWin ).bind( "load", function() { |
| 45 | + var module, test, |
| 46 | + count = 0; |
| 47 | + |
| 48 | + $.extend( iframeWin.QUnit, { |
| 49 | + moduleStart: function( data ) { |
| 50 | + // capture module name for messages |
| 51 | + module = data.name; |
| 52 | + }, |
| 53 | + |
| 54 | + testStart: function( data ) { |
| 55 | + // capture test name for messages |
| 56 | + test = data.name; |
| 57 | + }, |
| 58 | + |
| 59 | + log: function( data ) { |
| 60 | + // pass all test details through to the main page |
| 61 | + var message = module + ": " + test + ": " + data.message; |
| 62 | + expect( ++count ); |
| 63 | + QUnit.push( data.result, data.actual, data.expected, message ); |
| 64 | + }, |
| 65 | + |
| 66 | + done: function() { |
| 67 | + // hide the iframe from the main page once the tests are done |
| 68 | + // and start the wrapper test from the main page |
| 69 | + $( iframe ).hide(); |
| 70 | + start(); |
| 71 | + } |
| 72 | + }); |
| 73 | + }); |
| 74 | +} |
| 75 | + |
| 76 | +}( jQuery, QUnit ) ); |
0 commit comments