-
Notifications
You must be signed in to change notification settings - Fork 176
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
Make the test fail on a Promise unhandled rejection #649
Comments
@DanReyLop I like the idea, but I don't want to break applications that already have an An alternative is for anyone using promises to add process.on('unhandledRejection', (reason, promise) => {
console.error(reason);
throw reason;
}); Honestly, my bigger concern is that once we add this change people will start opening issues in lab saying that it broke their promises since we will be throwing when people don't handle rejections. |
Good point. I've yet to see any of those applications in the wild, but they may exist :)
The problem with the warning is that it's very easy to miss. In a
I understand that this, if implemented, would be a
I thought about something like that, but it would need to be included (directly or through a |
What about a command line flag to enable or disable this functionality? Or an option on an experiment or test? By default it could be turned off. If this was the case then we would skip the needless requirement of a major semver as it would only be turned on when the user has specifically requested it, it would not cause issues from users saying that it broke their tests. |
By the way, it sounds like a great idea to me. |
Sound reasonable. An option per experiment/test kinda defeats the purpose of this, but a global flag seems like the best approach to not break anything and still be useful. I'll hack something together on the next few days :) |
@DanReyLop @blacksun1 a global flag sounds good to me, I am definitely happy to add that change. |
This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions. |
We've recently migrated from NodeJS
4.x.x
to6.7.0
and we found that in some cases our Promise-based code was failing silently. In recent versions of NodeJS, when a Promise is rejected but it doesn't have a.catch()
handler, a warning is emitted in the console. But that warning was the only way to notice it, and it was easy to overlook, because the tests didn't fail.I propose that
lab
subscribes to theprocess.on('unhandledRejection')
event (documented here, available since NodeJS1.4.1
) and make the test fail if any Promise was rejected and not handled.Even though what I propose is a breaking change, I think it's worth going that way. 99% of time, if your code under test has a Promise being rejected and fail silently, there's something wrong with that code that ought to be fixed.
Any opinions on this? I'll be happy to make a PR, but I want to have an idea beforehand that the solution isn't gonna be rejected completely :)
The text was updated successfully, but these errors were encountered: