File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
app-config-extensions/src Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -727,6 +727,26 @@ describe('$env directive', () => {
727
727
expect ( parsed . toJSON ( ) ) . toEqual ( null ) ;
728
728
} ) ;
729
729
730
+ it ( 'uses the none option' , async ( ) => {
731
+ delete process . env . NODE_ENV ;
732
+ const source = new LiteralSource ( {
733
+ $env : { default : 1 , none : 2 } ,
734
+ } ) ;
735
+
736
+ const parsed = await source . read ( [ envDirective ( ) ] ) ;
737
+ expect ( parsed . toJSON ( ) ) . toEqual ( 2 ) ;
738
+ } ) ;
739
+
740
+ it ( 'uses the default over the none option when env is defined' , async ( ) => {
741
+ process . env . NODE_ENV = 'test' ;
742
+ const source = new LiteralSource ( {
743
+ $env : { default : 1 , none : 2 } ,
744
+ } ) ;
745
+
746
+ const parsed = await source . read ( [ envDirective ( ) ] ) ;
747
+ expect ( parsed . toJSON ( ) ) . toEqual ( 1 ) ;
748
+ } ) ;
749
+
730
750
it ( 'doesnt evaluate non-current environment' , async ( ) => {
731
751
const failDirective = forKey ( '$fail' , ( ) => ( ) => {
732
752
throw new Error ( ) ;
Original file line number Diff line number Diff line change @@ -168,6 +168,10 @@ export function envDirective(
168
168
( SchemaBuilder ) => SchemaBuilder . emptySchema ( ) . addAdditionalProperties ( ) ,
169
169
( value ) => ( parse ) => {
170
170
if ( ! environment ) {
171
+ if ( 'none' in value ) {
172
+ return parse ( value . none , metadata ) ;
173
+ }
174
+
171
175
if ( 'default' in value ) {
172
176
return parse ( value . default , metadata ) ;
173
177
}
You can’t perform that action at this time.
0 commit comments