-
-
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
be more friendly about async "overspecified" errors; closes #2407 #2413
Conversation
cc @papandreou |
Interesting edge case. First workaround that comes to mind would be waiting for test sync execution to finish before paying attention to any calls to |
@@ -73,4 +73,28 @@ describe('regressions', function() { | |||
done(); | |||
}); | |||
}); | |||
|
|||
it.only('issue-2407: should fail gracefully when overspecified but done() never called', function(done) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove .only
. (This is why I always use -g
myself :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😊
Awesome. This is very close to what I had in mind when I looked at #2407. Haven't played around with your implementation, but the tests look sane :) |
I noticed that the stack traces here are useless. Making them better. |
And then I noticed:
This is becoming kind of a rabbit hole. I'd rather do this the right way instead of half-assed. I want to shelve this for now; better documentation around the issue could help. Is anyone dying to get this in? |
@ScottFreeCode mainly I'm concerned about adding a bunch of complexity around this. The idea was to help the user see they likely have a bug, or are otherwise misusing the API. The challenge is both covering all of the weird cases that exist (I can think of 7-8 offhand) and providing as much information as possible. I'm not thrilled about forcing an "async" test to actually be async. On some level that makes a lot of sense. But IMO, it's too severe of a change for this issue. If we don't do it, we reduce the number of cases we can recognize and report to the user. I can reduce this PR to cover the single case reported in #2407. That would be best course of action, since Mocha can't get too smart without significant changes to the runner. Thoughts? |
To clarify, we're not talking about disallowing, say, a Promise API that's being tested from using
Maybe if
Sounds reasonable to me; I may be repeating myself, but while I don't have a strong opinion on whether using promises and |
We are operating under the assertion that there is no valid use case for |
I thought there were some examples in the discussion surrounding the original issue. Not things where anyone had to use them together, just things where it might be marginally simpler to do so than to use promises alone. E.g. #2407 (comment), #2407 (comment) (I also have a vague recollection that it came up in Gitter at some point, but Gitter's not great for finding past conversation...) I don't have a strong opinion on the value of such constructions, however; so I am fine either way when it comes to how extensive we want the current fix to be. PR looks fine as far as I can tell at the moment, by the way, although I should really download it and try it out. |
Those two comments are both hypothetical; I would like to see an actual test that needed to use both Promises (or cc @elado UPDATE (Because in the general case this is a bug. We could downgrade it to a warning if somebody shows that it's useful and necessary to use both.) |
@ScottFreeCode This is one of those changes that, while not strictly violating semver, would potentially cause complaints about tests which magically start failing upon a minor or patch upgrade. The crux of it is here. In For emphasis, your test does not run asynchronously. Instead, With this change, your test would finish some milliseconds after you told it you were finished by calling Whether or not this is more correct or less correct than the current behavior is unclear (though I said it seemed "more correct" originally). The "most correct" thing, if we wanted to force async, would be to run the test function in a |
@boneskull My general use-case for using both is that there's no built-in ability to ensure that assertions are run. The pattern embraced is to use
Without P.S. I love the library and the work you're doing here. I hope you guys are able to find a way to allow async-await with done without breaking changes elsewhere. In the meantime, I'm fixing myself to Mocha 2.5.3 which supports using them together. If it helps, I'm using |
@bitsoflogic At #1320 (comment) I suggest checking for both Promise fulfillment and 'done' execution if both are 'requested'. |
with v2.x the behavior is unexpected w/r/t A compromise would be to, if a The difference between this behavior and 2.x is that if you use both, the Thoughts? Would this work for everyone? |
Hmm, that sounds like the 'waiting for both' I'm suggesting. I'd add reporting whether the Error came from the Promise or from 'done'.
|
It sounds like you're both describing the same thing. I'm fine with that solution, although I think this would be best if we keep both the non-Promise and Promise
or, keep them the same this way:
|
@bitsoflogic I'm not sure I quite understand your examples. Can you be more explicit (where are But anyway, it does sound like we're talking about the same thing. I could implement this, but I'm not sure when that would happen. So if someone wants to beat me to it, I'll create a new issue. |
Sounds like a fun / cool thing to code.
|
@boneskull The way I ended up reading these threads was through https://github.com/mochajs/mocha/wiki/Spies I thought the latter method (using done in EventEmitter callback) seemed very nifty, and got that perplexing error. Reason is my function is async and I do await-stuff in it; in other words, my test is multi-step async stuff, AND I'd like to resolve it by done-ing upon emitted event. The way I'm going to do it now is to either just use the first suggested method ( |
This is what I got for #2407. It seems to work well, but I'm worried actually forcing async tests to be async is going to break some tests out there--especially amongst those using
--async-only
.Regardless of the above, I'm pretty sure what I've done here is "more correct."
I'm happy to pull that out, but the result is we cannot warn a user (or in fact do anything) about:
Yes, they returned a
Promise
, but it executes synchronously, so we can't inspect the return value of the test to even know it's aPromise
.cc @mochajs/core @elado @teckays @ScottFreeCode