Skip to content

Commit 97feeaf

Browse files
committed
moved check to interval, made the directories an ajax call instead of a templated js array, and reorged some bits to clean things up
1 parent a7045d3 commit 97feeaf

File tree

3 files changed

+23
-31
lines changed

3 files changed

+23
-31
lines changed

tests/unit/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<html lang="en">
33
<head>
44
<meta charset="utf-8">
5+
<link rel="stylesheet" href="../../external/qunit.css"></link>
56
</head>
67
<body>
78
<div style="float: left; width: 500px;">
@@ -14,7 +15,6 @@
1415
I think an entire link and stylesheet is a waste -->
1516
<iframe data-src="../../tests/unit/{{testdir}}" name="testFrame" id="testFrame" width="800px" height="100%" style="float: left; border: 0px; height: 100%;" scrolling="no">
1617
</iframe>
17-
<link rel="stylesheet" href="../../external/qunit.css"></link>
1818
<script src="../../js/jquery.js"></script>
1919
<script src="../../external/qunit.js"></script>
2020
<script src="runner.js"></script>

tests/unit/ls.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
closedir($handle);
1414
}
1515

16-
echo json_encode($response)
16+
echo json_encode($response)
1717
?>

tests/unit/runner.js

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,55 @@
11
(function(){
2-
var test = function(data){
2+
var test = function(data){
33
var $frameElem = $("#testFrame"),
4-
template = $frameElem.attr("data-src"),
5-
updateFrame = function(dir){
6-
return $frameElem.attr("src", template.replace("{{testdir}}", dir));
7-
};
4+
template = $frameElem.attr("data-src"),
5+
updateFrame = function(dir){
6+
return $frameElem.attr("src", template.replace("{{testdir}}", dir));
7+
};
88

99
$.each(data.directories, function(i, dir){
1010
asyncTest( dir, function(){
11-
var nextCheck = null;
11+
var testTimeout = 2 * 60 * 1000, checkInterval = 2000;
1212

1313
// establish a timeout for a given suite in case of async tests hanging
14-
var testTimeout = setTimeout( function(){
14+
var testTimer = setTimeout( function(){
1515
// prevent any schedule checks for completion
16-
clearTimeout(nextCheck);
16+
clearTimeout( checkTimer );
1717
start();
18-
}, 2 * 60 * 1000 ),
18+
}, testTimeout ),
1919

20-
// setup the next state check and record the timer id for removal
21-
scheduleCheck = function(){
22-
nextCheck = setTimeout( check, 2000 );
23-
},
20+
checkTimer = setInterval( check, checkInterval );
2421

2522
// check the iframe for success or failure and respond accordingly
26-
check = function(){
27-
23+
function check(){
2824
// check for the frames jquery object each time
2925
var framejQuery = window.frames["testFrame"].jQuery;
3026

3127
// if the iframe hasn't loaded (ie loaded jQuery) check back again shortly
32-
if( !framejQuery ){
33-
scheduleCheck();
34-
return;
35-
}
28+
if( !framejQuery ) return;
3629

3730
// grab the result of the iframe test suite
38-
// TODO strip extra white space
39-
var result = framejQuery("#qunit-banner").attr('class');
31+
// TODO strip extra white space
32+
var result = framejQuery( "#qunit-banner" ).attr( "class" );
4033

4134
// if we have a result check it, otherwise check back shortly
4235
if( result ){
4336
ok( result == "qunit-pass" );
44-
clearTimeout(testTimeout);
37+
38+
// prevent the next interval of the check function and the test timeout
39+
clearTimeout( checkTimer );
40+
clearTimeout( testTimer );
4541
start();
46-
} else {
47-
scheduleCheck();
4842
}
4943
};
5044

5145
expect( 1 );
46+
47+
// set the test suite page on the iframe
5248
updateFrame( dir );
53-
scheduleCheck();
5449
});
5550
});
5651
};
5752

5853
// get the test directories
59-
$.ajax({
60-
url: "ls.php",
61-
success: test
62-
});
54+
$.get("ls.php", test);
6355
})();

0 commit comments

Comments
 (0)