test-runner-template.tmpl 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Jasmine Spec Runner</title>
  6. <!-- generate script tags for tests -->
  7. <% var generateScriptTags = function(allScripts) { allScripts.forEach(function(script){ %>
  8. <script src="<%= script %>"></script>
  9. <% }); }; %>
  10. <!-- generate script tags for tests -->
  11. <% var toArray = function(scripts) {
  12. %>[<%
  13. scripts.forEach(function(scriptUrl, index){
  14. %>"<%= scriptUrl %>"<%
  15. if (index !== scripts.length -1) {
  16. %>,<%
  17. }
  18. });
  19. %>]<%
  20. }; %>
  21. <!-- for each test, generate CSS/LESS link tags -->
  22. <% scripts.src.forEach(function(fullLessName) {
  23. var pathParts = fullLessName.split('/');
  24. var fullCssName = fullLessName.replace(/less/g, 'css');
  25. var lessName = pathParts[pathParts.length - 1];
  26. var name = lessName.split('.')[0]; %>
  27. <!-- the tags to be generated -->
  28. <link id="original-less:test-less-<%= name %>" title="test-less-<%= name %>" rel="stylesheet/less" type="text/css" href="<%= fullLessName %>">
  29. <link id="expected-less:test-less-<%= name %>" rel="stylesheet" type="text/css" href="<%= fullCssName %>">
  30. <% }); %>
  31. <!-- generate grunt-contrib-jasmine link tags -->
  32. <% css.forEach(function(style){ %>
  33. <link rel="stylesheet" type="text/css" href="<%= style %>">
  34. <% }) %>
  35. <script>
  36. function loadScript(url,callback){
  37. var script = document.createElement('script');
  38. if(document.documentMode === 8){
  39. script.onreadystatechange = function(){
  40. if (script.readyState === 'loaded'){
  41. if (callback){callback()};
  42. };
  43. };
  44. } else {
  45. script.onload = function(){
  46. if (callback){callback()};
  47. };
  48. };
  49. script.src = url;
  50. document.body.appendChild(script);
  51. };
  52. // allow sauce to query for the jasmine report
  53. // because we have to load the page before starting the test, so the thing
  54. // sauce queries for might not be setup yet
  55. window.jasmine = { getJSReport: function() { } };
  56. setTimeout(function() {
  57. var jasmine = <% toArray([].concat(scripts.polyfills, scripts.jasmine, scripts.boot)) %>,
  58. helpers = <% toArray(scripts.helpers) %>,
  59. vendor = <% toArray(scripts.vendor) %>,
  60. specs = <% toArray(scripts.specs) %>,
  61. reporters = <% toArray([].concat(scripts.reporters)) %>,
  62. allScripts = jasmine.concat(helpers).concat(vendor).concat(specs).concat(reporters);
  63. function addNextScript() {
  64. // for sauce, see above. Additional step needed between loading jasmine and loading
  65. // the js reporter
  66. if (!jasmine.getJSReport) {
  67. jasmine.getJSReport = function() {};
  68. }
  69. if (allScripts.length) {
  70. var scriptSrc = allScripts.shift();
  71. loadScript(scriptSrc, addNextScript);
  72. } else {
  73. window.onload();
  74. }
  75. }
  76. addNextScript();
  77. },1000);
  78. </script>
  79. </head>
  80. <body>
  81. <!-- content -->
  82. </body>
  83. </html>