-
Notifications
You must be signed in to change notification settings - Fork 171
Expand file tree
/
Copy pathembeddedConfigDynamic.scenario.ts
More file actions
158 lines (136 loc) · 5.19 KB
/
embeddedConfigDynamic.scenario.ts
File metadata and controls
158 lines (136 loc) · 5.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import { test, expect } from '@playwright/test'
import { generateCombinedBundle } from '@datadog/browser-sdk-endpoint'
test.describe('embedded configuration with dynamic values', () => {
test('preserves cookie dynamic value markers in generated bundle', () => {
const config = {
applicationId: 'dynamic-cookie-app',
clientToken: 'pub-test-token',
version: { rcSerializedType: 'dynamic', strategy: 'cookie', name: 'app_version' },
}
const bundle = generateCombinedBundle({
sdkCode: '// SDK',
config,
variant: 'rum',
})
expect(bundle).toContain('"rcSerializedType": "dynamic"')
expect(bundle).toContain('"strategy": "cookie"')
expect(bundle).toContain('"name": "app_version"')
})
test('preserves DOM selector dynamic value markers in generated bundle', () => {
const config = {
applicationId: 'dynamic-dom-app',
clientToken: 'pub-test-token',
version: { rcSerializedType: 'dynamic', strategy: 'dom', selector: '#tracking-id' },
}
const bundle = generateCombinedBundle({
sdkCode: '// SDK',
config,
variant: 'rum',
})
expect(bundle).toContain('"strategy": "dom"')
expect(bundle).toContain('"selector": "#tracking-id"')
})
test('preserves DOM attribute dynamic value markers in generated bundle', () => {
const config = {
applicationId: 'dynamic-dom-attr-app',
clientToken: 'pub-test-token',
version: {
rcSerializedType: 'dynamic',
strategy: 'dom',
selector: '#app-meta',
attribute: 'data-version',
},
}
const bundle = generateCombinedBundle({
sdkCode: '// SDK',
config,
variant: 'rum',
})
expect(bundle).toContain('"strategy": "dom"')
expect(bundle).toContain('"selector": "#app-meta"')
expect(bundle).toContain('"attribute": "data-version"')
})
test('preserves JS path dynamic value markers in generated bundle', () => {
const config = {
applicationId: 'dynamic-js-app',
clientToken: 'pub-test-token',
version: { rcSerializedType: 'dynamic', strategy: 'js', path: 'appState.tracking.version' },
}
const bundle = generateCombinedBundle({
sdkCode: '// SDK',
config,
variant: 'rum',
})
expect(bundle).toContain('"strategy": "js"')
expect(bundle).toContain('"path": "appState.tracking.version"')
})
test('mixed static and dynamic values coexist in generated bundle', () => {
const config = {
applicationId: 'mixed-config-app',
clientToken: 'pub-test-token',
sessionSampleRate: 80,
service: 'static-service',
version: { rcSerializedType: 'dynamic', strategy: 'cookie', name: 'app_version' },
env: { rcSerializedType: 'dynamic', strategy: 'js', path: 'deployment.env' },
}
const bundle = generateCombinedBundle({
sdkCode: '// SDK',
config,
variant: 'rum',
})
// Static values embedded
expect(bundle).toContain('"applicationId": "mixed-config-app"')
expect(bundle).toContain('"sessionSampleRate": 80')
expect(bundle).toContain('"service": "static-service"')
// Dynamic markers preserved
expect(bundle).toContain('"strategy": "cookie"')
expect(bundle).toContain('"strategy": "js"')
expect(bundle).toContain('"name": "app_version"')
expect(bundle).toContain('"path": "deployment.env"')
})
test('nested dynamic values preserve structure in generated bundle', () => {
const config = {
applicationId: 'nested-dynamic-app',
clientToken: 'pub-test-token',
allowedTracingUrls: [
{
match: { rcSerializedType: 'string' as const, value: 'https://api.example.com' },
propagatorTypes: ['tracecontext'],
},
],
user: [
{ key: 'id', value: { rcSerializedType: 'dynamic', strategy: 'cookie', name: 'user_id' } },
{ key: 'email', value: { rcSerializedType: 'dynamic', strategy: 'js', path: 'userData.email' } },
],
}
const bundle = generateCombinedBundle({
sdkCode: '// SDK',
config,
variant: 'rum',
})
expect(bundle).toContain('"rcSerializedType": "string"')
expect(bundle).toContain('"value": "https://api.example.com"')
expect(bundle).toContain('"propagatorTypes"')
expect(bundle).toContain('"key": "id"')
expect(bundle).toContain('"key": "email"')
expect(bundle).toContain('"name": "user_id"')
expect(bundle).toContain('"path": "userData.email"')
})
test('generated bundle with dynamic values is valid JavaScript', () => {
const config = {
applicationId: 'valid-js-app',
clientToken: 'pub-test-token',
version: { rcSerializedType: 'dynamic', strategy: 'cookie', name: 'missing_cookie' },
env: { rcSerializedType: 'dynamic', strategy: 'dom', selector: '#nonexistent' },
service: { rcSerializedType: 'dynamic', strategy: 'js', path: 'window.nonexistent.path' },
}
const bundle = generateCombinedBundle({
sdkCode: 'window.__TEST_LOADED__ = true;',
config,
variant: 'rum',
})
// Bundle should be valid JavaScript even with complex dynamic values
// eslint-disable-next-line no-new-func, @typescript-eslint/no-implied-eval
expect(() => new Function(bundle)).not.toThrow()
})
})