@@ -3,7 +3,14 @@ import { Hub, makeMain } from '@sentry/core';
33import * as utils from '@sentry/utils' ;
44
55import { Span , spanStatusfromHttpCode , Transaction } from '../../src' ;
6- import { fetchCallback , FetchData , instrumentOutgoingRequests , xhrCallback , XHRData } from '../../src/browser/request' ;
6+ import {
7+ fetchCallback ,
8+ FetchData ,
9+ instrumentOutgoingRequests ,
10+ makeShouldAttachHeaders ,
11+ xhrCallback ,
12+ XHRData ,
13+ } from '../../src/browser/request' ;
714import { addExtensionMethods } from '../../src/hubextensions' ;
815import * as tracingUtils from '../../src/utils' ;
916import { getDefaultBrowserClientOptions } from '../testutils' ;
@@ -383,3 +390,52 @@ describe('callbacks', () => {
383390 } ) ;
384391 } ) ;
385392} ) ;
393+
394+ // TODO (v8): Adapt these tests once we remove `tracingOrigins`
395+ describe ( '[pre-v8]: shouldAttachHeaders' , ( ) => {
396+ describe ( 'prefer `tracePropagationTargets` over `tracingOrigins`' , ( ) => {
397+ it ( 'should return `true` if the url matches the new tracePropagationTargets' , ( ) => {
398+ const shouldAttachHeaders = makeShouldAttachHeaders ( [ 'example.com' ] , undefined ) ;
399+ expect ( shouldAttachHeaders ( 'http://example.com' ) ) . toBe ( true ) ;
400+ } ) ;
401+ it ( 'should return `false` if tracePropagationTargets array is empty' , ( ) => {
402+ const shouldAttachHeaders = makeShouldAttachHeaders ( [ ] , [ 'localhost' ] ) ;
403+ expect ( shouldAttachHeaders ( 'http://localhost:3000/test' ) ) . toBe ( false ) ;
404+ } ) ;
405+ it ( "should return `false` if tracePropagationTargets array doesn't match" , ( ) => {
406+ const shouldAttachHeaders = makeShouldAttachHeaders ( [ 'example.com' ] , [ 'localhost' ] ) ;
407+ expect ( shouldAttachHeaders ( 'http://localhost:3000/test' ) ) . toBe ( false ) ;
408+ } ) ;
409+ } ) ;
410+
411+ describe ( 'tracingOrigins backwards compatibility (tracePropagationTargets not defined)' , ( ) => {
412+ it ( 'should return `true` if the url matches tracingOrigns' , ( ) => {
413+ const shouldAttachHeaders = makeShouldAttachHeaders ( undefined , [ 'example.com' ] ) ;
414+ expect ( shouldAttachHeaders ( 'http://example.com' ) ) . toBe ( true ) ;
415+ } ) ;
416+ it ( 'should return `false` if tracePropagationTargets array is empty' , ( ) => {
417+ const shouldAttachHeaders = makeShouldAttachHeaders ( undefined , [ ] ) ;
418+ expect ( shouldAttachHeaders ( 'http://localhost:3000/test' ) ) . toBe ( false ) ;
419+ } ) ;
420+ it ( "should return `false` if tracePropagationTargets array doesn't match" , ( ) => {
421+ const shouldAttachHeaders = makeShouldAttachHeaders ( undefined , [ 'example.com' ] ) ;
422+ expect ( shouldAttachHeaders ( 'http://localhost:3000/test' ) ) . toBe ( false ) ;
423+ } ) ;
424+ } ) ;
425+
426+ describe ( 'should fall back to defaults if no options are specified' , ( ) => {
427+ it . each ( [
428+ '/api/test' ,
429+ 'http://localhost:3000/test' ,
430+ 'http://somewhere.com/test/localhost/123' ,
431+ 'http://somewhere.com/test?url=localhost:3000&test=123' ,
432+ ] ) ( 'return `true` for urls matching defaults (%s)' , url => {
433+ const shouldAttachHeaders = makeShouldAttachHeaders ( undefined , undefined ) ;
434+ expect ( shouldAttachHeaders ( url ) ) . toBe ( true ) ;
435+ } ) ;
436+ it . each ( [ 'notmydoman/api/test' , 'example.com' ] ) ( 'return `false` for urls not matching defaults (%s)' , url => {
437+ const shouldAttachHeaders = makeShouldAttachHeaders ( undefined , undefined ) ;
438+ expect ( shouldAttachHeaders ( url ) ) . toBe ( false ) ;
439+ } ) ;
440+ } ) ;
441+ } ) ;
0 commit comments