@@ -11,6 +11,7 @@ import {
1111} from '../../src/browser/browsertracing' ;
1212import { defaultRequestInstrumentionOptions } from '../../src/browser/request' ;
1313import { defaultRoutingInstrumentation } from '../../src/browser/router' ;
14+ import * as hubExtensions from '../../src/hubextensions' ;
1415import { DEFAULT_IDLE_TIMEOUT , IdleTransaction } from '../../src/idletransaction' ;
1516import { getActiveTransaction , secToMs } from '../../src/utils' ;
1617
@@ -76,7 +77,6 @@ describe('BrowserTracing', () => {
7677 const browserTracing = createBrowserTracing ( ) ;
7778
7879 expect ( browserTracing . options ) . toEqual ( {
79- beforeNavigate : expect . any ( Function ) ,
8080 idleTimeout : DEFAULT_IDLE_TIMEOUT ,
8181 markBackgroundTransactions : true ,
8282 maxTransactionDuration : DEFAULT_MAX_TRANSACTION_DURATION_SECONDS ,
@@ -210,12 +210,20 @@ describe('BrowserTracing', () => {
210210 const name = 'sentry-trace' ;
211211 const content = '126de09502ae4e0fb26c6967190756a4-b6e54397b12a2a0f-1' ;
212212 document . head . innerHTML = `<meta name="${ name } " content="${ content } ">` ;
213+ const startIdleTransaction = jest . spyOn ( hubExtensions , 'startIdleTransaction' ) ;
214+
213215 createBrowserTracing ( true , { routingInstrumentation : customRoutingInstrumentation } ) ;
214- const transaction = getActiveTransaction ( hub ) as IdleTransaction ;
215216
216- expect ( transaction . traceId ) . toBe ( '126de09502ae4e0fb26c6967190756a4' ) ;
217- expect ( transaction . parentSpanId ) . toBe ( 'b6e54397b12a2a0f' ) ;
218- expect ( transaction . sampled ) . toBe ( true ) ;
217+ expect ( startIdleTransaction ) . toHaveBeenCalledWith (
218+ expect . any ( Object ) ,
219+ expect . objectContaining ( {
220+ traceId : '126de09502ae4e0fb26c6967190756a4' ,
221+ parentSpanId : 'b6e54397b12a2a0f' ,
222+ parentSampled : true ,
223+ } ) ,
224+ expect . any ( Number ) ,
225+ expect . any ( Boolean ) ,
226+ ) ;
219227 } ) ;
220228
221229 describe ( 'idleTimeout' , ( ) => {
@@ -341,22 +349,35 @@ describe('BrowserTracing', () => {
341349 } ) ;
342350 } ) ;
343351 } ) ;
344- } ) ;
345352
346- describe ( 'getMeta' , ( ) => {
347- it ( 'returns a found meta tag contents' , ( ) => {
348- const name = 'sentry-trace' ;
349- const content = '126de09502ae4e0fb26c6967190756a4-b6e54397b12a2a0f-1' ;
350- document . head . innerHTML = `<meta name="${ name } " content="${ content } ">` ;
353+ describe ( 'sentry-trace <meta> element' , ( ) => {
354+ describe ( 'getMetaContent' , ( ) => {
355+ it ( 'finds the specified tag and extracts the value' , ( ) => {
356+ const name = 'sentry-trace' ;
357+ const content = '126de09502ae4e0fb26c6967190756a4-b6e54397b12a2a0f-1' ;
358+ document . head . innerHTML = `<meta name="${ name } " content="${ content } ">` ;
351359
352- const meta = getMetaContent ( name ) ;
353- expect ( meta ) . toBe ( content ) ;
354- } ) ;
360+ const metaTagValue = getMetaContent ( name ) ;
361+ expect ( metaTagValue ) . toBe ( content ) ;
362+ } ) ;
355363
356- it ( 'only returns meta tags queried for' , ( ) => {
357- document . head . innerHTML = `<meta name="not-test ">` ;
364+ it ( "doesn't return meta tags other than the one specified" , ( ) => {
365+ document . head . innerHTML = `<meta name="cat-cafe ">` ;
358366
359- const meta = getMetaContent ( 'test' ) ;
360- expect ( meta ) . toBe ( null ) ;
367+ const metaTagValue = getMetaContent ( 'dogpark' ) ;
368+ expect ( metaTagValue ) . toBe ( null ) ;
369+ } ) ;
370+
371+ it ( 'can pick the correct tag out of multiple options' , ( ) => {
372+ const name = 'sentry-trace' ;
373+ const content = '126de09502ae4e0fb26c6967190756a4-b6e54397b12a2a0f-1' ;
374+ const sentryTraceMeta = `<meta name="${ name } " content="${ content } ">` ;
375+ const otherMeta = `<meta name="cat-cafe">` ;
376+ document . head . innerHTML = `${ sentryTraceMeta } ${ otherMeta } ` ;
377+
378+ const metaTagValue = getMetaContent ( name ) ;
379+ expect ( metaTagValue ) . toBe ( content ) ;
380+ } ) ;
381+ } ) ;
361382 } ) ;
362383} ) ;
0 commit comments