@@ -22,7 +22,7 @@ describe('$envVar directive', () => {
22
22
expect ( parsed . toJSON ( ) ) . toEqual ( { foo : 'foo' , bar : 'bar' } ) ;
23
23
} ) ;
24
24
25
- it ( 'reads object with $ name' , async ( ) => {
25
+ it ( 'reads object with name' , async ( ) => {
26
26
process . env . FOO = 'foo' ;
27
27
28
28
const source = new LiteralSource ( {
@@ -34,15 +34,15 @@ describe('$envVar directive', () => {
34
34
expect ( parsed . toJSON ( ) ) . toEqual ( { foo : 'foo' } ) ;
35
35
} ) ;
36
36
37
- it ( 'fails with $ name when not defined' , async ( ) => {
37
+ it ( 'fails with name when not defined' , async ( ) => {
38
38
const source = new LiteralSource ( {
39
39
foo : { $envVar : { name : 'FOO' } } ,
40
40
} ) ;
41
41
42
42
await expect ( source . read ( [ envVarDirective ( ) ] ) ) . rejects . toThrow ( ) ;
43
43
} ) ;
44
44
45
- it ( 'uses $ name when $ fallback is defined' , async ( ) => {
45
+ it ( 'uses name when fallback is defined' , async ( ) => {
46
46
process . env . FOO = 'foo' ;
47
47
48
48
const source = new LiteralSource ( {
@@ -54,7 +54,7 @@ describe('$envVar directive', () => {
54
54
expect ( parsed . toJSON ( ) ) . toEqual ( { foo : 'foo' } ) ;
55
55
} ) ;
56
56
57
- it ( 'uses $ fallback when $ name was not found' , async ( ) => {
57
+ it ( 'uses fallback when name was not found' , async ( ) => {
58
58
const source = new LiteralSource ( {
59
59
foo : { $envVar : { name : 'FOO' , fallback : 'bar' } } ,
60
60
} ) ;
@@ -64,7 +64,7 @@ describe('$envVar directive', () => {
64
64
expect ( parsed . toJSON ( ) ) . toEqual ( { foo : 'bar' } ) ;
65
65
} ) ;
66
66
67
- it ( 'allows null value when $ allowNull' , async ( ) => {
67
+ it ( 'allows null value when allowNull' , async ( ) => {
68
68
const source = new LiteralSource ( {
69
69
foo : { $envVar : { name : 'FOO' , fallback : null , allowNull : true } } ,
70
70
} ) ;
@@ -74,14 +74,27 @@ describe('$envVar directive', () => {
74
74
expect ( parsed . toJSON ( ) ) . toEqual ( { foo : null } ) ;
75
75
} ) ;
76
76
77
- it ( 'does not allow number even when $ allowNull' , async ( ) => {
77
+ it ( 'does not allow number even when allowNull' , async ( ) => {
78
78
const source = new LiteralSource ( {
79
79
foo : { $envVar : { name : 'FOO' , fallback : 42 , allowNull : true } } ,
80
80
} ) ;
81
81
82
82
await expect ( source . read ( [ envVarDirective ( ) ] ) ) . rejects . toThrow ( ) ;
83
83
} ) ;
84
84
85
+ it ( 'returns null when allowMissing' , async ( ) => {
86
+ process . env . BAR = 'foo' ;
87
+
88
+ const source = new LiteralSource ( {
89
+ foo : { $envVar : { name : 'FOO' , allowMissing : true } } ,
90
+ bar : { $envVar : { name : 'BAR' , allowMissing : true } } ,
91
+ } ) ;
92
+
93
+ const parsed = await source . read ( [ envVarDirective ( ) ] ) ;
94
+
95
+ expect ( parsed . toJSON ( ) ) . toEqual ( { foo : null , bar : 'foo' } ) ;
96
+ } ) ;
97
+
85
98
it ( 'parses ints' , async ( ) => {
86
99
process . env . FOO = '11' ;
87
100
0 commit comments