@@ -250,6 +250,38 @@ describe('Logger', () => {
250250    expect ( logArguments . http . response . body . content ) . to . eql ( JSON . stringify ( error . response ?. data ) ) ; 
251251  } ) ; 
252252
253+   it ( 'should log causes' ,  ( )  =>  { 
254+     const  rootCause  =  new  Error ( 'Root cause error' ) ; 
255+     rootCause . name  =  'RootCauseError' ; 
256+     rootCause . stack  =  'RootCauseError: Root cause error\n    at rootFunction()' ; 
257+ 
258+     const  intermediateError  =  new  Error ( 'Intermediate error' ) ; 
259+     intermediateError . name  =  'IntermediateError' ; 
260+     intermediateError . stack  =  'IntermediateError: Intermediate error\n    at intermediateFunction()' ; 
261+     intermediateError . cause  =  rootCause ; 
262+ 
263+     const  mainError  =  new  Error ( 'Main error occurred' ) ; 
264+     mainError . name  =  'MainError' ; 
265+     mainError . stack  =  'MainError: Main error occurred\n    at mainFunction()' ; 
266+     mainError . cause  =  intermediateError ; 
267+ 
268+     logger . fromError ( 'test_action' ,  mainError ,  {  details : 'test details'  } ) ; 
269+ 
270+     const  logArguments  =  JSON . parse ( outputStub . args [ 0 ] [ 0 ] ) ; 
271+     expect ( logArguments . error . type ) . to . eql ( 'MainError' ) ; 
272+     expect ( logArguments . error . message ) . to . eql ( 'Main error occurred' ) ; 
273+     expect ( logArguments . error . cause ) . to . eql ( { 
274+       type : 'IntermediateError' , 
275+       message : 'Intermediate error' , 
276+       stack_trace : intermediateError . stack , 
277+       cause : { 
278+         type : 'RootCauseError' , 
279+         message : 'Root cause error' , 
280+         stack_trace : rootCause . stack , 
281+       } , 
282+     } ) ; 
283+   } ) ; 
284+ 
253285  describe ( '#customError' ,  ( )  =>  { 
254286    it ( 'should log error as the given severity with action' ,  ( )  =>  { 
255287      const  error : Error  &  {  data ?: any  }  =  new  Error ( 'failed' ) ; 
0 commit comments