|
1 | 1 | import { expect } from 'chai'; |
2 | 2 | import { stub } from 'sinon'; |
| 3 | +import { BrowserBackend } from '../../src/backend'; |
3 | 4 | import { LinkedErrors } from '../../src/integrations/linkederrors'; |
4 | 5 |
|
5 | 6 | let linkedErrors: LinkedErrors; |
@@ -52,67 +53,66 @@ describe('LinkedErrors', () => { |
52 | 53 | expect(spy.calledOnce).equal(true); |
53 | 54 | }); |
54 | 55 |
|
55 | | - it('should recursively walk error to find linked exceptions and assign them to the event', () => { |
56 | | - const event = { |
57 | | - exception: { |
58 | | - values: [], |
59 | | - }, |
60 | | - message: 'foo', |
61 | | - }; |
| 56 | + it('should recursively walk error to find linked exceptions and assign them to the event', async () => { |
| 57 | + const three: ExtendedError = new SyntaxError('three'); |
62 | 58 |
|
63 | | - const one: ExtendedError = new Error('one'); |
64 | 59 | const two: ExtendedError = new TypeError('two'); |
65 | | - const three: ExtendedError = new SyntaxError('three'); |
| 60 | + two.cause = three; |
66 | 61 |
|
67 | | - const originalException = one; |
| 62 | + const one: ExtendedError = new Error('one'); |
68 | 63 | one.cause = two; |
69 | | - two.cause = three; |
70 | 64 |
|
| 65 | + const originalException = one; |
| 66 | + const backend = new BrowserBackend({}); |
| 67 | + const event = await backend.eventFromException(originalException); |
71 | 68 | const result = linkedErrors.handler(event, { |
72 | 69 | originalException, |
73 | 70 | }); |
74 | 71 |
|
75 | 72 | // It shouldn't include root exception, as it's already processed in the event by the main error handler |
76 | | - expect(result!.exception!.values!.length).equal(2); |
77 | | - expect(result!.exception!.values![0].type).equal('TypeError'); |
78 | | - expect(result!.exception!.values![0].value).equal('two'); |
| 73 | + expect(result!.exception!.values!.length).equal(3); |
| 74 | + expect(result!.exception!.values![0].type).equal('Error'); |
| 75 | + expect(result!.exception!.values![0].value).equal('one'); |
79 | 76 | expect(result!.exception!.values![0].stacktrace).to.have.property('frames'); |
80 | | - expect(result!.exception!.values![1].type).equal('SyntaxError'); |
81 | | - expect(result!.exception!.values![1].value).equal('three'); |
| 77 | + expect(result!.exception!.values![1].type).equal('TypeError'); |
| 78 | + expect(result!.exception!.values![1].value).equal('two'); |
82 | 79 | expect(result!.exception!.values![1].stacktrace).to.have.property('frames'); |
| 80 | + expect(result!.exception!.values![2].type).equal('SyntaxError'); |
| 81 | + expect(result!.exception!.values![2].value).equal('three'); |
| 82 | + expect(result!.exception!.values![2].stacktrace).to.have.property('frames'); |
83 | 83 | }); |
84 | 84 |
|
85 | | - it('should allow to change walk key', () => { |
| 85 | + it('should allow to change walk key', async () => { |
86 | 86 | linkedErrors = new LinkedErrors({ |
87 | 87 | key: 'reason', |
88 | 88 | }); |
89 | | - const event = { |
90 | | - exception: { |
91 | | - values: [], |
92 | | - }, |
93 | | - message: 'foo', |
94 | | - }; |
95 | 89 |
|
96 | | - const one: ExtendedError = new Error('one'); |
97 | | - const two: ExtendedError = new TypeError('two'); |
98 | 90 | const three: ExtendedError = new SyntaxError('three'); |
99 | 91 |
|
100 | | - const originalException = one; |
101 | | - one.reason = two; |
| 92 | + const two: ExtendedError = new TypeError('two'); |
102 | 93 | two.reason = three; |
103 | 94 |
|
| 95 | + const one: ExtendedError = new Error('one'); |
| 96 | + one.reason = two; |
| 97 | + |
| 98 | + const originalException = one; |
| 99 | + const backend = new BrowserBackend({}); |
| 100 | + const event = await backend.eventFromException(originalException); |
104 | 101 | const result = linkedErrors.handler(event, { |
105 | 102 | originalException, |
106 | 103 | }); |
107 | 104 |
|
108 | 105 | // It shouldn't include root exception, as it's already processed in the event by the main error handler |
109 | | - expect(result!.exception!.values!.length).equal(2); |
110 | | - expect(result!.exception!.values![0].type).equal('TypeError'); |
111 | | - expect(result!.exception!.values![0].value).equal('two'); |
| 106 | + expect(result!.exception!.values!.length).equal(3); |
| 107 | + expect(result!.exception!.values![0].type).equal('Error'); |
| 108 | + expect(result!.exception!.values![0].value).equal('one'); |
112 | 109 | expect(result!.exception!.values![0].stacktrace).to.have.property('frames'); |
113 | | - expect(result!.exception!.values![1].type).equal('SyntaxError'); |
114 | | - expect(result!.exception!.values![1].value).equal('three'); |
| 110 | + expect(result!.exception!.values![1].type).equal('TypeError'); |
| 111 | + expect(result!.exception!.values![1].value).equal('two'); |
115 | 112 | expect(result!.exception!.values![1].stacktrace).to.have.property('frames'); |
| 113 | + expect(result!.exception!.values![2].type).equal('SyntaxError'); |
| 114 | + expect(result!.exception!.values![2].value).equal('three'); |
| 115 | + expect(result!.exception!.values![2].stacktrace).to.have.property('frames'); |
116 | 116 | }); |
117 | 117 | }); |
118 | 118 | }); |
0 commit comments