@@ -16,35 +16,99 @@ import malformedConfiguration from './__fixtures__/malformed-configuration.json'
1616
1717describe ( 'FileBasedConfiguration' , ( ) => {
1818 describe ( 'with user-specified configuration' , ( ) => {
19+ it ( 'resolves configuration fields' , ( ) => {
20+ const configuration = new FileBasedConfiguration (
21+ configurationAllFields
22+ ) ;
23+
24+ expect ( configuration ) . toMatchInlineSnapshot ( `
25+ FileBasedConfiguration {
26+ "actionEventMapper": null,
27+ "actionNameAttribute": "action-name-attr",
28+ "additionalConfiguration": {},
29+ "applicationId": "fake-app-id",
30+ "batchProcessingLevel": "MEDIUM",
31+ "batchSize": "MEDIUM",
32+ "bundleLogsWithRum": true,
33+ "bundleLogsWithTraces": true,
34+ "clientToken": "fake-client-token",
35+ "customEndpoints": {},
36+ "env": "fake-env",
37+ "errorEventMapper": null,
38+ "firstPartyHosts": [
39+ {
40+ "match": "example.com",
41+ "propagatorTypes": [
42+ "b3multi",
43+ "tracecontext",
44+ ],
45+ },
46+ ],
47+ "initializationMode": "SYNC",
48+ "logEventMapper": null,
49+ "longTaskThresholdMs": 44,
50+ "nativeCrashReportEnabled": false,
51+ "nativeInteractionTracking": false,
52+ "nativeLongTaskThresholdMs": 200,
53+ "nativeViewTracking": false,
54+ "proxyConfig": undefined,
55+ "resourceEventMapper": null,
56+ "resourceTracingSamplingRate": 33,
57+ "serviceName": undefined,
58+ "sessionSamplingRate": 100,
59+ "site": "US5",
60+ "telemetrySampleRate": 20,
61+ "trackBackgroundEvents": false,
62+ "trackErrors": true,
63+ "trackFrustrations": true,
64+ "trackInteractions": true,
65+ "trackResources": true,
66+ "trackWatchdogTerminations": false,
67+ "trackingConsent": "not_granted",
68+ "uploadFrequency": "AVERAGE",
69+ "useAccessibilityLabel": false,
70+ "verbosity": "warn",
71+ "vitalsUpdateFrequency": "AVERAGE",
72+ }
73+ ` ) ;
74+ } ) ;
75+
76+ it ( 'prints a warning message when the configuration file cannot be parsed correctly' , ( ) => {
77+ const warnSpy = jest . spyOn ( console , 'warn' ) ;
78+ getJSONConfiguration ( malformedConfiguration ) ;
79+
80+ expect ( warnSpy ) . toHaveBeenCalledWith (
81+ 'DATADOG: Warning: Malformed json configuration file - clientToken, applicationId and env are mandatory properties.'
82+ ) ;
83+ } ) ;
84+
1985 it ( 'resolves all properties from a given file path' , ( ) => {
2086 const config = new FileBasedConfiguration ( {
2187 configuration : {
22- configuration : {
23- applicationId : 'fake-app-id' ,
24- env : 'fake-env' ,
25- clientToken : 'fake-client-token' ,
26- trackInteractions : true ,
27- trackResources : true ,
28- trackErrors : true ,
29- trackingConsent : 'NOT_GRANTED' ,
30- longTaskThresholdMs : 44 ,
31- site : 'US5' ,
32- verbosity : 'WARN' ,
33- actionNameAttribute : 'action-name-attr' ,
34- useAccessibilityLabel : false ,
35- resourceTracingSamplingRate : 33 ,
36- firstPartyHosts : [
37- {
38- match : 'example.com' ,
39- propagatorTypes : [
40- 'B3MULTI' ,
41- 'TRACECONTEXT' ,
42- 'B3' ,
43- 'DATADOG'
44- ]
45- }
46- ]
47- }
88+ applicationId : 'fake-app-id' ,
89+ env : 'fake-env' ,
90+ clientToken : 'fake-client-token' ,
91+ trackInteractions : true ,
92+ trackResources : true ,
93+ trackErrors : true ,
94+ trackingConsent : 'NOT_GRANTED' ,
95+ longTaskThresholdMs : 44 ,
96+ site : 'US5' ,
97+ verbosity : 'WARN' ,
98+ actionNameAttribute : 'action-name-attr' ,
99+ useAccessibilityLabel : false ,
100+ resourceTracingSamplingRate : 33 ,
101+ firstPartyHosts : [
102+ {
103+ match : 'example.com' ,
104+ propagatorTypes : [
105+ 'B3MULTI' ,
106+ 'TRACECONTEXT' ,
107+ 'B3' ,
108+ 'DATADOG'
109+ ]
110+ }
111+ ]
48112 }
49113 } ) ;
50114 expect ( config ) . toMatchInlineSnapshot ( `
@@ -103,11 +167,9 @@ describe('FileBasedConfiguration', () => {
103167 it ( 'applies default values to configuration from a given file path' , ( ) => {
104168 const config = new FileBasedConfiguration ( {
105169 configuration : {
106- configuration : {
107- applicationId : 'fake-app-id' ,
108- env : 'fake-env' ,
109- clientToken : 'fake-client-token'
110- }
170+ applicationId : 'fake-app-id' ,
171+ env : 'fake-env' ,
172+ clientToken : 'fake-client-token'
111173 }
112174 } ) ;
113175 expect ( config ) . toMatchInlineSnapshot ( `
@@ -159,11 +221,9 @@ describe('FileBasedConfiguration', () => {
159221 const resourceEventMapper = ( ) => null ;
160222 const config = new FileBasedConfiguration ( {
161223 configuration : {
162- configuration : {
163- applicationId : 'fake-app-id' ,
164- env : 'fake-env' ,
165- clientToken : 'fake-client-token'
166- }
224+ applicationId : 'fake-app-id' ,
225+ env : 'fake-env' ,
226+ clientToken : 'fake-client-token'
167227 } ,
168228 actionEventMapper,
169229 errorEventMapper,
@@ -188,62 +248,20 @@ describe('FileBasedConfiguration', () => {
188248 it ( 'prints a warning message when the first party hosts contain unknown propagator types' , ( ) => {
189249 const config = new FileBasedConfiguration ( {
190250 configuration : {
191- configuration : {
192- applicationId : 'fake-app-id' ,
193- env : 'fake-env' ,
194- clientToken : 'fake-client-token' ,
195- firstPartyHosts : [
196- {
197- match : 'example.com' ,
198- propagatorTypes : [ 'UNKNOWN' ]
199- }
200- ]
201- }
251+ applicationId : 'fake-app-id' ,
252+ env : 'fake-env' ,
253+ clientToken : 'fake-client-token' ,
254+ firstPartyHosts : [
255+ {
256+ match : 'example.com' ,
257+ propagatorTypes : [ 'UNKNOWN' ]
258+ }
259+ ]
202260 }
203261 } ) ;
204262 expect ( config . firstPartyHosts ) . toHaveLength ( 0 ) ;
205263 } ) ;
206264 } ) ;
207- describe ( 'with resolved file configuration' , ( ) => {
208- it ( 'resolves configuration fields' , ( ) => {
209- const configuration = getJSONConfiguration ( configurationAllFields ) ;
210-
211- expect ( configuration ) . toMatchInlineSnapshot ( `
212- {
213- "actionNameAttribute": "action-name-attr",
214- "applicationId": "fake-app-id",
215- "clientToken": "fake-client-token",
216- "env": "fake-env",
217- "firstPartyHosts": [
218- {
219- "match": "example.com",
220- "propagatorTypes": [
221- "b3multi",
222- "tracecontext",
223- ],
224- },
225- ],
226- "longTaskThresholdMs": 44,
227- "resourceTracingSamplingRate": 33,
228- "site": "US5",
229- "trackErrors": true,
230- "trackInteractions": true,
231- "trackResources": true,
232- "trackingConsent": "not_granted",
233- "useAccessibilityLabel": false,
234- "verbosity": "warn",
235- }
236- ` ) ;
237- } ) ;
238- it ( 'prints a warning message when the configuration file is not found' , ( ) => {
239- expect ( ( ) => getJSONConfiguration ( undefined ) ) . not . toThrow ( ) ;
240- } ) ;
241- it ( 'prints a warning message when the configuration file cannot be parsed correctly' , ( ) => {
242- expect ( ( ) =>
243- getJSONConfiguration ( malformedConfiguration )
244- ) . not . toThrow ( ) ;
245- } ) ;
246- } ) ;
247265
248266 describe ( 'formatPropagatorType' , ( ) => {
249267 it ( 'formats all propagatorTypes correctly' , ( ) => {
0 commit comments