-
Notifications
You must be signed in to change notification settings - Fork 784
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
Allow assert.async callback to "wrap" actual async callback and handle errors? #816
Comments
Thanks for the input, @platinumazure! (And on a personal note: Hi, Kevin! Hope all is well. 👋) My thoughts: For example: var syncCallbackInvokedAsynchronously = function() {
// This will be caught. YAY! =D
throw new Error();
};
QUnit.test("Working wrapping an error callback - USEFUL!", function (assert) {
var done = assert.async();
setTimeout(
done.wrapError(syncCallbackInvokedAsynchronously),
50
);
});
var asyncCallbackInvokedAsynchronously = function() {
setTimeout(
function() {
// This will not be caught... BOO-HISS! =(
throw new Error();
},
50
);
};
QUnit.test("Non-working wrapping an error callback - USELESS!", function (assert) {
var done = assert.async();
setTimeout(
done.wrapError(asyncCallbackInvokedAsynchronously),
50
);
}); The only way I know of to track that type of flow is to duck-punch all of the core asynchronous functions ( To date, QUnit has not yet gone down the path of duck-punching any core Web Platform functions in such a manner, so we will definitely need to discuss further. |
I definitely agree that QUnit should not go down the path of stubbing out My thoughts are as follows:
It's probably worth clarifying that the only issue I'm really trying to Am I not understanding your point fully? If I'm missing something, please
|
And now I'm on the website, your code sample renders... My basic points are unchanged: the second case is converted either by multiple I just want to make the common stuff, within a test, easy (I.e., setTimeout or require embedded in a test itself). I don't want to turn QUnit into a stub library. |
I'm -1 on this. |
@scottgonzalez Would love to hear why. |
It's awkward and potentially misleading. |
@scottgonzalez Well, I can understand that the proposed API needs some work. Are you in favor of the concept, at least (that is, shoring up an inconsistency in exception handling between synchronous, promise, and asynchronous test code)? |
I'm not in favor of the concept. |
That's something we should address, but not with the suggested solution. |
I've no doubt there is a better approach out there somewhere. If you have an idea how it should be done, let me know what you're thinking and I'm happy to write up a pull request to get things started. Thanks! |
For a start, could you do a PR that modifies one of the existing test page and makes the runner halt? Preferably with a scenario that is likely to occur in practice. |
Sure. Should the target branch be anything besides master? |
master is fine. |
@platinumazure I guess this is also something that fell out of sight? Would be great if you could still put together the failure case we discussed above. |
Yeah, I've been trying to think of one besides my RequireJS case with no
|
Okay, thanks. Let us know either way. |
@platinumazure what's the current status on this one? We did some changes on our RequireJS since last year and that might be slightly better to handle now. |
@leobalter No meaningful updates at this time. This has become less of an issue for us since we were able to use require.in error to trap most errors. I still think this could be useful in general but I haven't had the time to fulfill your (reasonable) requirements around proving that this is a real issue. If you like, you can close this and I can reopen when I have something to add to the discussion. Sound good? |
Closing, as global error handlers can now invoke |
It would be really excellent if there was an easy way to have inadvertent exceptions from async callbacks be noted in an assertion and the test runner restarted, much like what is already done in the synchronous and promise pathways. (As it is, the test runner chokes completely in these cases because
QUnit.start()
, or equivalent, is not called.)What I would like to see is something similar for when an asynchronous callback throws an error and the async callback doesn't have anything QUnit on its call stack.
I think this could be implemented with a generic callback-wrapping function that basically has a try/catch in it and handles errors in a similar way as the two sections of code I've outlined above. I'll write up a pull request in the next few days to outline what I'm getting at, but here's a very rough API:
Usage:
One could easily envision a similar API which would just invoke the
done()
callback on success or error, allowing consumers to avoid invokingdone()
in the callback itself. (I don't think there's a huge loss of readability either, sincedone
is still mentioned in the function wrap invocation. It's just a matter of choosing an intelligent function name to complement or replacewrapError
.)Any thoughts?
The text was updated successfully, but these errors were encountered: