1- import { expect , test } from 'vitest' ;
1+ import { describe , expect , test } from 'vitest' ;
22import {
33 baggageHeaderToDynamicSamplingContext ,
44 dynamicSamplingContextToSentryBaggageHeader ,
5+ parseBaggageHeader ,
56} from '../../src/utils-hoist/baggage' ;
67
78test . each ( [
@@ -27,7 +28,7 @@ test.each([
2728 { environment : 'production' , release : '1.0.1' } ,
2829 ] ,
2930 [ 42 , undefined ] ,
30- ] ) ( 'baggageHeaderToDynamicSamplingContext(%p ) should return %p ' , ( input , expectedOutput ) => {
31+ ] ) ( 'baggageHeaderToDynamicSamplingContext(%j ) should return %j ' , ( input , expectedOutput ) => {
3132 expect ( baggageHeaderToDynamicSamplingContext ( input ) ) . toStrictEqual ( expectedOutput ) ;
3233} ) ;
3334
@@ -40,6 +41,34 @@ test.each([
4041 { release : 'abcdf' , environment : '1234' , someRandomKey : 'foo' } ,
4142 'sentry-release=abcdf,sentry-environment=1234,sentry-someRandomKey=foo' ,
4243 ] ,
43- ] ) ( 'dynamicSamplingContextToSentryBaggageHeader(%p ) should return %p ' , ( input , expectedOutput ) => {
44+ ] ) ( 'dynamicSamplingContextToSentryBaggageHeader(%j ) should return %j ' , ( input , expectedOutput ) => {
4445 expect ( dynamicSamplingContextToSentryBaggageHeader ( input ) ) . toStrictEqual ( expectedOutput ) ;
4546} ) ;
47+
48+ describe ( 'parseBaggageHeader' , ( ) => {
49+ test . each ( [
50+ [ undefined , undefined ] ,
51+ [ 1 , undefined ] ,
52+ [ true , undefined ] ,
53+ [ false , undefined ] ,
54+ [ null , undefined ] ,
55+ [ NaN , undefined ] ,
56+ [ Infinity , undefined ] ,
57+ [ 0 , undefined ] ,
58+ [ '' , undefined ] ,
59+ [ 'foo' , { } ] ,
60+ [
61+ 'sentry-environment=production,sentry-release=10.0.2,foo=bar' ,
62+ { 'sentry-environment' : 'production' , 'sentry-release' : '10.0.2' , foo : 'bar' } ,
63+ ] ,
64+ [
65+ [ 'sentry-environment=production,sentry-release=10.0.2,foo=bar' , 'foo2=bar2' ] ,
66+ { 'sentry-environment' : 'production' , 'sentry-release' : '10.0.2' , foo : 'bar' , foo2 : 'bar2' } ,
67+ ] ,
68+ // ignores malformed baggage entries
69+ [ 'foo=bar,foo2=%3G' , { foo : 'bar' } ] ,
70+ ] ) ( 'parseBaggageHeader(%j) should return %j' , ( input , expectedOutput ) => {
71+ const actual = parseBaggageHeader ( input ) ;
72+ expect ( actual ) . toStrictEqual ( expectedOutput ) ;
73+ } ) ;
74+ } ) ;
0 commit comments