Mercurial > repos > saskia-hiltemann > ireport
comparison DataTables-1.9.4/media/unit_testing/controller.js @ 0:ac5f9272033b draft
first upload
author | saskia-hiltemann |
---|---|
date | Tue, 01 Jul 2014 11:42:23 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:ac5f9272033b |
---|---|
1 var giTotalTestCount = 0; | |
2 var giActiveModule = 0; | |
3 var giModuleTests; | |
4 var giStartTime; | |
5 var giTest; | |
6 var gbStop = false; | |
7 var gtoTest; | |
8 | |
9 function fnTestStart ( sTestInfo ) | |
10 { | |
11 gaoTest[ giActiveModule ].iTests++; | |
12 document.getElementById('test_info').innerHTML += | |
13 (giActiveModule+1)+'.'+(giModuleTests+1)+'. '+sTestInfo+'... '; | |
14 document.getElementById('test_number').innerHTML = giTotalTestCount+1; | |
15 giModuleTests++; | |
16 giTotalTestCount++; | |
17 | |
18 /* Set a timer to catch stalled script */ | |
19 gtoTest = setTimeout( function () { | |
20 fnMessage( '<span class="error">WARNING - test script stalled. Likely a JS error</span>' ); | |
21 gbStop = true; | |
22 }, 3000 ); | |
23 } | |
24 | |
25 function fnTestResult ( bResult ) | |
26 { | |
27 clearTimeout( gtoTest ); | |
28 if ( bResult ) | |
29 { | |
30 fnMessage( 'Passed' ); | |
31 } | |
32 else | |
33 { | |
34 fnMessage( '<span class="error">FAILED</span>' ); | |
35 gbStop = true; | |
36 fnEnd( false ); | |
37 } | |
38 } | |
39 | |
40 function fnUnitStart( iTest ) | |
41 { | |
42 if ( !gbStop ) | |
43 { | |
44 giModuleTests = 0; | |
45 window.parent.test_arena.location.href = | |
46 (iTest==0?"":"../")+'templates/'+gaoTest[iTest].sTemplate+'.php?scripts='+gaoTest[iTest].sTest; | |
47 giTest = iTest; | |
48 } | |
49 } | |
50 | |
51 function fnStartMessage( sMessage ) | |
52 { | |
53 fnMessage( '<br><b>'+gaoTest[giTest].sGroup+' - '+sMessage+'</b>' ); | |
54 } | |
55 | |
56 function fnMessage( sMessage ) | |
57 { | |
58 var nInfo = document.getElementById('test_info'); | |
59 nInfo.innerHTML += sMessage+'<br>'; | |
60 nInfo.scrollTop = nInfo.scrollHeight; | |
61 } | |
62 | |
63 function fnUnitComplete() | |
64 { | |
65 if ( giActiveModule < gaoTest.length - 1 ) | |
66 { | |
67 fnUnitStart( ++giActiveModule ); | |
68 } | |
69 else | |
70 { | |
71 fnEnd( true ); | |
72 } | |
73 } | |
74 | |
75 function fnEnd( bSuccess ) | |
76 { | |
77 var iEndTime = new Date().getTime(); | |
78 var sTime = '<br>This test run took '+parseInt((iEndTime-giStartTime)/1000, 10)+ | |
79 ' second(s) to complete.'; | |
80 | |
81 if ( bSuccess ) | |
82 { | |
83 $('#test_running').html( 'Tests complete. '+giTotalTestCount+' tests were run.'+sTime ); | |
84 } | |
85 else | |
86 { | |
87 $('#test_running').html( 'Unit tests failed at test '+giTotalTestCount+'.'+sTime ); | |
88 } | |
89 } | |
90 | |
91 $(document).ready( function () { | |
92 giStartTime = new Date().getTime(); | |
93 fnUnitStart( giActiveModule ); | |
94 } ); |