@@ -455,6 +455,80 @@ describe('sentry-xcode.sh', () => {
455455 expect ( result . stdout ) . toContain ( 'skipping sourcemaps upload' ) ;
456456 } ) ;
457457
458+ describe ( 'sentry.options.json SENTRY_ENVIRONMENT override' , ( ) => {
459+ it ( 'copies file without modification when SENTRY_ENVIRONMENT is not set' , ( ) => {
460+ const optionsContent = JSON . stringify ( { dsn : 'https://key@sentry.io/123' , environment : 'production' } ) ;
461+ const optionsFile = path . join ( tempDir , 'sentry.options.json' ) ;
462+ fs . writeFileSync ( optionsFile , optionsContent ) ;
463+
464+ const buildDir = path . join ( tempDir , 'build' ) ;
465+ const resourcesPath = 'Resources' ;
466+ fs . mkdirSync ( path . join ( buildDir , resourcesPath ) , { recursive : true } ) ;
467+
468+ const result = runScript ( {
469+ SENTRY_DISABLE_AUTO_UPLOAD : 'true' ,
470+ SENTRY_COPY_OPTIONS_FILE : 'true' ,
471+ SENTRY_OPTIONS_FILE_PATH : optionsFile ,
472+ CONFIGURATION_BUILD_DIR : buildDir ,
473+ UNLOCALIZED_RESOURCES_FOLDER_PATH : resourcesPath ,
474+ } ) ;
475+
476+ expect ( result . exitCode ) . toBe ( 0 ) ;
477+ const destPath = path . join ( buildDir , resourcesPath , 'sentry.options.json' ) ;
478+ const copied = JSON . parse ( fs . readFileSync ( destPath , 'utf8' ) ) ;
479+ expect ( copied . dsn ) . toBe ( 'https://key@sentry.io/123' ) ;
480+ expect ( copied . environment ) . toBe ( 'production' ) ;
481+ } ) ;
482+
483+ it ( 'overrides environment from SENTRY_ENVIRONMENT env var' , ( ) => {
484+ const optionsContent = JSON . stringify ( { dsn : 'https://key@sentry.io/123' , environment : 'production' } ) ;
485+ const optionsFile = path . join ( tempDir , 'sentry.options.json' ) ;
486+ fs . writeFileSync ( optionsFile , optionsContent ) ;
487+
488+ const buildDir = path . join ( tempDir , 'build' ) ;
489+ const resourcesPath = 'Resources' ;
490+ fs . mkdirSync ( path . join ( buildDir , resourcesPath ) , { recursive : true } ) ;
491+
492+ const result = runScript ( {
493+ SENTRY_DISABLE_AUTO_UPLOAD : 'true' ,
494+ SENTRY_COPY_OPTIONS_FILE : 'true' ,
495+ SENTRY_OPTIONS_FILE_PATH : optionsFile ,
496+ CONFIGURATION_BUILD_DIR : buildDir ,
497+ UNLOCALIZED_RESOURCES_FOLDER_PATH : resourcesPath ,
498+ SENTRY_ENVIRONMENT : 'staging' ,
499+ } ) ;
500+
501+ expect ( result . exitCode ) . toBe ( 0 ) ;
502+ expect ( result . stdout ) . toContain ( 'Overriding' ) ;
503+ const destPath = path . join ( buildDir , resourcesPath , 'sentry.options.json' ) ;
504+ const copied = JSON . parse ( fs . readFileSync ( destPath , 'utf8' ) ) ;
505+ expect ( copied . environment ) . toBe ( 'staging' ) ;
506+ expect ( copied . dsn ) . toBe ( 'https://key@sentry.io/123' ) ;
507+ } ) ;
508+
509+ it ( 'does not modify the source sentry.options.json' , ( ) => {
510+ const optionsContent = JSON . stringify ( { dsn : 'https://key@sentry.io/123' , environment : 'production' } ) ;
511+ const optionsFile = path . join ( tempDir , 'sentry.options.json' ) ;
512+ fs . writeFileSync ( optionsFile , optionsContent ) ;
513+
514+ const buildDir = path . join ( tempDir , 'build' ) ;
515+ const resourcesPath = 'Resources' ;
516+ fs . mkdirSync ( path . join ( buildDir , resourcesPath ) , { recursive : true } ) ;
517+
518+ runScript ( {
519+ SENTRY_DISABLE_AUTO_UPLOAD : 'true' ,
520+ SENTRY_COPY_OPTIONS_FILE : 'true' ,
521+ SENTRY_OPTIONS_FILE_PATH : optionsFile ,
522+ CONFIGURATION_BUILD_DIR : buildDir ,
523+ UNLOCALIZED_RESOURCES_FOLDER_PATH : resourcesPath ,
524+ SENTRY_ENVIRONMENT : 'staging' ,
525+ } ) ;
526+
527+ const source = JSON . parse ( fs . readFileSync ( optionsFile , 'utf8' ) ) ;
528+ expect ( source . environment ) . toBe ( 'production' ) ;
529+ } ) ;
530+ } ) ;
531+
458532 describe ( 'SOURCEMAP_FILE path resolution' , ( ) => {
459533 // Returns a mock sentry-cli that prints the SOURCEMAP_FILE env var it received.
460534 const makeSourcemapEchoScript = ( dir : string ) : string => {
0 commit comments