test-runner-template.tmpl 4.0 KB

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