-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uncaught exceptions are silenced if happen in timeframe of skipped test #3938
Comments
Test1 should pass, though the error may get caught outside the test itself (depending on timing). All other tests should be marked pending regardless. |
It's a question of how mocha handles the case where user misconfigured the test so it results with unhandled exception. I believe the goal is to expose such errors unconditionally, in this case it doesn't happen, therefore it's a bug. |
Which part of my reply are you implying Mocha does incorrectly here -- Test1 or the other three? Your "Expected Behavior" is hard to tell what you expect -- did you mean "all" tests or only the attempted fail of first one? |
Incorrect is assumption that developers do not make mistakes. In discussed case, test by mistake was configured that it ends before an actual job it started ends. The left over job additionally raises an uncaught exception (currently silenced by Mocha, therefore developer is left with no clue that tests setup is broken) I believe Test runner should not silence uncaught exceptions, no matter in what context they exploded, whether it was failed test, pending test, or maybe after all tests were registered as ended. It general it goes down to rule: unhandled errors should not be silenced |
Which is the result when you use |
Fail to understand why you continue to create new issues over the same problem though; you're creating synchronous Mocha tests which use asynchronous functions. If you want it fixed, send a PR. |
No, it's a different issue. All things I report are actually issues I discover when working with quite extensive Mocha setup in real world project (currently it comes with four Mocha bug patches, so it behaves reasonably) |
Seems like another aspect of same problem -- an uncaught error occurs in asynchronous code run from a synchronous Mocha test. Notwithstanding whether Mocha is lacking in this department, some chunk of the solution for you would be to write your tests using Mocha's asynchronous API instead... |
In this case it ends with output as: test
✓ test1
1) test2 Which indicates an error in And process exists with So it's also an invalid outcome |
Can you give me a more detailed explanation? describe('test', () => {
it('test1', () => {
setTimeout(() => {
throw new Error('Uncaught');
}, 3);
});
it('test2', function () {
console.log(2)
this.skip();
});
it('test3', function () {
console.log(3)
this.skip();
});
it('test4', function () {
console.log(4)
this.skip();
});
}); and result
is very clear, 1 passing because move to event loop and other things pending |
@wnghdcjfe run it few times, you'll see that in some cases test suite ends with success, not reporting the error. It happens only when race condition ( describe("test", () => {
it("test1", () => {
setTimeout(() => {
throw new Error("Uncaught");
}, 3);
});
it("test2", function() {
this.skip();
});
it("test3", function() {
this.skip();
});
it("test4", function() {
this.skip();
});
it("test5", function() {
this.skip();
});
it("test6", function() {
this.skip();
});
it("test7", function() {
this.skip();
});
it("test8", function() {
this.skip();
});
it("test9", function() {
this.skip();
});
it("test10", function() {
this.skip();
});
it("test11", function() {
this.skip();
});
});
|
Possibly related to #3740
Steps to Reproduce
Expected behavior:
Tests should fail unconditionally
Actual behavior:
In most cases suite passes (there is a race condition,due to which occasionally error gets exposed)
Versions
mocha: 6.1.4
Node.js: 12.3.1
macOS: 10.14.5
The text was updated successfully, but these errors were encountered: