@@ -166,5 +166,42 @@ describe('gulp-ng-config', function () {
166166 done ( ) ;
167167 } ) ) ;
168168 } ) ;
169+ it ( 'should select an embedded json object if an environment key is supplied and the key exists' , function ( done ) {
170+ var expectedOutputA = fs . readFileSync ( path . normalize ( __dirname + '/mocks/output_8.js' ) ) , // match envA
171+ expectedOutputB = fs . readFileSync ( path . normalize ( __dirname + '/mocks/output_9.js' ) ) , // match envB
172+ expectedOutputC = fs . readFileSync ( path . normalize ( __dirname + '/mocks/output_10.js' ) ) , // no match
173+ streamA = gulp . src ( path . normalize ( __dirname + '/mocks/input_3.json' ) ) ,
174+ streamB = gulp . src ( path . normalize ( __dirname + '/mocks/input_3.json' ) ) ,
175+ streamC = gulp . src ( path . normalize ( __dirname + '/mocks/input_3.json' ) ) ;
176+
177+ // tests output with `environmentA`
178+ streamA . pipe ( plugin ( 'gulp-ng-config' , {
179+ environment : 'environmentA'
180+ } ) )
181+ . pipe ( through . obj ( function ( file ) {
182+ expect ( file . contents . toString ( ) ) . to . equal ( expectedOutputA . toString ( ) ) ;
183+ } ) ) ;
184+
185+ // tests output with `environmentB`
186+ streamB . pipe ( plugin ( 'gulp-ng-config' , {
187+ environment : 'environmentB'
188+ } ) )
189+ . pipe ( through . obj ( function ( file ) {
190+ expect ( file . contents . toString ( ) ) . to . equal ( expectedOutputB . toString ( ) ) ;
191+ } ) ) ;
192+
193+ // tests output with no matching environment key
194+ streamC . pipe ( plugin ( 'gulp-ng-config' , {
195+ environment : 'nonExistant'
196+ } ) )
197+ . pipe ( through . obj ( function ( file ) {
198+ expect ( file . contents . toString ( ) ) . to . equal ( expectedOutputC . toString ( ) ) ;
199+ } ) ) ;
200+
201+ es . merge ( streamA , streamB , streamC )
202+ . pipe ( through . obj ( function ( ) {
203+ done ( ) ;
204+ } ) ) ;
205+ } ) ;
169206 } ) ;
170207} ) ;
0 commit comments