File tree 2 files changed +20
-3
lines changed
2 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -56,7 +56,7 @@ export class EnvNotSetError extends Error {
56
56
* 5. Validate the environment variable's value using `validator`.
57
57
*
58
58
* @param envVariable name of the environment variable
59
- * @param validator Zod schema used to validate the environment variable's value
59
+ * @param validator Zod schema used to validate the environment variable's value. Defaults to { @link OPTIONAL}.
60
60
* @param defaultValue default value for the environment variable
61
61
*
62
62
* @throws {ConfigParseError } If the final environment variable's value cannot be parsed using `validator`,
@@ -66,7 +66,7 @@ export class EnvNotSetError extends Error {
66
66
*/
67
67
export async function initVariable (
68
68
envVariable : string ,
69
- validator : ZodSchemaCompat ,
69
+ validator : ZodSchemaCompat = OPTIONAL ,
70
70
defaultValue ?: string ,
71
71
) : Promise < void > {
72
72
logger ( ) . debug ( `(${ envVariable } ) Setting up environment variable.` , {
Original file line number Diff line number Diff line change @@ -296,6 +296,23 @@ Deno.test("initVariable", async (t) => {
296
296
"Expected the value to be undefined" ,
297
297
) ;
298
298
} ) ;
299
+
300
+ await t . step ( "Single Argument defaults to OPTIONAL" , async ( t ) => {
301
+ prepare ( "XXX" ) ;
302
+ await initVariable ( ENV_VAR ) ;
303
+ await assertEquals (
304
+ Deno . env . get ( ENV_VAR ) ,
305
+ "XXX" ,
306
+ "Expected the value to be undefined" ,
307
+ ) ;
308
+ prepare ( ) ;
309
+ await initVariable ( ENV_VAR ) ;
310
+ await assertEquals (
311
+ Deno . env . get ( ENV_VAR ) ,
312
+ undefined ,
313
+ "Expected the value to be undefined" ,
314
+ ) ;
315
+ } ) ;
299
316
} ) ;
300
317
301
318
Deno . test ( "Built-in ZodSchemaCompat Validators" , async ( t ) => {
@@ -332,7 +349,7 @@ Deno.test("Built-in ZodSchemaCompat Validators", async (t) => {
332
349
[
333
350
"" ,
334
351
] ,
335
- )
352
+ ) ;
336
353
337
354
function testZodSchemaCompatValidator (
338
355
ctx : Deno . TestContext ,
You can’t perform that action at this time.
0 commit comments