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

All subsequent tests will be skipped if throw non Error #229

Open farwayer opened 1 year ago

farwayer commented 1 year ago

Thanks for the nice lib! Just started using it and found a bug:

test('example', () => new Promise((resolve, reject) => {
  reject()
})

test('example', () => new Promise((resolve, reject) => {
  reject("reason")
})

test('example', () => {
  throw "reason"
})

As result test fail will be silently ignored. The bug is here: format function expects that err is defined and is Error instance although this is not required.

farwayer commented 1 year ago

The problem is even more serious than I expected. All subsequent tests will be silently skipped. Even if the test itself worries about this problematic behavior, any third-party library that is used in the code can cause trouble and completely disable testing.

test('example', () => {
  externalLibFail()
})

test('example2', () => {
  throw new Error("It will never be called")
})

function externalLibFail() {
  throw "not an Error"
}
pashak09 commented 1 year ago

I have opened a PR to fix this issue.

https://github.com/lukeed/uvu/pull/240

e-rakovets32 commented 1 year ago

When are you going to merge it? I want this fix too. Thanks!

victordidenko commented 7 months ago

Just encountered this behavior after few years of using uvu, this is very unexpected and very unpleasant :(

I've looked through other issues and found out, that author knew about this behavior since 2021, but did nothing (not even changed documentation) — https://github.com/lukeed/uvu/issues/130#issuecomment-896377702