-
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
Added a flag (-R, --rejections) to make the test fail if an unhandled Promise rejection happened during its execution #658
Conversation
…p failing though)
… Promise rejection happened during its execution
Ouch. I've added tests to cover this feature in Do you have any suggestion on how to handle this? I thought about adding tests to |
|
||
RunCli(['test/cli_reject_promise/reject_promise.js', '-R'], (error, result) => { | ||
|
||
if (error) { |
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.
instead:
expect(error).to.not.exist();
@DanReyLop The naming looks good. For improving the code coverage, you are likely going to need to emit the rejection event manually on the |
@geek I've ended up adding a test to |
"posttest": "npm run lint-md", | ||
"test-cov-html": "./bin/_lab -fL -r html -m 3000 -o coverage.html", | ||
"lint": "./bin/_lab -d -f -L", | ||
"test-cov-html": "node ./bin/_lab -fL -r html -m 3000 -o coverage.html", |
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.
Is there a reason why this needed to change?
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.
Not directly related to this PR, but the previous command didn't work on Windows, because the #! /bin/node
trick obviously doesn't work on Windows.
Some tests keep failing on my Windows 10 machine, but with this change at least I can run them.
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. |
Fixes #649
I'm open to suggestions, specially about naming.
All the relevant discussion is on the #649 issue. To sum up, I've added a flag to Lab, called
--rejections
(alias-R
). If that flag is set, and an unhandled Promise rejection happens during a test, that test will be failed.Without this flag, the behaviour will be exactly the same as before: The test pass, and in versions of Node.JS
6.6.0+
, a warning is printed on the console (but the test still passes).An unhandled Promise rejection looks like this:
Initially, the behaviour of unhandled rejections was to be silenced and totally ignored, by design. It looks like everyone is changing their minds, because in the latest versions of Chrome and Node.JS (maybe more engines, I don't know more examples) the unhandled rejections have started to display console warnings. In 99% an unhandled rejection means that something is terribly bad with the code, and the fact that doesn't crash the entire process is just a questionable design choice. So I think it should definitely make a test fail.