Hide internal stack traces
sz-piotr opened this issue · 2 comments
sz-piotr commented
Given the following tests
import { expect } from "earljs"
describe('example', () => {
it('regular failure', () => {
expect(123).toEqual(456)
})
it('async failure', async () => {
async function foo() {
throw new Error('bar')
}
await expect(foo()).toBeRejected('baz')
})
})
The output is:
1) example
regular failure:
AssertionError: 123 not equal to 456
Hint: value mismatch
+ expected - actual
-123
+456
at Control.assert (/home/piotr/Documents/projects/l2beat/node_modules/earljs/dist/Control.js:14:23)
at toEqual (/home/piotr/Documents/projects/l2beat/node_modules/earljs/dist/validators/toEqual.js:11:17)
at Expectation.toEqual (/home/piotr/Documents/projects/l2beat/node_modules/earljs/dist/Expectation.js:48:31)
at Context.<anonymous> (test/x.test.ts:5:17)
at processImmediate (internal/timers.js:464:21)
2) example
async failure:
AssertionError: Expected to be rejected with "[Error: baz]" but got "Error: bar"
Hint: error
at Control.assert (/home/piotr/Documents/projects/l2beat/node_modules/earljs/dist/Control.js:14:23)
at /home/piotr/Documents/projects/l2beat/node_modules/earljs/dist/validators/toBeRejected.js:38:21
at Generator.throw (<anonymous>)
at rejected (/home/piotr/Documents/projects/l2beat/node_modules/earljs/dist/validators/toBeRejected.js:6:65)
The output could be:
1) example
regular failure:
AssertionError: 123 not equal to 456
Hint: value mismatch
+ expected - actual
-123
+456
at Context.<anonymous> (test/x.test.ts:5:17)
at processImmediate (internal/timers.js:464:21)
2) example
async failure:
AssertionError: Expected to be rejected with "[Error: baz]" but got "Error: bar"
Hint: error
at Context.<anonymous> (test/x.test.ts:12:19)
at processImmediate (internal/timers.js:464:21)
This can be achieved by creating the error in the Control
constructor and removing node_modules/earljs
entries from the stack trace thereby preserving both the synchronous stack trace as well as removing internals.
krzkaczor commented