annotate DataTables-1.9.4/media/unit_testing/controller.js @ 7:0f2b740536fb draft

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