@@ -30,6 +30,8 @@ describe('config()', () => {
3030 afterEach ( ( ) => {
3131 mockRequire . stopAll ( ) ;
3232 unsetSingleton ( ) ;
33+ delete process . env . FIREBASE_PROJECT ;
34+ delete process . env . CLOUD_RUNTIME_CONFIG ;
3335 } ) ;
3436
3537 it ( 'loads config values from .runtimeconfig.json' , ( ) => {
@@ -39,25 +41,49 @@ describe('config()', () => {
3941 expect ( loaded ) . to . have . property ( 'foo' , 'bar' ) ;
4042 } ) ;
4143
42- it ( 'loads config values from config.json' , ( ) => {
43- mockRequire ( '../../../config.json' , { foo : 'bar' , firebase : { } } ) ;
44- let loaded = config ( ) ;
45- expect ( loaded ) . to . have . property ( 'firebase' ) ;
46- expect ( loaded ) . to . have . property ( 'foo' , 'bar' ) ;
47- } ) ;
48-
4944 it ( 'injects a Firebase credential' , ( ) => {
5045 mockRequire ( '../../../.runtimeconfig.json' , { firebase : { } } ) ;
5146 expect ( config ( ) ) . to . deep . property ( 'firebase.credential' ) ;
5247 } ) ;
5348
54- it ( 'throws an error if config .json not present' , ( ) => {
49+ it ( 'throws an error if .runtimeconfig .json not present' , ( ) => {
5550 mockRequire ( '../../../.runtimeconfig.json' , 'does-not-exist' ) ;
5651 expect ( config ) . to . throw ( 'not available' ) ;
5752 } ) ;
5853
5954 it ( 'throws an error if Firebase configs not present' , ( ) => {
6055 mockRequire ( '../../../.runtimeconfig.json' , { } ) ;
61- expect ( config ) . to . throw ( 'Firebase config variables are missing.' ) ;
56+ expect ( config ) . to . throw ( 'Firebase config variables are not available.' ) ;
57+ } ) ;
58+
59+ it ( 'loads Firebase configs from FIREBASE_PROJECT env variable' , ( ) => {
60+ process . env . FIREBASE_PROJECT = JSON . stringify ( {
61+ databaseURL : 'foo@firebaseio.com' ,
62+ } ) ;
63+ let firebaseConfig = config ( ) . firebase ;
64+ expect ( firebaseConfig ) . to . have . property ( 'databaseURL' , 'foo@firebaseio.com' ) ;
65+ } ) ;
66+
67+ it ( 'behaves well when both FIREBASE_PROJECT and .runtimeconfig.json present' , ( ) => {
68+ process . env . FIREBASE_PROJECT = JSON . stringify ( {
69+ databaseURL : 'foo@firebaseio.com' ,
70+ } ) ;
71+ mockRequire ( '../../../.runtimeconfig.json' , {
72+ firebase : {
73+ databaseURL : 'foo@firebaseio.com' ,
74+ } ,
75+ foo : 'bar' ,
76+ } ) ;
77+ let loaded = config ( ) ;
78+ expect ( loaded . firebase ) . to . have . property ( 'databaseURL' , 'foo@firebaseio.com' ) ;
79+ expect ( loaded ) . to . have . property ( 'foo' , 'bar' ) ;
80+ } ) ;
81+
82+ it ( 'accepts alternative locations for config file' , ( ) => {
83+ process . env . CLOUD_RUNTIME_CONFIG = 'another.json' ;
84+ mockRequire ( 'another.json' , { foo : 'bar' , firebase : { } } ) ;
85+ let loaded = config ( ) ;
86+ expect ( loaded ) . to . have . property ( 'firebase' ) ;
87+ expect ( loaded ) . to . have . property ( 'foo' , 'bar' ) ;
6288 } ) ;
6389} ) ;
0 commit comments