lukeed / uvu

uvu is an extremely fast and lightweight test runner for Node.js and the browser
MIT License
2.98k stars 99 forks source link

Throwing from test.after.each() makes otherwise failing test pass #201

Open aral opened 2 years ago

aral commented 2 years ago

So this had me scratching my head for a while today.

The following fails as expected:

import { test } from 'uvu'

function ouch () {
  throw new Error('Oops!')
}

test('two wrongs do not make a right', async (context) => {
  ouch()
})

test.run()

Result:

❯ node index.mjs

✘   (0 / 1)

   FAIL  "two wrongs do not make a right"
    Oops!

    at ouch (file:///home/aral/sandbox/uvu-test/index.mjs:4:9)
    at Object.handler (file:///home/aral/sandbox/uvu-test/index.mjs:12:3)
    at Number.runner (file:///home/aral/sandbox/uvu-test/node_modules/uvu/dist/index.mjs:77:16)
    at Timeout.exec [as _onTimeout] (file:///home/aral/sandbox/uvu-test/node_modules/uvu/dist/index.mjs:138:39)

  Total:     1
  Passed:    0
  Skipped:   0
  Duration:  1.60ms

However, if you add an after.each() method that itself throws, the test run doesn’t fail (exits with a success status and without showing the error):

import { test } from 'uvu'

function ouch () {
  throw new Error('Oops!')
}

test.after.each(() => {
  throw new Error('The sky is falling.')
})

test('two wrongs do not make a right', async (context) => {
  ouch()
})

test.run()

Result:

❯ node index.mjs

  (0 / 1)

  Total:     1
  Passed:    0
  Skipped:   0
  Duration:  1.03ms
jmcdo29 commented 2 years ago

I think to an extent this may be related to #191. I can probably update my PR for that to include a fix for this too. Looks like the error isn't being properly reported