Skip to content

Commit

Permalink
refactor mongodb uri for test mode
Browse files Browse the repository at this point in the history
  • Loading branch information
marekzelinka committed Jul 24, 2024
1 parent 9bd6312 commit abea622
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/node_modules

.env
.env*
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"type": "module",
"scripts": {
"start": "cross-env NODE_ENV=production node src/index.js",
"dev": "cross-env NODE_ENV=development node --watch --env-file=.env src/index.js",
"dev": "cross-env NODE_ENV=development node --watch --env-file=.env --env-file=.env.local src/index.js",
"lint": "eslint src",
"test": "cross-env NODE_ENV=test node --test --watch --env-file=.env",
"test": "cross-env NODE_ENV=test node --test --watch --env-file=.env --env-file=.env.test",
"format": "prettier . -w"
},
"devDependencies": {
Expand Down
9 changes: 1 addition & 8 deletions src/utils/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,7 @@ invariant(NODE_ENV, 'Missing NODE_ENV env var')
const PORT = process.env.PORT
invariant(PORT, 'Missing PORT env var')

let MONGODB_URI = process.env.MONGODB_URI
const MONGODB_URI = process.env.MONGODB_URI
invariant(MONGODB_URI, 'Missing MONGODB_URI env var')

if (NODE_ENV === 'test') {
const TEST_MONGODB_URI = process.env.TEST_MONGODB_URI
invariant(TEST_MONGODB_URI, 'Missing TEST_MONGODB_URI env var')

MONGODB_URI = TEST_MONGODB_URI
}

export const env = { NODE_ENV, PORT, MONGODB_URI }

0 comments on commit abea622

Please sign in to comment.