controller.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. function fnTestStart ( sTestInfo )
  9. {
  10. gaoTest[ giActiveModule ].iTests++;
  11. document.getElementById('test_info').innerHTML +=
  12. (giActiveModule+1)+'.'+(giModuleTests+1)+'. '+sTestInfo+'... ';
  13. document.getElementById('test_number').innerHTML = giTotalTestCount+1;
  14. giModuleTests++;
  15. giTotalTestCount++;
  16. /* Set a timer to catch stalled script */
  17. gtoTest = setTimeout( function () {
  18. fnMessage( '<span class="error">WARNING - test script stalled. Likely a JS error</span>' );
  19. gbStop = true;
  20. }, 3000 );
  21. }
  22. function fnTestResult ( bResult )
  23. {
  24. clearTimeout( gtoTest );
  25. if ( bResult )
  26. {
  27. fnMessage( 'Passed' );
  28. }
  29. else
  30. {
  31. fnMessage( '<span class="error">FAILED</span>' );
  32. gbStop = true;
  33. fnEnd( false );
  34. }
  35. }
  36. function fnUnitStart( iTest )
  37. {
  38. if ( !gbStop )
  39. {
  40. giModuleTests = 0;
  41. window.parent.test_arena.location.href =
  42. (iTest==0?"":"../")+'templates/'+gaoTest[iTest].sTemplate+'.php?scripts='+gaoTest[iTest].sTest;
  43. giTest = iTest;
  44. }
  45. }
  46. function fnStartMessage( sMessage )
  47. {
  48. fnMessage( '<br><b>'+gaoTest[giTest].sGroup+' - '+sMessage+'</b>' );
  49. }
  50. function fnMessage( sMessage )
  51. {
  52. var nInfo = document.getElementById('test_info');
  53. nInfo.innerHTML += sMessage+'<br>';
  54. nInfo.scrollTop = nInfo.scrollHeight;
  55. }
  56. function fnUnitComplete()
  57. {
  58. if ( giActiveModule < gaoTest.length - 1 )
  59. {
  60. fnUnitStart( ++giActiveModule );
  61. }
  62. else
  63. {
  64. fnEnd( true );
  65. }
  66. }
  67. function fnEnd( bSuccess )
  68. {
  69. var iEndTime = new Date().getTime();
  70. var sTime = '<br>This test run took '+parseInt((iEndTime-giStartTime)/1000, 10)+
  71. ' second(s) to complete.';
  72. if ( bSuccess )
  73. {
  74. $('#test_running').html( 'Tests complete. '+giTotalTestCount+' tests were run.'+sTime );
  75. }
  76. else
  77. {
  78. $('#test_running').html( 'Unit tests failed at test '+giTotalTestCount+'.'+sTime );
  79. }
  80. }
  81. $(document).ready( function () {
  82. giStartTime = new Date().getTime();
  83. fnUnitStart( giActiveModule );
  84. } );