Răsfoiți Sursa

Fix race condition in test runner

Previously, there would be a case where if your tests took
too long to run, the casper test runner would only report
on certain tests.  This has been fixed.
Solly Ross 11 ani în urmă
părinte
comite
9b731d3a58
2 a modificat fișierele cu 5 adăugiri și 2 ștergeri
  1. 4 1
      tests/run_from_console.casper.js
  2. 1 1
      tests/run_from_console.js

+ 4 - 1
tests/run_from_console.casper.js

@@ -26,7 +26,10 @@ var provide_emitter = function(file_paths) {
 
 
     file_paths.forEach(function(file_path, path_ind) {
     file_paths.forEach(function(file_path, path_ind) {
       spooky.thenOpen('file://'+file_path);
       spooky.thenOpen('file://'+file_path);
-      spooky.then([{ path_ind: path_ind }, function() {
+      spooky.waitFor(function() {
+        return this.getGlobal('__mocha_done') === true;
+      },
+      [{ path_ind: path_ind }, function() {
         var res_json = {
         var res_json = {
           file_ind: path_ind
           file_ind: path_ind
         };
         };

+ 1 - 1
tests/run_from_console.js

@@ -68,7 +68,7 @@ if (program.autoInject) {
   var template = {
   var template = {
     header: "<html>\n<head>\n<meta charset='utf-8' />\n<link rel='stylesheet' href='" + path.resolve(__dirname, 'node_modules/mocha/mocha.css') + "'/>\n</head>\n<body><div id='mocha'></div>",
     header: "<html>\n<head>\n<meta charset='utf-8' />\n<link rel='stylesheet' href='" + path.resolve(__dirname, 'node_modules/mocha/mocha.css') + "'/>\n</head>\n<body><div id='mocha'></div>",
     script_tag: function(p) { return "<script src='" + p + "'></script>"; },
     script_tag: function(p) { return "<script src='" + p + "'></script>"; },
-    footer: "<script>\nmocha.checkLeaks();\nmocha.globals(['navigator', 'create', 'ClientUtils', '__utils__']);\nmocha.run();\n</script>\n</body>\n</html>"
+    footer: "<script>\nmocha.checkLeaks();\nmocha.globals(['navigator', 'create', 'ClientUtils', '__utils__']);\nmocha.run(function () { window.__mocha_done = true; });\n</script>\n</body>\n</html>"
   };
   };
 
 
   template.header += "\n" + template.script_tag(path.resolve(__dirname, 'node_modules/chai/chai.js'));
   template.header += "\n" + template.script_tag(path.resolve(__dirname, 'node_modules/chai/chai.js'));