Skip to content

Commit e3cd9df

Browse files
authored
Add multi-env tests and warning (#14)
* WIP test fixes * multi env warning
1 parent 407a625 commit e3cd9df

File tree

7 files changed

+23
-2
lines changed

7 files changed

+23
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ rm -rf node_modules/.cache/babel-loader/*
131131

132132
Or you can override the default `cacheIdentifier` to include some of your environment variables.
133133

134+
Multi-environment is still a work in progress.
135+
134136
## Credits
135137

136138
* Based on [David Chang](https://github.com/zetachang)’s works on [babel-plugin-dotenv](https://github.com/zetachang/react-native-dotenv/tree/master/babel-plugin-dotenv).
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"plugins": [
3+
["../../../", {
4+
"path": "__tests__/__fixtures__/multi-env/.env"
5+
}]
6+
]
7+
}

__tests__/__fixtures__/multi-env/.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
API_KEY=never
2+
DEV_USERNAME=username123456
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
API_KEY=abc123456
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import {API_KEY, DEV_USERNAME} from '@env'
2+
3+
console.log(API_KEY)
4+
console.log(DEV_USERNAME)

__tests__/index.test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const {transformFileSync} = require('@babel/core')
33
const FIXTURES = '__tests__/__fixtures__/'
44
const env = Object.apply({}, process.env)
55

6-
describe('babel-plugin-dotenv-import', () => {
6+
describe('react-native-dotenv', () => {
77
afterEach(() => {
88
process.env = Object.apply({}, env)
99
})
@@ -50,6 +50,11 @@ describe('babel-plugin-dotenv-import', () => {
5050
expect(code).toBe('console.log("abc123456");\nconsole.log("username123456");')
5151
})
5252

53+
it('should load multiple env files', () => {
54+
const {code} = transformFileSync(FIXTURES + 'multi-env/source.js')
55+
expect(code).toBe('console.log("abc123456");\nconsole.log("username123456");')
56+
})
57+
5358
it('should support `as alias` import syntax', () => {
5459
const {code} = transformFileSync(FIXTURES + 'as-alias/source.js')
5560
expect(code).toBe('const a = "abc123";\nconst b = "username";')

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-dotenv",
3-
"version": "1.0.0",
3+
"version": "2.2.0",
44
"description": "Load environment variables using import statements.",
55
"repository": "github:goatandsheep/react-native-dotenv",
66
"homepage": "https://github.com/goatandsheep/react-native-dotenv",

0 commit comments

Comments
 (0)