@@ -13,7 +13,7 @@ import type { Client, Integration } from '@sentry/core';
1313
1414import type { BrowserOptions } from '../src' ;
1515import { WINDOW } from '../src' ;
16- import { init } from '../src/sdk' ;
16+ import { applyDefaultOptions , getDefaultIntegrations , init } from '../src/sdk' ;
1717
1818const PUBLIC_DSN = 'https://username@domain/123' ;
1919
@@ -277,3 +277,100 @@ describe('init', () => {
277277 expect ( client ) . not . toBeUndefined ( ) ;
278278 } ) ;
279279} ) ;
280+
281+ describe ( 'applyDefaultOptions' , ( ) => {
282+ test ( 'it works with empty options' , ( ) => {
283+ const options = { } ;
284+ const actual = applyDefaultOptions ( options ) ;
285+
286+ expect ( actual ) . toEqual ( {
287+ defaultIntegrations : expect . any ( Array ) ,
288+ release : undefined ,
289+ autoSessionTracking : true ,
290+ sendClientReports : true ,
291+ } ) ;
292+
293+ expect ( actual . defaultIntegrations && actual . defaultIntegrations . map ( i => i . name ) ) . toEqual (
294+ getDefaultIntegrations ( options ) . map ( i => i . name ) ,
295+ ) ;
296+ } ) ;
297+
298+ test ( 'it works with options' , ( ) => {
299+ const options = {
300+ tracesSampleRate : 0.5 ,
301+ release : '1.0.0' ,
302+ autoSessionTracking : false ,
303+ } ;
304+ const actual = applyDefaultOptions ( options ) ;
305+
306+ expect ( actual ) . toEqual ( {
307+ defaultIntegrations : expect . any ( Array ) ,
308+ release : '1.0.0' ,
309+ autoSessionTracking : false ,
310+ sendClientReports : true ,
311+ tracesSampleRate : 0.5 ,
312+ } ) ;
313+
314+ expect ( actual . defaultIntegrations && actual . defaultIntegrations . map ( i => i . name ) ) . toEqual (
315+ getDefaultIntegrations ( options ) . map ( i => i . name ) ,
316+ ) ;
317+ } ) ;
318+
319+ test ( 'it works with defaultIntegrations=false' , ( ) => {
320+ const options = {
321+ defaultIntegrations : false ,
322+ } as const ;
323+ const actual = applyDefaultOptions ( options ) ;
324+
325+ expect ( actual . defaultIntegrations ) . toStrictEqual ( false ) ;
326+ } ) ;
327+
328+ test ( 'it works with defaultIntegrations=[]' , ( ) => {
329+ const options = {
330+ defaultIntegrations : [ ] ,
331+ } ;
332+ const actual = applyDefaultOptions ( options ) ;
333+
334+ expect ( actual . defaultIntegrations ) . toEqual ( [ ] ) ;
335+ } ) ;
336+
337+ test ( 'it works with tracesSampleRate=undefined' , ( ) => {
338+ const options = {
339+ tracesSampleRate : undefined ,
340+ } as const ;
341+ const actual = applyDefaultOptions ( options ) ;
342+
343+ // Not defined, not even undefined
344+ expect ( 'tracesSampleRate' in actual ) . toBe ( false ) ;
345+ } ) ;
346+
347+ test ( 'it works with tracesSampleRate=null' , ( ) => {
348+ const options = {
349+ tracesSampleRate : null ,
350+ } as any ;
351+ const actual = applyDefaultOptions ( options ) ;
352+
353+ expect ( actual . tracesSampleRate ) . toStrictEqual ( null ) ;
354+ } ) ;
355+
356+ test ( 'it works with tracesSampleRate=0' , ( ) => {
357+ const options = {
358+ tracesSampleRate : 0 ,
359+ } as const ;
360+ const actual = applyDefaultOptions ( options ) ;
361+
362+ expect ( actual . tracesSampleRate ) . toStrictEqual ( 0 ) ;
363+ } ) ;
364+
365+ test ( 'it does not deep-drop undefined keys' , ( ) => {
366+ const options = {
367+ obj : {
368+ prop : undefined ,
369+ } ,
370+ } as any ;
371+ const actual = applyDefaultOptions ( options ) as any ;
372+
373+ expect ( 'prop' in actual . obj ) . toBe ( true ) ;
374+ expect ( actual . obj . prop ) . toStrictEqual ( undefined ) ;
375+ } ) ;
376+ } ) ;
0 commit comments