mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Tests: Modified testsuites.js into a subsuiteRunner extension for QUnit.
This commit is contained in:
parent
70687f7955
commit
8fe87e2885
8
external/qunit.js
vendored
8
external/qunit.js
vendored
@ -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;
|
||||
}
|
||||
|
@ -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() {
|
||||
|
8
tests/unit/subsuiteRunner.css
Normal file
8
tests/unit/subsuiteRunner.css
Normal file
@ -0,0 +1,8 @@
|
||||
iframe.qunit-subsuite {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border-width: 1px 0 0;
|
||||
height: 600px;
|
||||
width: 100%;
|
||||
background: #fff;
|
||||
}
|
82
tests/unit/subsuiteRunner.js
Normal file
82
tests/unit/subsuiteRunner.js
Normal file
@ -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 ) );
|
@ -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 ) );
|
Loading…
Reference in New Issue
Block a user