Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

Old test suite finishes up before next --watch run

Benjie Gillam0d3762da5046
diff --git a/bin/_mocha b/bin/_mocha
index c60e86d3..950836f4 100644
--- a/bin/_mocha
+++ b/bin/_mocha
@@ -307,11 +307,18 @@ if (program.watch) {
});
var watchFiles = utils.files(cwd);
+ var runAgain = false;
function loadAndRun() {
try {
mocha.files = files;
- runner = mocha.run(function(){});
+ runAgain = false;
+ runner = mocha.run(function(){
+ runner = null;
+ if (runAgain) {
+ rerun();
+ }
+ });
} catch(e) {
console.log(e.stack);
}
@@ -325,15 +332,21 @@ if (program.watch) {
loadAndRun();
- utils.watch(watchFiles, function(){
+ function rerun() {
purge();
stop()
- if (runner) {
- runner.abort();
- }
mocha.suite = mocha.suite.clone();
mocha.ui(program.ui);
loadAndRun();
+ }
+
+ utils.watch(watchFiles, function(){
+ runAgain = true;
+ if (runner) {
+ runner.abort();
+ } else {
+ rerun();
+ }
});
return;