Use the --bail . Be sure to use at least mocha 0.14.0. (I tried this with older versions without success.)
Firstly, you have nothing to do for mocha to start a test only after the previous one is finished. This is how mocha works by default. Save this value in test.js :
describe("test", function () { this.timeout(5 * 1000); // Tests time out in 5 seconds. it("first", function (done) { console.log("first: do nothing"); done(); }); it("second", function (done) { console.log("second is executing"); // This test will take 2.5 seconds. setTimeout(function () { done(); }, 2.5 * 1000); }); it("third", function (done) { console.log("third is executing"); // This test will time out. }); it("fourth", function (done) { console.log("fourth: do nothing"); done(); }); });
Then execute it with
mocha -R spec test.js
You will not see the fourth test run until:
- The first and second tests are completed.
- The third test has a timeout.
Now run it with
mocha -R spec --bail test.js
Mocha stops as soon as test 3 fails.
Louis
source share