File tree Expand file tree Collapse file tree 3 files changed +34
-1
lines changed
Expand file tree Collapse file tree 3 files changed +34
-1
lines changed Original file line number Diff line number Diff line change 3030 "pem" : " ^1.8.1" ,
3131 "standard" : " ^6.0.5" ,
3232 "supertest" : " ^1.1.0" ,
33+ "test-console" : " ^1.0.0" ,
3334 "zombie" : " ^4.2.1"
3435 },
3536 "peerDependencies" : {
Original file line number Diff line number Diff line change @@ -21,7 +21,29 @@ const util = require('../../lib/util')
2121class Env {
2222
2323 constructor ( Helpers ) {
24- dotenv . load ( { path : path . join ( Helpers . basePath ( ) , '.env' ) } )
24+ const envLocation = this . envPath ( )
25+ const options = {
26+ path : path . join ( Helpers . basePath ( ) , envLocation ) ,
27+ silent : process . env . ENV_SILENT || false ,
28+ encoding : process . env . ENV_ENCODING || 'utf8'
29+ }
30+ dotenv . load ( options )
31+ }
32+
33+ /**
34+ * returns envPath by checking the environment variables
35+ *
36+ * @method envPath
37+ *
38+ * @return {String }
39+ *
40+ * @public
41+ */
42+ envPath ( ) {
43+ if ( ! process . env . ENV_PATH || process . env . ENV_PATH . length === 0 ) {
44+ return '.env'
45+ }
46+ return process . env . ENV_PATH
2547 }
2648
2749 /**
Original file line number Diff line number Diff line change 77*/
88
99const Env = require ( '../../src/Env' )
10+ const stderr = require ( "test-console" ) . stderr
1011const chai = require ( 'chai' )
1112const expect = chai . expect
1213
@@ -21,6 +22,15 @@ describe('Env', function() {
2122 new Env ( Helpers )
2223 } )
2324
25+ it ( 'should load .env file from the location defined as ENV_PATH flag' , function ( ) {
26+ const inspect = stderr . inspect ( )
27+ process . env . ENV_PATH = '/users/.env'
28+ new Env ( Helpers )
29+ inspect . restore ( )
30+ expect ( inspect . output [ 0 ] ) . to . match ( / \/ u s e r s \/ \. e n v / )
31+ process . env . ENV_PATH = ''
32+ } )
33+
2434 it ( 'should get values defined in .env file' , function ( ) {
2535 const env = new Env ( Helpers )
2636 expect ( env . get ( 'APP_PORT' ) ) . to . equal ( '3000' )
You can’t perform that action at this time.
0 commit comments