1+ import { NodeBackend } from '../../src' ;
12import { LinkedErrors } from '../../src/integrations/linkederrors' ;
23
34let linkedErrors : LinkedErrors ;
@@ -24,12 +25,9 @@ describe('LinkedErrors', () => {
2425
2526 it ( 'should bail out if event contains exception, but no hint' , async ( ) => {
2627 const spy = jest . spyOn ( linkedErrors , 'walkErrorTree' ) ;
27- const event = {
28- exception : {
29- values : [ ] ,
30- } ,
31- message : 'foo' ,
32- } ;
28+ const one = new Error ( 'originalException' ) ;
29+ const backend = new NodeBackend ( { } ) ;
30+ const event = await backend . eventFromException ( one ) ;
3331 const result = await linkedErrors . handler ( event ) ;
3432 expect ( spy . mock . calls . length ) . toEqual ( 0 ) ;
3533 expect ( result ) . toEqual ( event ) ;
@@ -42,79 +40,92 @@ describe('LinkedErrors', () => {
4240 resolve ( [ ] ) ;
4341 } ) ,
4442 ) ;
45- const event = {
46- exception : {
47- values : [ ] ,
48- } ,
49- message : 'foo' ,
50- } ;
51- const hint = {
52- originalException : new Error ( 'originalException' ) ,
53- } ;
54- await linkedErrors . handler ( event , hint ) ;
43+ const one = new Error ( 'originalException' ) ;
44+ const backend = new NodeBackend ( { } ) ;
45+ const event = await backend . eventFromException ( one ) ;
46+ await linkedErrors . handler ( event , {
47+ originalException : one ,
48+ } ) ;
5549 expect ( spy . mock . calls . length ) . toEqual ( 1 ) ;
5650 } ) ;
5751
5852 it ( 'should recursively walk error to find linked exceptions and assign them to the event' , async ( ) => {
59- const event = {
60- exception : {
61- values : [ ] ,
62- } ,
63- message : 'foo' ,
64- } ;
65-
6653 const one : ExtendedError = new Error ( 'one' ) ;
6754 const two : ExtendedError = new TypeError ( 'two' ) ;
6855 const three : ExtendedError = new SyntaxError ( 'three' ) ;
69-
70- const originalException = one ;
7156 one . cause = two ;
7257 two . cause = three ;
7358
59+ const backend = new NodeBackend ( { } ) ;
60+ const event = await backend . eventFromException ( one ) ;
7461 const result = await linkedErrors . handler ( event , {
75- originalException,
62+ originalException : one ,
7663 } ) ;
7764
78- // It shouldn't include root exception, as it's already processed in the event by the main error handler
79- expect ( result ! . exception ! . values ! . length ) . toEqual ( 2 ) ;
80- expect ( result ! . exception ! . values ! [ 0 ] . type ) . toEqual ( 'TypeError' ) ;
81- expect ( result ! . exception ! . values ! [ 0 ] . value ) . toEqual ( 'two' ) ;
65+ expect ( result ! . exception ! . values ! . length ) . toEqual ( 3 ) ;
66+ expect ( result ! . exception ! . values ! [ 0 ] . type ) . toEqual ( 'SyntaxError' ) ;
67+ expect ( result ! . exception ! . values ! [ 0 ] . value ) . toEqual ( 'three' ) ;
8268 expect ( result ! . exception ! . values ! [ 0 ] . stacktrace ) . toHaveProperty ( 'frames' ) ;
83- expect ( result ! . exception ! . values ! [ 1 ] . type ) . toEqual ( 'SyntaxError ' ) ;
84- expect ( result ! . exception ! . values ! [ 1 ] . value ) . toEqual ( 'three ' ) ;
69+ expect ( result ! . exception ! . values ! [ 1 ] . type ) . toEqual ( 'TypeError ' ) ;
70+ expect ( result ! . exception ! . values ! [ 1 ] . value ) . toEqual ( 'two ' ) ;
8571 expect ( result ! . exception ! . values ! [ 1 ] . stacktrace ) . toHaveProperty ( 'frames' ) ;
72+ expect ( result ! . exception ! . values ! [ 2 ] . type ) . toEqual ( 'Error' ) ;
73+ expect ( result ! . exception ! . values ! [ 2 ] . value ) . toEqual ( 'one' ) ;
74+ expect ( result ! . exception ! . values ! [ 2 ] . stacktrace ) . toHaveProperty ( 'frames' ) ;
8675 } ) ;
8776
8877 it ( 'should allow to change walk key' , async ( ) => {
8978 linkedErrors = new LinkedErrors ( {
9079 key : 'reason' ,
9180 } ) ;
92- const event = {
93- exception : {
94- values : [ ] ,
95- } ,
96- message : 'foo' ,
97- } ;
9881
9982 const one : ExtendedError = new Error ( 'one' ) ;
10083 const two : ExtendedError = new TypeError ( 'two' ) ;
10184 const three : ExtendedError = new SyntaxError ( 'three' ) ;
102-
103- const originalException = one ;
10485 one . reason = two ;
10586 two . reason = three ;
10687
88+ const backend = new NodeBackend ( { } ) ;
89+ const event = await backend . eventFromException ( one ) ;
90+ const result = await linkedErrors . handler ( event , {
91+ originalException : one ,
92+ } ) ;
93+
94+ expect ( result ! . exception ! . values ! . length ) . toEqual ( 3 ) ;
95+ expect ( result ! . exception ! . values ! [ 0 ] . type ) . toEqual ( 'SyntaxError' ) ;
96+ expect ( result ! . exception ! . values ! [ 0 ] . value ) . toEqual ( 'three' ) ;
97+ expect ( result ! . exception ! . values ! [ 0 ] . stacktrace ) . toHaveProperty ( 'frames' ) ;
98+ expect ( result ! . exception ! . values ! [ 1 ] . type ) . toEqual ( 'TypeError' ) ;
99+ expect ( result ! . exception ! . values ! [ 1 ] . value ) . toEqual ( 'two' ) ;
100+ expect ( result ! . exception ! . values ! [ 1 ] . stacktrace ) . toHaveProperty ( 'frames' ) ;
101+ expect ( result ! . exception ! . values ! [ 2 ] . type ) . toEqual ( 'Error' ) ;
102+ expect ( result ! . exception ! . values ! [ 2 ] . value ) . toEqual ( 'one' ) ;
103+ expect ( result ! . exception ! . values ! [ 2 ] . stacktrace ) . toHaveProperty ( 'frames' ) ;
104+ } ) ;
105+
106+ it ( 'should allow to change stack size limit' , async ( ) => {
107+ linkedErrors = new LinkedErrors ( {
108+ limit : 2 ,
109+ } ) ;
110+
111+ const one : ExtendedError = new Error ( 'one' ) ;
112+ const two : ExtendedError = new TypeError ( 'two' ) ;
113+ const three : ExtendedError = new SyntaxError ( 'three' ) ;
114+ one . cause = two ;
115+ two . cause = three ;
116+
117+ const backend = new NodeBackend ( { } ) ;
118+ const event = await backend . eventFromException ( one ) ;
107119 const result = await linkedErrors . handler ( event , {
108- originalException,
120+ originalException : one ,
109121 } ) ;
110122
111- // It shouldn't include root exception, as it's already processed in the event by the main error handler
112123 expect ( result ! . exception ! . values ! . length ) . toEqual ( 2 ) ;
113124 expect ( result ! . exception ! . values ! [ 0 ] . type ) . toEqual ( 'TypeError' ) ;
114125 expect ( result ! . exception ! . values ! [ 0 ] . value ) . toEqual ( 'two' ) ;
115126 expect ( result ! . exception ! . values ! [ 0 ] . stacktrace ) . toHaveProperty ( 'frames' ) ;
116- expect ( result ! . exception ! . values ! [ 1 ] . type ) . toEqual ( 'SyntaxError ' ) ;
117- expect ( result ! . exception ! . values ! [ 1 ] . value ) . toEqual ( 'three ' ) ;
127+ expect ( result ! . exception ! . values ! [ 1 ] . type ) . toEqual ( 'Error ' ) ;
128+ expect ( result ! . exception ! . values ! [ 1 ] . value ) . toEqual ( 'one ' ) ;
118129 expect ( result ! . exception ! . values ! [ 1 ] . stacktrace ) . toHaveProperty ( 'frames' ) ;
119130 } ) ;
120131 } ) ;
0 commit comments