Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
goatandsheep committed Feb 11, 2024
1 parent 8b683e0 commit b352f71
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,21 @@ describe('react-native-dotenv', () => {
})

it('should fail to load APP_ENV development', () => {
console.error = jest.fn()
process.env.APP_ENV = 'development'

const {code} = transformFileSync(FIXTURES + 'app-env-development/source.js')
expect(code).toBe('console.log("never");\nconsole.log("this-should-not-appear");')
expect(console.error.mock.calls[0][0]).toBe('APP_ENV error')
})

it('should fail to load APP_ENV production', () => {
console.error = jest.fn()
process.env.APP_ENV = 'production'

const {code} = transformFileSync(FIXTURES + 'app-env-production/source.js')
expect(code).toBe('console.log("never");\nconsole.log("this-should-not-appear");')
expect(console.error.mock.calls[0][0]).toBe('APP_ENV error')
})

it('should load MY_ENV specific env file', () => {
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ module.exports = (api, options) => {

if (options.verbose) {
console.log('dotenvMode', babelMode)
if (options.envName === 'production' || options.envName === 'development') {
console.error('dotenv error', 'cannot use APP_ENV=development or APP_ENV=production')
if (process.env[options.envName] === 'production' || process.env[options.envName] === 'development') {
console.error('APP_ENV error', 'cannot use APP_ENV=development or APP_ENV=production')
}
}

Expand Down

0 comments on commit b352f71

Please sign in to comment.