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

Support for printing error causes #234

Open dwoznicki opened 1 year ago

dwoznicki commented 1 year ago

This PR adds support for printing error cause. Causes appear as part of the stack trace, and are checked recursively. For example, the following snippet

const {test} = require("uvu");

test("error cause", () => {
    throw new Error("top level", {cause: new Error("mid level", {cause: new Error("bottom level")})});
});
test.run();

produces the following output

✘   (0 / 1)

   FAIL  "error cause"
    top level

    at Object.handler (/home/danwoz/testo/test/t.js:4:11)
    at Number.runner (/home/danwoz/testo/node_modules/uvu/dist/index.js:88:16)
    at Timeout.exec [as _onTimeout] (/home/danwoz/testo/node_modules/uvu/dist/index.js:151:39)

    Caused by: mid level
    at Object.handler (/home/danwoz/testo/test/t.js:4:42)
    at Number.runner (/home/danwoz/testo/node_modules/uvu/dist/index.js:88:16)
    at Timeout.exec [as _onTimeout] (/home/danwoz/testo/node_modules/uvu/dist/index.js:151:39)

    Caused by: bottom level
    at Object.handler (/home/danwoz/testo/test/t.js:4:73)
    at Number.runner (/home/danwoz/testo/node_modules/uvu/dist/index.js:88:16)
    at Timeout.exec [as _onTimeout] (/home/danwoz/testo/node_modules/uvu/dist/index.js:151:39)

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

Fixes #233