Skip to content

Commit

Permalink
Add multi-env tests and warning (#14)
Browse files Browse the repository at this point in the history
* WIP test fixes

* multi env warning
  • Loading branch information
goatandsheep authored Jul 8, 2020
1 parent 407a625 commit e3cd9df
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ rm -rf node_modules/.cache/babel-loader/*

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

Multi-environment is still a work in progress.

## Credits

* 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).
Expand Down
7 changes: 7 additions & 0 deletions __tests__/__fixtures__/multi-env/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"plugins": [
["../../../", {
"path": "__tests__/__fixtures__/multi-env/.env"
}]
]
}
2 changes: 2 additions & 0 deletions __tests__/__fixtures__/multi-env/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
API_KEY=never
DEV_USERNAME=username123456
1 change: 1 addition & 0 deletions __tests__/__fixtures__/multi-env/.env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
API_KEY=abc123456
4 changes: 4 additions & 0 deletions __tests__/__fixtures__/multi-env/source.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {API_KEY, DEV_USERNAME} from '@env'

console.log(API_KEY)
console.log(DEV_USERNAME)
7 changes: 6 additions & 1 deletion __tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const {transformFileSync} = require('@babel/core')
const FIXTURES = '__tests__/__fixtures__/'
const env = Object.apply({}, process.env)

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

it('should load multiple env files', () => {
const {code} = transformFileSync(FIXTURES + 'multi-env/source.js')
expect(code).toBe('console.log("abc123456");\nconsole.log("username123456");')
})

it('should support `as alias` import syntax', () => {
const {code} = transformFileSync(FIXTURES + 'as-alias/source.js')
expect(code).toBe('const a = "abc123";\nconst b = "username";')
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-dotenv",
"version": "1.0.0",
"version": "2.2.0",
"description": "Load environment variables using import statements.",
"repository": "github:goatandsheep/react-native-dotenv",
"homepage": "https://github.com/goatandsheep/react-native-dotenv",
Expand Down

0 comments on commit e3cd9df

Please sign in to comment.