|
1 | 1 | (function(){ |
2 | | - var test = function(data){ |
| 2 | + var test = function(data){ |
3 | 3 | 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 | + }; |
8 | 8 |
|
9 | 9 | $.each(data.directories, function(i, dir){ |
10 | 10 | asyncTest( dir, function(){ |
11 | | - var nextCheck = null; |
| 11 | + var testTimeout = 2 * 60 * 1000, checkInterval = 2000; |
12 | 12 |
|
13 | 13 | // establish a timeout for a given suite in case of async tests hanging |
14 | | - var testTimeout = setTimeout( function(){ |
| 14 | + var testTimer = setTimeout( function(){ |
15 | 15 | // prevent any schedule checks for completion |
16 | | - clearTimeout(nextCheck); |
| 16 | + clearTimeout( checkTimer ); |
17 | 17 | start(); |
18 | | - }, 2 * 60 * 1000 ), |
| 18 | + }, testTimeout ), |
19 | 19 |
|
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 ); |
24 | 21 |
|
25 | 22 | // check the iframe for success or failure and respond accordingly |
26 | | - check = function(){ |
27 | | - |
| 23 | + function check(){ |
28 | 24 | // check for the frames jquery object each time |
29 | 25 | var framejQuery = window.frames["testFrame"].jQuery; |
30 | 26 |
|
31 | 27 | // 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; |
36 | 29 |
|
37 | 30 | // 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" ); |
40 | 33 |
|
41 | 34 | // if we have a result check it, otherwise check back shortly |
42 | 35 | if( result ){ |
43 | 36 | 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 ); |
45 | 41 | start(); |
46 | | - } else { |
47 | | - scheduleCheck(); |
48 | 42 | } |
49 | 43 | }; |
50 | 44 |
|
51 | 45 | expect( 1 ); |
| 46 | + |
| 47 | + // set the test suite page on the iframe |
52 | 48 | updateFrame( dir ); |
53 | | - scheduleCheck(); |
54 | 49 | }); |
55 | 50 | }); |
56 | 51 | }; |
57 | 52 |
|
58 | 53 | // get the test directories |
59 | | - $.ajax({ |
60 | | - url: "ls.php", |
61 | | - success: test |
62 | | - }); |
| 54 | + $.get("ls.php", test); |
63 | 55 | })(); |
0 commit comments