File tree Expand file tree Collapse file tree 2 files changed +25
-6
lines changed Expand file tree Collapse file tree 2 files changed +25
-6
lines changed Original file line number Diff line number Diff line change @@ -86,4 +86,21 @@ describe('config()', () => {
8686 expect ( loaded ) . to . have . property ( 'firebase' ) ;
8787 expect ( loaded ) . to . have . property ( 'foo' , 'bar' ) ;
8888 } ) ;
89+
90+ it ( 'accepts full JSON in env.CLOUD_RUNTIME_CONFIG' , ( ) => {
91+ process . env . CLOUD_RUNTIME_CONFIG = JSON . stringify ( { foo : 'bar' , firebase :{ } } ) ;
92+ let loaded = config ( ) ;
93+ expect ( loaded ) . to . have . property ( 'firebase' ) ;
94+ expect ( loaded ) . to . have . property ( 'foo' , 'bar' ) ;
95+ } ) ;
96+
97+ it ( 'behaves well when both env.CLOUD_RUNTIME_CONFIG and env.FIREBASE_PROJECT are set' , ( ) => {
98+ process . env . CLOUD_RUNTIME_CONFIG = JSON . stringify ( { foo : 'bar' } ) ;
99+ process . env . FIREBASE_PROJECT = JSON . stringify ( {
100+ databaseURL : 'foo@firebaseio.com' ,
101+ } ) ;
102+ let loaded = config ( ) ;
103+ expect ( loaded . firebase ) . to . have . property ( 'databaseURL' , 'foo@firebaseio.com' ) ;
104+ expect ( loaded ) . to . have . property ( 'foo' , 'bar' ) ;
105+ } ) ;
89106} ) ;
Original file line number Diff line number Diff line change @@ -42,20 +42,22 @@ export namespace config {
4242}
4343
4444function init ( credential : firebase . credential . Credential ) {
45- let loadedFromFile = { } ;
4645 let firebaseEnv = { } ;
4746 if ( process . env . FIREBASE_PROJECT ) {
4847 firebaseEnv = { firebase : JSON . parse ( process . env . FIREBASE_PROJECT ) } ;
4948 }
49+ let merged = firebaseEnv ;
5050
5151 try {
52- let path = process . env . CLOUD_RUNTIME_CONFIG || '../../../.runtimeconfig.json' ;
53- loadedFromFile = require ( path ) ;
52+ merged = _ . merge ( { } , JSON . parse ( process . env . CLOUD_RUNTIME_CONFIG ) , firebaseEnv ) ;
5453 } catch ( e ) {
55- // Do nothing
54+ try {
55+ let path = process . env . CLOUD_RUNTIME_CONFIG || '../../../.runtimeconfig.json' ;
56+ merged = _ . merge ( { } , require ( path ) , firebaseEnv ) ;
57+ } catch ( e ) {
58+ // Do nothing
59+ }
5660 }
57- let merged = _ . merge ( { } , loadedFromFile , firebaseEnv ) ;
58-
5961 if ( ! hasFirebase ( merged ) ) {
6062 throw new Error ( 'Firebase config variables are not available. ' +
6163 'Please use the latest version of the Firebase CLI to deploy this function.' ) ;
You can’t perform that action at this time.
0 commit comments