1
+ import { Scope } from '@sentry/browser' ;
1
2
import type { SpanContext } from '@sentry/types' ;
2
3
import { render } from '@testing-library/react' ;
3
4
import { renderHook } from '@testing-library/react-hooks' ;
@@ -14,31 +15,26 @@ const mockFinish = jest.fn();
14
15
class MockSpan {
15
16
public constructor ( public readonly ctx : SpanContext ) { }
16
17
17
- public startChild ( ctx : SpanContext ) : MockSpan {
18
- mockStartChild ( ctx ) ;
19
- return new MockSpan ( ctx ) ;
20
- }
21
-
22
18
public end ( ) : void {
23
19
mockFinish ( ) ;
24
20
}
25
21
}
26
22
27
- let activeTransaction : Record < string , any > ;
23
+ let activeSpan : Record < string , any > ;
28
24
29
25
jest . mock ( '@sentry/browser' , ( ) => ( {
30
- getCurrentHub : ( ) => ( {
31
- getIntegration : ( ) => undefined ,
32
- getScope : ( ) => ( {
33
- getTransaction : ( ) => activeTransaction ,
34
- } ) ,
35
- } ) ,
26
+ ... jest . requireActual ( '@sentry/browser' ) ,
27
+ getActiveSpan : ( ) => activeSpan ,
28
+ startInactiveSpan : ( ctx : SpanContext ) => {
29
+ mockStartChild ( ctx ) ;
30
+ return new MockSpan ( ctx ) ;
31
+ } ,
36
32
} ) ) ;
37
33
38
34
beforeEach ( ( ) => {
39
35
mockStartChild . mockClear ( ) ;
40
36
mockFinish . mockClear ( ) ;
41
- activeTransaction = new MockSpan ( { op : 'pageload' } ) ;
37
+ activeSpan = new MockSpan ( { op : 'pageload' } ) ;
42
38
} ) ;
43
39
44
40
describe ( 'withProfiler' , ( ) => {
@@ -78,10 +74,10 @@ describe('withProfiler', () => {
78
74
79
75
expect ( mockStartChild ) . toHaveBeenCalledTimes ( 1 ) ;
80
76
expect ( mockStartChild ) . toHaveBeenLastCalledWith ( {
81
- description : `<${ UNKNOWN_COMPONENT } >` ,
77
+ name : `<${ UNKNOWN_COMPONENT } >` ,
82
78
op : REACT_MOUNT_OP ,
83
79
origin : 'auto.ui.react.profiler' ,
84
- data : { 'ui.component_name' : 'unknown' } ,
80
+ attributes : { 'ui.component_name' : 'unknown' } ,
85
81
} ) ;
86
82
} ) ;
87
83
} ) ;
@@ -96,12 +92,11 @@ describe('withProfiler', () => {
96
92
97
93
expect ( mockStartChild ) . toHaveBeenCalledTimes ( 2 ) ;
98
94
expect ( mockStartChild ) . toHaveBeenLastCalledWith ( {
99
- description : `<${ UNKNOWN_COMPONENT } >` ,
100
- endTimestamp : expect . any ( Number ) ,
95
+ name : `<${ UNKNOWN_COMPONENT } >` ,
101
96
op : REACT_RENDER_OP ,
102
97
origin : 'auto.ui.react.profiler' ,
103
98
startTimestamp : undefined ,
104
- data : { 'ui.component_name' : 'unknown' } ,
99
+ attributes : { 'ui.component_name' : 'unknown' } ,
105
100
} ) ;
106
101
} ) ;
107
102
@@ -128,22 +123,24 @@ describe('withProfiler', () => {
128
123
rerender ( < ProfiledComponent num = { 1 } /> ) ;
129
124
expect ( mockStartChild ) . toHaveBeenCalledTimes ( 2 ) ;
130
125
expect ( mockStartChild ) . toHaveBeenLastCalledWith ( {
131
- data : { changedProps : [ 'num' ] , 'ui.component_name' : 'unknown' } ,
132
- description : `<${ UNKNOWN_COMPONENT } >` ,
126
+ attributes : { 'ui.react.changed_props' : [ 'num' ] , 'ui.component_name' : 'unknown' } ,
127
+ name : `<${ UNKNOWN_COMPONENT } >` ,
133
128
op : REACT_UPDATE_OP ,
134
129
origin : 'auto.ui.react.profiler' ,
135
130
startTimestamp : expect . any ( Number ) ,
131
+ scope : expect . any ( Scope ) ,
136
132
} ) ;
137
133
expect ( mockFinish ) . toHaveBeenCalledTimes ( 2 ) ;
138
134
// New props yet again
139
135
rerender ( < ProfiledComponent num = { 2 } /> ) ;
140
136
expect ( mockStartChild ) . toHaveBeenCalledTimes ( 3 ) ;
141
137
expect ( mockStartChild ) . toHaveBeenLastCalledWith ( {
142
- data : { changedProps : [ 'num' ] , 'ui.component_name' : 'unknown' } ,
143
- description : `<${ UNKNOWN_COMPONENT } >` ,
138
+ attributes : { 'ui.react.changed_props' : [ 'num' ] , 'ui.component_name' : 'unknown' } ,
139
+ name : `<${ UNKNOWN_COMPONENT } >` ,
144
140
op : REACT_UPDATE_OP ,
145
141
origin : 'auto.ui.react.profiler' ,
146
142
startTimestamp : expect . any ( Number ) ,
143
+ scope : expect . any ( Scope ) ,
147
144
} ) ;
148
145
expect ( mockFinish ) . toHaveBeenCalledTimes ( 3 ) ;
149
146
@@ -179,10 +176,10 @@ describe('useProfiler()', () => {
179
176
180
177
expect ( mockStartChild ) . toHaveBeenCalledTimes ( 1 ) ;
181
178
expect ( mockStartChild ) . toHaveBeenLastCalledWith ( {
182
- description : '<Example>' ,
179
+ name : '<Example>' ,
183
180
op : REACT_MOUNT_OP ,
184
181
origin : 'auto.ui.react.profiler' ,
185
- data : { 'ui.component_name' : 'Example' } ,
182
+ attributes : { 'ui.component_name' : 'Example' } ,
186
183
} ) ;
187
184
} ) ;
188
185
} ) ;
@@ -203,10 +200,10 @@ describe('useProfiler()', () => {
203
200
expect ( mockStartChild ) . toHaveBeenCalledTimes ( 2 ) ;
204
201
expect ( mockStartChild ) . toHaveBeenLastCalledWith (
205
202
expect . objectContaining ( {
206
- description : '<Example>' ,
203
+ name : '<Example>' ,
207
204
op : REACT_RENDER_OP ,
208
205
origin : 'auto.ui.react.profiler' ,
209
- data : { 'ui.component_name' : 'Example' } ,
206
+ attributes : { 'ui.component_name' : 'Example' } ,
210
207
} ) ,
211
208
) ;
212
209
} ) ;
0 commit comments