@@ -9,7 +9,6 @@ import { getClient, getCurrentScope, getIsolationScope, init, startSpan } from '
9
9
10
10
import type { TransactionEvent } from '@sentry/core' ;
11
11
12
- // @ts -expect-error svelte import
13
12
import DummyComponent from './components/Dummy.svelte' ;
14
13
15
14
const PUBLIC_DSN = 'https://username@domain/123' ;
@@ -37,7 +36,7 @@ describe('Sentry.trackComponent()', () => {
37
36
} ) ;
38
37
} ) ;
39
38
40
- it ( 'creates init and update spans on component initialization' , async ( ) => {
39
+ it ( 'creates init spans on component initialization by default ' , async ( ) => {
41
40
startSpan ( { name : 'outer' } , span => {
42
41
expect ( span ) . toBeDefined ( ) ;
43
42
render ( DummyComponent , { props : { options : { } } } ) ;
@@ -47,7 +46,7 @@ describe('Sentry.trackComponent()', () => {
47
46
48
47
expect ( transactions ) . toHaveLength ( 1 ) ;
49
48
const transaction = transactions [ 0 ] ! ;
50
- expect ( transaction . spans ) . toHaveLength ( 2 ) ;
49
+ expect ( transaction . spans ) . toHaveLength ( 1 ) ;
51
50
52
51
const rootSpanId = transaction . contexts ?. trace ?. span_id ;
53
52
expect ( rootSpanId ) . toBeDefined ( ) ;
@@ -68,29 +67,14 @@ describe('Sentry.trackComponent()', () => {
68
67
timestamp : expect . any ( Number ) ,
69
68
trace_id : expect . stringMatching ( / [ a - f 0 - 9 ] { 32 } / ) ,
70
69
} ) ;
71
-
72
- expect ( transaction . spans ! [ 1 ] ) . toEqual ( {
73
- data : {
74
- 'sentry.op' : 'ui.svelte.update' ,
75
- 'sentry.origin' : 'auto.ui.svelte' ,
76
- } ,
77
- description : '<Svelte Component>' ,
78
- op : 'ui.svelte.update' ,
79
- origin : 'auto.ui.svelte' ,
80
- parent_span_id : rootSpanId ,
81
- span_id : expect . stringMatching ( / [ a - f 0 - 9 ] { 16 } / ) ,
82
- start_timestamp : expect . any ( Number ) ,
83
- timestamp : expect . any ( Number ) ,
84
- trace_id : expect . stringMatching ( / [ a - f 0 - 9 ] { 32 } / ) ,
85
- } ) ;
86
70
} ) ;
87
71
88
- it ( 'creates an update span, when the component is updated ' , async ( ) => {
72
+ it ( 'creates an update span, if `trackUpdates` is `true` ' , async ( ) => {
89
73
startSpan ( { name : 'outer' } , async span => {
90
74
expect ( span ) . toBeDefined ( ) ;
91
75
92
76
// first we create the component
93
- const { component } = render ( DummyComponent , { props : { options : { } } } ) ;
77
+ const { component } = render ( DummyComponent , { props : { options : { trackUpdates : true } } } ) ;
94
78
95
79
// then trigger an update
96
80
// (just changing the trackUpdates prop so that we trigger an update. #
@@ -175,7 +159,7 @@ describe('Sentry.trackComponent()', () => {
175
159
startSpan ( { name : 'outer' } , span => {
176
160
expect ( span ) . toBeDefined ( ) ;
177
161
178
- render ( DummyComponent , { props : { options : { trackInit : false } } } ) ;
162
+ render ( DummyComponent , { props : { options : { trackInit : false , trackUpdates : true } } } ) ;
179
163
} ) ;
180
164
181
165
await getClient ( ) ?. flush ( ) ;
@@ -206,7 +190,13 @@ describe('Sentry.trackComponent()', () => {
206
190
expect ( span ) . toBeDefined ( ) ;
207
191
208
192
render ( DummyComponent , {
209
- props : { options : { componentName : 'CustomComponentName' } } ,
193
+ props : {
194
+ options : {
195
+ componentName : 'CustomComponentName' ,
196
+ // enabling updates to check for both span names in one test
197
+ trackUpdates : true ,
198
+ } ,
199
+ } ,
210
200
} ) ;
211
201
} ) ;
212
202
@@ -220,7 +210,7 @@ describe('Sentry.trackComponent()', () => {
220
210
expect ( transaction . spans ! [ 1 ] ?. description ) . toEqual ( '<CustomComponentName>' ) ;
221
211
} ) ;
222
212
223
- it ( "doesn't do anything, if there's no ongoing transaction " , async ( ) => {
213
+ it ( "doesn't do anything, if there's no ongoing parent span " , async ( ) => {
224
214
render ( DummyComponent , {
225
215
props : { options : { componentName : 'CustomComponentName' } } ,
226
216
} ) ;
@@ -230,11 +220,11 @@ describe('Sentry.trackComponent()', () => {
230
220
expect ( transactions ) . toHaveLength ( 0 ) ;
231
221
} ) ;
232
222
233
- it ( "doesn't record update spans, if there's no ongoing root span at that time" , async ( ) => {
223
+ it ( "doesn't record update spans, if there's no ongoing parent span at that time" , async ( ) => {
234
224
const component = startSpan ( { name : 'outer' } , span => {
235
225
expect ( span ) . toBeDefined ( ) ;
236
226
237
- const { component } = render ( DummyComponent , { props : { options : { } } } ) ;
227
+ const { component } = render ( DummyComponent , { props : { options : { trackUpdates : true } } } ) ;
238
228
return component ;
239
229
} ) ;
240
230
0 commit comments