added a page to run all the tests in a single place, depends on subdirectories representing their tested mobile files

This commit is contained in:
John Bender 2011-06-26 12:09:56 -07:00
parent 345c9e4dbb
commit 75a4a0795c
2 changed files with 81 additions and 0 deletions

36
tests/unit/index.php Normal file
View file

@ -0,0 +1,36 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<div style="float: left; width: 500px;">
<h1 id="qunit-header"><a href="#">jQuery Mobile Complete Test Suite</a></h1>
<h2 id="qunit-banner"></h2>
<ol id="qunit-tests">
</ol>
</div>
<iframe data-src="/tests/unit/{{testdir}}" name="testFrame" id="testFrame" width="800px" height="100%" style="float: left; border: 0px;" scrolling="no">
</iframe>
<link rel="stylesheet" href="../../external/qunit.css"></link>
<script src="/js/jquery.js"></script>
<script src="../../external/qunit.js"></script>
<script type="text/javascript">
window.testDirectories = [
<?php
// TODO move to php which produces json or data attrs. This is just dirty.
if ($handle = opendir(getcwd())) {
while (false !== ($file = readdir($handle))) {
if (is_dir($file) && $file[0] !== "." ) {
echo "'$file',\n";
}
}
closedir($handle);
}
?>
];
</script>
<script src="runner.js"></script>
</body>
</html>

45
tests/unit/runner.js Normal file
View file

@ -0,0 +1,45 @@
(function(){
var $frameElem = $("#testFrame"),
template = $frameElem.attr("data-src"),
updateFrame = function(dir){
return $frameElem.attr("src", template.replace("{{testdir}}", dir));
};
$.each(testDirectories, function(i, dir){
asyncTest( dir, function(){
// give each test a maximum of two minutes to finish
var testTimeout = setTimeout( function(){
console.log("wtf");
start();
}, 2 * 60 * 1000 );
expect( 1 );
updateFrame( dir );
function check(){
// check for the frames jquery object each time
var framejQuery = window.frames["testFrame"].jQuery;
// if the iframe hasn't loaded (ie loaded jQuery) check back again shortly
if( !framejQuery ){
return;
setTimeout( arguments.callee, 2000 );
}
// grab the result of the iframe test suite
var result = framejQuery("#qunit-banner").attr('class');
// if we have a result check it, otherwise check back shortly
if( result ){
ok( result == "qunit-pass" );
clearTimeout(testTimeout);
start();
} else {
setTimeout( arguments.callee, 2000 );
}
}
setTimeout( check, 2000 );
});
});
})();