@@ -11,7 +11,7 @@ export function createCommonTests({
11
11
testkit : Testkit
12
12
} ) {
13
13
beforeEach ( ( ) => {
14
- Sentry . configureScope ( scope => scope . clearBreadcrumbs ( ) )
14
+ Sentry . getCurrentScope ( ) . clearBreadcrumbs ( )
15
15
} )
16
16
17
17
test ( 'should return an empty breadcrumbs array when there are no breadcrumbs' , async function ( ) {
@@ -25,7 +25,10 @@ export function createCommonTests({
25
25
Sentry . addBreadcrumb ( breadcrumb )
26
26
Sentry . captureException ( new Error ( 'sentry test kit is awesome!' ) )
27
27
await waitForExpect ( ( ) => expect ( testkit . reports ( ) ) . toHaveLength ( 1 ) )
28
- expect ( testkit . reports ( ) [ 0 ] ! . breadcrumbs ) . toMatchObject ( [ breadcrumb ] )
28
+ const expectedBreadcrumb = testkit
29
+ . reports ( ) [ 0 ] !
30
+ . breadcrumbs . find ( b => b . message === breadcrumb . message )
31
+ expect ( expectedBreadcrumb ) . toBeDefined ( )
29
32
} )
30
33
31
34
test ( 'should return report.message when using captureMessage' , async function ( ) {
@@ -42,10 +45,11 @@ export function createCommonTests({
42
45
} )
43
46
44
47
test ( 'should return the provided level' , async function ( ) {
45
- Sentry . configureScope ( scope => {
48
+ {
49
+ const scope = Sentry . getCurrentScope ( )
46
50
scope . setLevel ( 'warning' )
47
51
Sentry . captureException ( new Error ( 'sentry test kit is awesome!' ) )
48
- } )
52
+ }
49
53
50
54
await waitForExpect ( ( ) => expect ( testkit . reports ( ) ) . toHaveLength ( 1 ) )
51
55
expect ( testkit . reports ( ) [ 0 ] ! . level ) . toEqual ( 'warning' )
@@ -113,6 +117,7 @@ export function createCommonTests({
113
117
114
118
test ( 'should extract the exception out of the report at specific index' , async function ( ) {
115
119
Sentry . captureException ( new Error ( 'testing get exception at index 0' ) )
120
+ await waitForExpect ( ( ) => expect ( testkit . reports ( ) ) . toHaveLength ( 1 ) )
116
121
Sentry . captureException ( new Error ( 'testing get exception at index 1' ) )
117
122
await waitForExpect ( ( ) => expect ( testkit . reports ( ) ) . toHaveLength ( 2 ) )
118
123
const { message } = testkit . getExceptionAt ( 1 ) !
@@ -164,55 +169,62 @@ export function createCommonTests({
164
169
165
170
describe ( 'performance' , ( ) => {
166
171
test ( 'should collect transactions' , async function ( ) {
167
- Sentry . startTransaction ( {
172
+ // TODO(sentry): Use `startInactiveSpan()` instead - see https://github.com/getsentry/sentry-javascript/blob/develop/docs/v8-new-performance-apis.md
173
+ Sentry . startInactiveSpan ( {
168
174
op : 'transaction' ,
169
175
name : 'transaction-name' ,
170
- } ) . finish ( )
176
+ } ) . end ( )
171
177
await waitForExpect ( ( ) => expect ( testkit . transactions ( ) ) . toHaveLength ( 1 ) )
172
178
expect ( testkit . transactions ( ) [ 0 ] ! . name ) . toEqual ( 'transaction-name' )
173
179
expect ( testkit . transactions ( ) [ 0 ] ! . release ) . toEqual ( 'test' )
174
180
} )
175
181
176
- test ( 'should support tags ' , async function ( ) {
177
- Sentry . startTransaction ( {
182
+ test ( 'should support attributes ' , async function ( ) {
183
+ Sentry . startInactiveSpan ( {
178
184
op : 'transaction' ,
179
185
name : 'transaction-name' ,
180
- tags : { a : 1 , b : 2 } ,
181
- } ) . finish ( )
186
+ attributes : { a : 1 , b : 2 } ,
187
+ } ) . end ( )
182
188
await waitForExpect ( ( ) => expect ( testkit . transactions ( ) ) . toHaveLength ( 1 ) )
183
- expect ( testkit . transactions ( ) [ 0 ] ! . tags ) . toEqual ( { a : 1 , b : 2 } )
189
+ expect ( testkit . transactions ( ) [ 0 ] ! . data ) . toEqual (
190
+ expect . objectContaining ( { a : 1 , b : 2 } )
191
+ )
184
192
} )
185
193
186
194
test ( 'should support extra data' , async function ( ) {
187
195
Sentry . withScope ( scope => {
188
196
scope . setExtra ( 'hello' , 'world' )
189
- Sentry . startTransaction ( {
197
+ // TODO(sentry): Use `startInactiveSpan()` instead - see https://github.com/getsentry/sentry-javascript/blob/develop/docs/v8-new-performance-apis.md
198
+ Sentry . startInactiveSpan ( {
190
199
op : 'transaction' ,
191
200
name : 'transaction-name' ,
192
- } ) . finish ( )
201
+ } ) . end ( )
193
202
} )
194
203
await waitForExpect ( ( ) => expect ( testkit . transactions ( ) ) . toHaveLength ( 1 ) )
195
204
expect ( testkit . transactions ( ) [ 0 ] ! . extra ) . toEqual ( { hello : 'world' } )
196
205
} )
197
206
198
207
test ( 'should collect child spans' , async function ( ) {
199
- const transaction = Sentry . startTransaction ( {
200
- op : 'transaction' ,
201
- name : 'transaction-name' ,
202
- } )
203
- const child = transaction . startChild ( {
204
- op : 'child' ,
205
- description : 'child-description' ,
206
- } )
207
- child . finish ( )
208
- transaction . finish ( )
208
+ const transaction = Sentry . startSpan (
209
+ {
210
+ // op: 'transaction',
211
+ name : 'transaction-name' ,
212
+ } ,
213
+ span => {
214
+ const child = Sentry . startInactiveSpan ( {
215
+ name : 'child-span' ,
216
+ op : 'child' ,
217
+ } )
218
+ child . end ( )
219
+ return span
220
+ }
221
+ )
222
+
223
+ transaction . end ( )
209
224
await waitForExpect ( ( ) => expect ( testkit . transactions ( ) ) . toHaveLength ( 1 ) )
210
- expect ( testkit . transactions ( ) [ 0 ] ! . spans [ 0 ] ) . toEqual ( {
211
- id : child . spanId ,
212
- op : 'child' ,
213
- description : 'child-description' ,
214
- parentSpanId : child . parentSpanId ,
215
- } )
225
+ const span = testkit . transactions ( ) [ 0 ] ! . spans [ 0 ]
226
+ expect ( span . parent_span_id ) . toEqual ( transaction . spanContext ( ) . spanId )
227
+ expect ( span . trace_id ) . toEqual ( transaction . spanContext ( ) . traceId )
216
228
} )
217
229
} )
218
230
}
0 commit comments