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', () => {
727727 expect ( parsed . toJSON ( ) ) . toEqual ( null ) ;
728728 } ) ;
729729
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+
730750 it ( 'doesnt evaluate non-current environment' , async ( ) => {
731751 const failDirective = forKey ( '$fail' , ( ) => ( ) => {
732752 throw new Error ( ) ;
Original file line number Diff line number Diff line change @@ -168,6 +168,10 @@ export function envDirective(
168168 ( SchemaBuilder ) => SchemaBuilder . emptySchema ( ) . addAdditionalProperties ( ) ,
169169 ( value ) => ( parse ) => {
170170 if ( ! environment ) {
171+ if ( 'none' in value ) {
172+ return parse ( value . none , metadata ) ;
173+ }
174+
171175 if ( 'default' in value ) {
172176 return parse ( value . default , metadata ) ;
173177 }
You can’t perform that action at this time.
0 commit comments