Browse Source

Update tests to handle unresolved promises

1122-buz-zinga
Clement Denis 2 years ago
parent
commit
d8ec885b25
  1. 11
      js/tests/test.mjs

11
js/tests/test.mjs

@ -163,14 +163,23 @@ const runTests = async ({ url, path, code }) => {
const tools = { eq, fail, wait, code, path, randStr, between, upperFirst }
tools.ctx = (await (setup && setup(tools))) || {}
let timeout
for (const [i, t] of tests.entries()) {
try {
if (!(await t(tools))) {
const waitWithTimeout = Promise.race([
t(tools),
new Promise((s, f) => {
timeout = setTimeout(f, 60000, Error('Time limit reached (1min)'))
}),
])
if (!(await waitWithTimeout)) {
throw Error('Test failed')
}
} catch (err) {
console.log(`test #${i+1} failed:\n${t.toString()}\n\nError:`)
fatal(stackFmt(err, url))
} finally {
clearTimeout(timeout)
}
}
console.log(`${name} passed (${tests.length} tests)`)

Loading…
Cancel
Save