1
- import { expect , test } from 'vitest' ;
1
+ import { describe , expect , test } from 'vitest' ;
2
2
import {
3
3
baggageHeaderToDynamicSamplingContext ,
4
4
dynamicSamplingContextToSentryBaggageHeader ,
5
+ parseBaggageHeader ,
5
6
} from '../../src/utils-hoist/baggage' ;
6
7
7
8
test . each ( [
@@ -27,7 +28,7 @@ test.each([
27
28
{ environment : 'production' , release : '1.0.1' } ,
28
29
] ,
29
30
[ 42 , undefined ] ,
30
- ] ) ( 'baggageHeaderToDynamicSamplingContext(%p ) should return %p ' , ( input , expectedOutput ) => {
31
+ ] ) ( 'baggageHeaderToDynamicSamplingContext(%j ) should return %j ' , ( input , expectedOutput ) => {
31
32
expect ( baggageHeaderToDynamicSamplingContext ( input ) ) . toStrictEqual ( expectedOutput ) ;
32
33
} ) ;
33
34
@@ -40,6 +41,34 @@ test.each([
40
41
{ release : 'abcdf' , environment : '1234' , someRandomKey : 'foo' } ,
41
42
'sentry-release=abcdf,sentry-environment=1234,sentry-someRandomKey=foo' ,
42
43
] ,
43
- ] ) ( 'dynamicSamplingContextToSentryBaggageHeader(%p ) should return %p ' , ( input , expectedOutput ) => {
44
+ ] ) ( 'dynamicSamplingContextToSentryBaggageHeader(%j ) should return %j ' , ( input , expectedOutput ) => {
44
45
expect ( dynamicSamplingContextToSentryBaggageHeader ( input ) ) . toStrictEqual ( expectedOutput ) ;
45
46
} ) ;
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