This gist produces the following output, where test 3 runs twice. (It actually does run twice, as can be observed with the process.stdout.writes; it's not just a reporting artifact)
child_process: customFds option is deprecated, use stdio instead.
✓ test 1
1) test 1
This actually runs twice.
This actually runs twice.
2) test 3
3) test 3
1 passing (8ms)
3 failing
1) test 1:
Uncaught Error: Too bad
at /Users/dom/Dev/JSRad/dupe-test.js:3:15
at process._tickCallback (node.js:343:11)
2) test 3:
Error: done() invoked with non-Error: OUCH
at Object.<anonymous> (/Users/dom/Dev/JSRad/node_modules/mocha.git/lib/runnable.js:223:25)
at process._tickCallback (node.js:343:11)
3) test 3:
Error: done() invoked with non-Error: OUCH
at Object.<anonymous> (/Users/dom/Dev/JSRad/node_modules/mocha.git/lib/runnable.js:223:25)
at process._tickCallback (node.js:343:11)
This looks like it could be related with https://github.com/visionmedia/mocha/issues/660
your first test needs to use done:
it("test 1", function(done) {
process.nextTick(function() {
throw new Error("Too bad");
done();
});
});
it("test 2", function() {});
it("test 3", function(done) {
process.stdout.write("This actually runs twice.\n");
process.nextTick(done.bind({},"OUCH"));
});
1) test 1
✓ test 2
This actually runs twice.
2) test 3
1 passing (5ms)
2 failing
1) test 1:
Uncaught Error: Too bad
at /Users/tj/dev/mocha-test/test.js:5:15
at process._tickCallback (node.js:419:13)
2) test 3:
Error: done() invoked with non-Error: OUCH
at Object.<anonymous> (/Users/tj/dev/mocha-test/node_modules/mocha/lib/runnable.js:222:25)
at process._tickCallback (node.js:419:13)
2014-08-29 23:52 GMT+02:00 Travis Jeffery [email protected]:
your first test needs to use done:
Hi Travis, thanks for the quick reply.
I arrived to this gist by minimizing a much larger problematic case, and
indeed at this point pretty much any change will make the reported symptom
disappear. Still, it seems to me that it() test bodies should never run
twice (and whatever happens in the tests that run before them shouldn't
make a difference whether they do).
I'll work on the issue next week, but I'll need some time to get up to
speed with the mocha code base.
It's bedtime now in Europe, have a nice evening,
Dominique Quatravaux
[email protected]
Please pull from https://github.com/visionmedia/mocha/pull/1335 for a regression test and a fix.
Thanks for reporting and fixing this!
This seems to be happening again.
@diegoalberto do you have an example? The regression test for this issue is showing things are fine: https://github.com/mochajs/mocha/pull/1686
Hello, not really sure if this is the same error as the one I'm referring to:
https://github.com/mad-eye/meteor-mocha-web/issues/166
Test being run twice on velocity mocha.
I fixed this in my case by encapsulating my Mocha.run() in the following condition. I'm not sure why it does but...
if (navigator.userAgent.indexOf('PhantomJS') === -1) {
mocha.run();
}
Oooh I get it. mocha.run() in the yeoman generator-backbone project I'm using, mocha.run() is inserted dynamically while that mocha.run() there in my DOM is for when a browser that isn't PhantomJS hits the page. Without that if statement, mocha.run() would definitely be run twice which would cause all the it calls to run twice.
@rjsteinert - didn't solve the problem for me when running tests though the HTML file in the browser. failed tests still appear twice :(
<html>
<head>
<meta charset="utf-8">
<link href="mocha.css" rel="stylesheet" />
<link href="tests.css" rel="stylesheet" />
</head>
<body>
<div id="mocha"></div>
<script src="../node_modules/mocha/mocha.js"></script>
<script src="../node_modules/chai/chai.js"></script>
<script>
mocha.setup('bdd');
mocha.ui('bdd');
var expect = chai.expect;
var should = chai.should();
var assert = chai.assert;
</script>
<script src="bin/test.js"></script>
<script>
if( navigator.userAgent.indexOf('PhantomJS') === -1 ){
mocha.run();
}
</script>
</body>
</html>
describe('Test', ()=> {
it('Failed test', ()=>{
'1'.should.equal(2);
});
});
Failed tests shown twice... [email protected]
I am experiencing the issue above.
Here is a js-fiddle, I am forcing a failing test to showcase that failing tests display twice:
https://jsfiddle.net/sgnl/wfyavarf/2/
^ above example is fixed with mocha 5: https://jsfiddle.net/wfyavarf/9/
Duplicate error reports in the browser will be fixed via https://github.com/mochajs/mocha/pull/2112
I'm seeing the test run twice in the browser despite being on Mocha 3.1.2.
Sorry, my mistake...
Any resolution for this?
+1 getting same error.
Came across this issue while trying to debug an issue I had with an amqplib. Turns out that I had an async action that would emit an error using Node's EventEmitter API. So I'm assuming the test had received the promise rejection plus the error that was never caught from the event emitter. I managed to get it to stop reproducing the test by implementing on('error') and handling the error on the event emitter. Hope this helps.
@johnslay Thanks for the tip! I'll try it
It was happening to me due to not passing done and calling it, but could not understand why was it run twice because of this.
@meetDeveloper this just happened to me as well
Same failed test ran twice despite having done handled properly:
3) should update the attribute: awayMode of a device with: {"type":"action"}
4) should update the attribute: awayMode of a device with: {"type":"action"}
I got same issue, I only have one case.
#indexOf()
√ new test (1979ms)
#indexOf()
√ new test (4547ms)
2 passing (7s)
For me the Glob path for spec was running/FINDING a test twice.
AND using QUOTING mattered.
I landed on using single quotes around my Glob path in my npm script: https://github.com/resistdesign/rdx/blob/refactor/2020/package.json#L30
"test:int": "mocha --inline-diffs --require resistdesign-babel-register --ui exports './src/**/*.integration.jsx'"
Most helpful comment
Came across this issue while trying to debug an issue I had with an
amqplib. Turns out that I had an async action that would emit an error using Node'sEventEmitterAPI. So I'm assuming the test had received the promise rejection plus the error that was never caught from the event emitter. I managed to get it to stop reproducing the test by implementingon('error')and handling the error on the event emitter. Hope this helps.