@@ -4,10 +4,13 @@ import mockery from 'mockery';
44import sinon from 'sinon' ;
55import sinonChai from 'sinon-chai' ;
66
7+ import dotenvex from '../lib/index' ;
8+ import parseCommand from '../lib/utils/parse-command' ;
9+ import getConfigFromEnv from '../lib/utils/config-from-env' ;
10+
711chai . use ( sinonChai ) ;
812
913describe ( 'dotenv-extended tests' , ( ) => {
10- let dotenvex ;
1114
1215 before ( ( ) => {
1316 mockery . enable ( {
@@ -16,7 +19,6 @@ describe('dotenv-extended tests', () => {
1619 useCleanCache : true
1720 } ) ;
1821 sinon . stub ( console , 'error' ) ;
19- dotenvex = require ( '../' ) ;
2022 } ) ;
2123
2224 after ( ( ) => {
@@ -163,6 +165,16 @@ describe('dotenv-extended tests', () => {
163165 expect ( runTest ) . to . throw ( 'REGEX MISMATCH: TEST_TWO, TEST_THREE' ) ;
164166 } ) ;
165167
168+ it ( 'Should default missing values to empty string when errorOnRegex is true' , ( ) => {
169+ const runTest = ( ) => {
170+ dotenvex . load ( {
171+ schema : '.env.schema.regex-optional' ,
172+ errorOnRegex : true ,
173+ } ) ;
174+ } ;
175+ expect ( runTest ) . to . throw ( 'REGEX MISMATCH: TEST_MISSING_REQUIRED' ) ;
176+ } ) ;
177+
166178 it ( 'Should log an error when silent is set to false and .env.defaults is missing' , function ( ) {
167179 dotenvex . load ( { silent : false } ) ;
168180 expect ( console . error ) . to . have . been . calledOnce ;
@@ -183,9 +195,6 @@ describe('Supporting libraries tests', () => {
183195 delete process . env . DOTENV_CONFIG_ASSIGN_TO_PROCESS_ENV ;
184196 delete process . env . DOTENV_CONFIG_OVERRIDE_PROCESS_ENV ;
185197 } ) ;
186-
187- const parseCommand = require ( '../lib/utils/parse-command' ) . parseCommand ;
188- const getConfigFromEnv = require ( '../lib/utils/config-from-env' ) . getConfigFromEnv ;
189198 const cliArgs = [
190199 '--encoding=utf8' ,
191200 '--silent=true' ,
0 commit comments