1- import { trace } from './traceDecorator ' ;
1+ import { trace } from './trace.decorator ' ;
22
33describe ( 'trace decorator' , ( ) => {
44 const executionTraceExpectation = {
@@ -21,15 +21,15 @@ describe('trace decorator', () => {
2121 } ;
2222
2323 describe ( 'Tracing synchronous functions' , ( ) => {
24- const traceHandlerMock = jest . fn ( ) ;
25- const traceHandlerMockThrows = jest . fn ( ) ;
24+ const onTraceEventMock = jest . fn ( ) ;
25+ const onTraceEventMockThrows = jest . fn ( ) ;
2626
2727 class SyncClass {
2828 greetingFrom = [ 'hello from class' ] ;
2929
3030 @trace ( function ( ...args ) {
3131 this . greetingFrom . push ( 'hello from trace handler' ) ;
32- traceHandlerMock ( ...args ) ;
32+ onTraceEventMock ( ...args ) ;
3333 expect ( this . greetingFrom ) . toEqual ( [ 'hello from class' , 'hello from method' , 'hello from trace handler' ] ) ;
3434 } )
3535 helloWorld ( ) : string {
@@ -38,7 +38,7 @@ describe('trace decorator', () => {
3838 }
3939
4040 @trace ( ( ...args ) => {
41- traceHandlerMockThrows ( ...args ) ;
41+ onTraceEventMockThrows ( ...args ) ;
4242 throw new Error ( 'hello but I throw!' ) ;
4343 } )
4444 helloWorldHandlerThrows ( ) : string {
@@ -50,8 +50,8 @@ describe('trace decorator', () => {
5050 it ( 'should trace a synchronous function and verify context' , ( ) => {
5151 const instance = new SyncClass ( ) ;
5252 expect ( instance . helloWorld ( ) ) . toBe ( 'Hello World' ) ;
53- expect ( traceHandlerMock ) . toHaveBeenCalledTimes ( 1 ) ;
54- expect ( traceHandlerMock ) . toHaveBeenCalledWith (
53+ expect ( onTraceEventMock ) . toHaveBeenCalledTimes ( 1 ) ;
54+ expect ( onTraceEventMock ) . toHaveBeenCalledWith (
5555 expect . objectContaining ( {
5656 metadata : expect . objectContaining ( {
5757 class : 'SyncClass' ,
@@ -69,8 +69,8 @@ describe('trace decorator', () => {
6969 it ( 'should trace a synchronous function and verify helloWorldHandlerThrows' , ( ) => {
7070 const instance = new SyncClass ( ) ;
7171 expect ( ( ) => instance . helloWorldHandlerThrows ( ) ) . toThrowError ( 'hello but I throw!' ) ;
72- expect ( traceHandlerMockThrows ) . toHaveBeenCalledTimes ( 1 ) ;
73- expect ( traceHandlerMockThrows ) . toHaveBeenCalledWith (
72+ expect ( onTraceEventMockThrows ) . toHaveBeenCalledTimes ( 1 ) ;
73+ expect ( onTraceEventMockThrows ) . toHaveBeenCalledWith (
7474 expect . objectContaining ( {
7575 metadata : expect . objectContaining ( {
7676 class : 'SyncClass' ,
@@ -124,11 +124,11 @@ describe('trace decorator', () => {
124124 } ) ;
125125 } ) ;
126126
127- describe ( 'Tracing function traceHandlerMock and traceContext' , ( ) => {
127+ describe ( 'Tracing function onTraceEventMock and traceContext' , ( ) => {
128128 const traceContextDivision = { context : { metadata : { requestId : '12345' } } } ;
129129 const traceContextFetchData = { context : { metadata : { requestId : '6789' } } } ;
130- const traceHandlerDivisionMock = jest . fn ( ) ;
131- const traceHandlerFetchDataMock = jest . fn ( ) ;
130+ const onTraceEventDivisionMock = jest . fn ( ) ;
131+ const onTraceEventFetchDataMock = jest . fn ( ) ;
132132
133133 function empty ( ) : MethodDecorator {
134134 return function ( target : unknown , propertyKey : string , descriptor : PropertyDescriptor ) {
@@ -140,7 +140,7 @@ describe('trace decorator', () => {
140140 }
141141
142142 class MyClass {
143- @trace ( traceHandlerDivisionMock , traceContextDivision , { contextKey : '__execution' } )
143+ @trace ( onTraceEventDivisionMock , traceContextDivision , { contextKey : '__execution' } )
144144 divisionFunction ( x : number , y : number , traceContext : Record < string , unknown > = { } ) : number {
145145 if ( y === 0 ) {
146146 traceContext [ 'narratives' ] = [ `Throwing because division of ${ x } by ${ y } ` ] ;
@@ -150,7 +150,7 @@ describe('trace decorator', () => {
150150 return x / y ;
151151 }
152152
153- @trace ( traceHandlerFetchDataMock , traceContextFetchData , { contextKey : '__execution' } )
153+ @trace ( onTraceEventFetchDataMock , traceContextFetchData , { contextKey : '__execution' } )
154154 async fetchDataFunction ( url : string , traceContext : Record < string , unknown > = { } ) : Promise < { data : string } > {
155155 traceContext [ 'narratives' ] = [ `Fetching data from ${ url } ` ] ;
156156 if ( ! url . startsWith ( 'http' ) ) {
@@ -160,24 +160,24 @@ describe('trace decorator', () => {
160160 return { data : 'Success' } ;
161161 }
162162
163- @trace ( traceHandlerDivisionMock , traceContextDivision )
163+ @trace ( onTraceEventDivisionMock , traceContextDivision )
164164 @empty ( )
165165 divisionFunctionOnAnotherDecorator ( x : number , y : number , traceContext : Record < string , unknown > = { } ) : number {
166166 return this . divisionFunction ( x , y , traceContext ) ;
167167 }
168168
169- @trace ( traceHandlerFetchDataMock , traceContextFetchData )
169+ @trace ( onTraceEventFetchDataMock , traceContextFetchData )
170170 @empty ( )
171171 async fetchDataFunctionOnAnotherDecorator (
172172 url : string ,
173173 traceContext : Record < string , unknown > = { }
174174 ) : Promise < {
175- data : string ;
176- } > {
175+ data : string ;
176+ } > {
177177 return this . fetchDataFunction ( url , traceContext ) ;
178178 }
179179
180- @trace ( traceHandlerFetchDataMock , traceContextFetchData , { errorStrategy : 'catch' } )
180+ @trace ( onTraceEventFetchDataMock , traceContextFetchData , { errorStrategy : 'catch' } )
181181 @empty ( )
182182 async fetchDataFunctionOnAnotherDecoratorCoughtError (
183183 url : string ,
@@ -188,14 +188,14 @@ describe('trace decorator', () => {
188188 }
189189
190190 beforeEach ( ( ) => {
191- traceHandlerFetchDataMock . mockClear ( ) ;
192- traceHandlerDivisionMock . mockClear ( ) ;
191+ onTraceEventFetchDataMock . mockClear ( ) ;
192+ onTraceEventDivisionMock . mockClear ( ) ;
193193 } ) ;
194194
195- it ( 'should sync trace successfully and pass correct traceHandlerMock and traceContext' , ( ) => {
195+ it ( 'should sync trace successfully and pass correct onTraceEventMock and traceContext' , ( ) => {
196196 const classInstance = new MyClass ( ) ;
197197 const response = classInstance . divisionFunction ( 1 , 2 ) ;
198- expect ( traceHandlerDivisionMock ) . toHaveBeenCalledWith (
198+ expect ( onTraceEventDivisionMock ) . toHaveBeenCalledWith (
199199 expect . objectContaining ( {
200200 metadata : expect . objectContaining ( {
201201 class : 'MyClass' ,
@@ -213,10 +213,10 @@ describe('trace decorator', () => {
213213 expect ( response ) . toEqual ( 0.5 ) ;
214214 } ) ;
215215
216- it ( 'should sync trace errors and pass correct traceHandlerMock and traceContext' , ( ) => {
216+ it ( 'should sync trace errors and pass correct onTraceEventMock and traceContext' , ( ) => {
217217 expect ( ( ) => new MyClass ( ) . divisionFunction ( 1 , 0 ) ) . toThrow ( 'Throwing because division by zero is not allowed.' ) ;
218218
219- expect ( traceHandlerDivisionMock ) . toHaveBeenCalledWith (
219+ expect ( onTraceEventDivisionMock ) . toHaveBeenCalledWith (
220220 expect . objectContaining ( {
221221 metadata : expect . objectContaining ( {
222222 class : 'MyClass' ,
@@ -233,9 +233,9 @@ describe('trace decorator', () => {
233233 ) ;
234234 } ) ;
235235
236- it ( 'should async trace successfully and pass correct traceHandlerMock and traceContext' , async ( ) => {
236+ it ( 'should async trace successfully and pass correct onTraceEventMock and traceContext' , async ( ) => {
237237 const response = await new MyClass ( ) . fetchDataFunction ( 'https://api.example.com/data' ) ;
238- expect ( traceHandlerFetchDataMock ) . toHaveBeenCalledWith (
238+ expect ( onTraceEventFetchDataMock ) . toHaveBeenCalledWith (
239239 expect . objectContaining ( {
240240 metadata : expect . objectContaining ( {
241241 class : 'MyClass' ,
@@ -253,9 +253,9 @@ describe('trace decorator', () => {
253253 expect ( response ) . toMatchObject ( { data : 'Success' } ) ;
254254 } ) ;
255255
256- it ( 'should async trace errors and pass correct traceHandlerMock and traceContext' , async ( ) => {
256+ it ( 'should async trace errors and pass correct onTraceEventMock and traceContext' , async ( ) => {
257257 await expect ( new MyClass ( ) . fetchDataFunction ( 'invalid-url' ) ) . rejects . toThrow ( 'Invalid URL provided.' ) ;
258- expect ( traceHandlerFetchDataMock ) . toHaveBeenCalledWith (
258+ expect ( onTraceEventFetchDataMock ) . toHaveBeenCalledWith (
259259 expect . objectContaining ( {
260260 metadata : expect . objectContaining ( {
261261 class : 'MyClass' ,
@@ -275,7 +275,7 @@ describe('trace decorator', () => {
275275 it ( 'should async trace successfully divisionFunctionOnAnotherDecorator' , async ( ) => {
276276 const classInstance = new MyClass ( ) ;
277277 const response = classInstance . divisionFunctionOnAnotherDecorator ( 1 , 2 ) ;
278- expect ( traceHandlerDivisionMock ) . toHaveBeenNthCalledWith (
278+ expect ( onTraceEventDivisionMock ) . toHaveBeenNthCalledWith (
279279 2 ,
280280 expect . objectContaining ( {
281281 metadata : expect . objectContaining ( {
@@ -297,7 +297,7 @@ describe('trace decorator', () => {
297297
298298 it ( 'should async trace error divisionFunctionOnAnotherDecorator' , async ( ) => {
299299 expect ( ( ) => new MyClass ( ) . divisionFunctionOnAnotherDecorator ( 1 , 0 ) ) . toThrow ( 'Throwing because division by zero is not allowed.' ) ;
300- expect ( traceHandlerDivisionMock ) . toHaveBeenNthCalledWith (
300+ expect ( onTraceEventDivisionMock ) . toHaveBeenNthCalledWith (
301301 2 ,
302302 expect . objectContaining ( {
303303 metadata : expect . objectContaining ( {
@@ -318,7 +318,7 @@ describe('trace decorator', () => {
318318
319319 it ( 'should async trace successfully fetchDataFunctionOnAnotherDecorator' , async ( ) => {
320320 const response = await new MyClass ( ) . fetchDataFunctionOnAnotherDecorator ( 'https://api.example.com/data' ) ;
321- expect ( traceHandlerFetchDataMock ) . toHaveBeenNthCalledWith (
321+ expect ( onTraceEventFetchDataMock ) . toHaveBeenNthCalledWith (
322322 2 ,
323323 expect . objectContaining ( {
324324 metadata : expect . objectContaining ( {
@@ -340,7 +340,7 @@ describe('trace decorator', () => {
340340
341341 it ( 'should async trace error fetchDataFunctionOnAnotherDecorator' , async ( ) => {
342342 await expect ( new MyClass ( ) . fetchDataFunctionOnAnotherDecorator ( 'invalid-url' ) ) . rejects . toThrow ( 'Invalid URL provided.' ) ;
343- expect ( traceHandlerFetchDataMock ) . toHaveBeenNthCalledWith (
343+ expect ( onTraceEventFetchDataMock ) . toHaveBeenNthCalledWith (
344344 2 ,
345345 expect . objectContaining ( {
346346 metadata : expect . objectContaining ( {
@@ -361,7 +361,7 @@ describe('trace decorator', () => {
361361
362362 it ( 'should async trace error fetchDataFunctionOnAnotherDecorator cought' , async ( ) => {
363363 const response = await new MyClass ( ) . fetchDataFunctionOnAnotherDecoratorCoughtError ( 'invalid-url' ) ;
364- expect ( traceHandlerFetchDataMock ) . toHaveBeenNthCalledWith (
364+ expect ( onTraceEventFetchDataMock ) . toHaveBeenNthCalledWith (
365365 2 ,
366366 expect . objectContaining ( {
367367 metadata : expect . objectContaining ( {
0 commit comments