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
Fix a number of causes of unhandled rejections (and ensure tests fail when unhandled rejection occurs). #9070
Conversation
7fbcdeb
to
2677785
Compare
260eb6f
to
1da58bc
Compare
1da58bc
to
d564247
Compare
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.
LGTM
let tmp = warning.line.split(':'); | ||
let file = tmp[0].trim(); | ||
let line = tmp[1]; |
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.
Seems like a good place to destructure, and I'm looking for a chance to make a multi-line suggestion
let tmp = warning.line.split(':'); | |
let file = tmp[0].trim(); | |
let line = tmp[1]; | |
let [file, line] = warning.line.split(':').map(item => item.trim()); |
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.
Ya, that's a fine suggestion. But in general I try to avoid cosmetic cleanup in bug-fixes.
} catch (e) { | ||
expect(e.message).to.include(`Livereload failed on 'http://localhost:1337', It may be in use.`); | ||
} finally { | ||
await new Promise(resolve => preexistingServer.close(resolve)); |
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.
I'm curious about whether there's there a reason you're not using Promise.resolve
here?
await new Promise(resolve => preexistingServer.close(resolve)); | |
await Promise.resolve(preexistingServer.close(resolve)); |
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.
We need a promise that fulfills only when the callback passed to prexistingServer.close
is invoked.
Unfortunately the return value of preexistingServer.close
is not meaningful when it comes to the above mentioned goal as preexistingServer.close(cb) === preexistingServer
which when awaited fulfills on the next tick, regardless if the server has closed or not.
Two other reason to not take the alternative approach:
await Promise.resolve(value)
can be safely reduced toawait value
assumingPromise
is the platform provided promise, which in this case it is. So if the return value ofpreexistingServer.close
was meaningful, we would only need toawait
it.- the
resolve
argument passed toclose
is not defined, and will trigger a thrownReferenceError
.
prep work to address #9007