Description
- Version: v10.18.1, v13.5.0
- Platform: macOS v10.15.2 (19.2.0 Darwin Kernel Version 19.2.0: Sat Nov 9 03:47:04 PST 2019; root:xnu-6153.61.1~20/RELEASE_X86_64 x86_64)
- Subsystem: ?
Using await
on a Promise
that never resolves or rejects behaves very strangely. I would expect it to simply hang, indefinitely awaiting the promise.
What actually happens is that the rest of the script outside the async function carries on normally, and the process exits fast and without an error.
// demo.js
const promise = new Promise(() => {})
async function demo1() {
await promise
console.log('This never logs.')
}
async function demo2() {
await require('assert').rejects(promise)
}
demo1()
demo2()
console.log('This logs.')
Result:
It's concerning that in the case of demo 2, a test could in a way be skipped at the point of a rejects
assertion, without any exception or warning even though the promise never actually rejected.
I would prefer await
on a promise that never resolves or rejects hangs indefinitely, that way when testing locally you can tell something is wrong, and CI can timeout and exit with an error.
Tweet thread: https://twitter.com/jaydenseric/status/1217964277727809536