File tree Expand file tree Collapse file tree 3 files changed +13
-6
lines changed Expand file tree Collapse file tree 3 files changed +13
-6
lines changed File renamed without changes.
Original file line number Diff line number Diff line change 1
1
const { transformFileSync} = require ( '@babel/core' )
2
2
3
3
const FIXTURES = '__tests__/__fixtures__/'
4
- const env = Object . apply ( { } , process . env )
5
4
6
5
describe ( 'react-native-dotenv' , ( ) => {
6
+ const OLD_ENV = process . env
7
7
afterEach ( ( ) => {
8
- process . env = Object . apply ( { } , env )
8
+ jest . resetModules ( )
9
+ process . env = { ...OLD_ENV }
10
+
9
11
} )
10
12
11
13
it ( 'should throw if the variable does not exist' , ( ) => {
@@ -50,6 +52,11 @@ describe('react-native-dotenv', () => {
50
52
expect ( code ) . toBe ( 'console.log("abc123456");\nconsole.log("username123456");' )
51
53
} )
52
54
55
+ it ( 'should load multiple env files' , ( ) => {
56
+ const { code} = transformFileSync ( FIXTURES + 'multi-env/source.js' )
57
+ expect ( code ) . toBe ( 'console.log("abc123456");\nconsole.log("username123456");' )
58
+ } )
59
+
53
60
it ( 'should support `as alias` import syntax' , ( ) => {
54
61
const { code} = transformFileSync ( FIXTURES + 'as-alias/source.js' )
55
62
expect ( code ) . toBe ( 'const a = "abc123";\nconst b = "username";' )
Original file line number Diff line number Diff line change @@ -32,19 +32,19 @@ module.exports = ({types: t}) => ({
32
32
...this . opts
33
33
}
34
34
35
- const babelMode = process . env . BABEL_ENV || 'development'
35
+ const babelMode = process . env . BABEL_ENV || process . env . NODE_ENV || 'development'
36
36
if ( this . opts . safe ) {
37
37
const parsed = parseDotenvFile ( this . opts . path , this . opts . verbose )
38
38
const modeParsed = parseDotenvFile ( this . opts . path + '.' + babelMode )
39
39
this . env = Object . assign ( parsed , modeParsed )
40
40
} else {
41
- dotenv . config ( {
42
- path : this . opts . path
43
- } )
44
41
dotenv . config ( {
45
42
path : this . opts . path + '.' + babelMode ,
46
43
silent : true
47
44
} )
45
+ dotenv . config ( {
46
+ path : this . opts . path
47
+ } )
48
48
this . env = process . env
49
49
}
50
50
} ,
You can’t perform that action at this time.
0 commit comments