Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TEST="This is the content of TEST variable"
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ Pass in the path to your `.env`-file using the `-p` flag:
$ run.env -p my/path/env-file node my-node-app.js
```

Run test locally:
1. Change `.env.test` to `.env`
2. Run `npm run test`. This command will create the build and simulate how `run.env` works on `test/test_app.js`
3. If the test passed, it would log _"This is the content of TEST variable"_ which is the value of TEST variable in `.env` file
4. Otherwise, it would log _"No value for process.env.TEST"_

## License

[MIT](LICENSE)
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"build": "babel --presets es2015 src -d lib",
"prepublish": "rm -fr lib/ && npm run build",
"dev": "./node_modules/.bin/babel-node src/",
"start": "node lib/"
"start": "node lib/",
"test": "npm run build && node lib/index.js node test/test_app.js"
},
"engines": {
"node": ">=6.1.0",
Expand Down
17 changes: 17 additions & 0 deletions test/test_app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
try {
if (process.env.TEST) {
console.log(`\nValue of process.env.TEST: "${process.env.TEST}"`);
} else {
throw new Error('\nNo value for process.env.TEST');
}

if (process.env.NON_EXISTING_VAR) {
console.log(
`\nValue of process.env.TEST: "${process.env.NON_EXISTING_VAR}"`
);
} else {
throw new Error('\nNo value for process.env.NON_EXISTING_VAR');
}
} catch (err) {
console.log(err.message);
}