diff --git a/.env.test b/.env.test new file mode 100644 index 0000000..232d48c --- /dev/null +++ b/.env.test @@ -0,0 +1 @@ +TEST="This is the content of TEST variable" diff --git a/README.md b/README.md index fc8cbe3..3cf1745 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/package.json b/package.json index b32aaa1..c1f407e 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/test_app.js b/test/test_app.js new file mode 100644 index 0000000..26fff20 --- /dev/null +++ b/test/test_app.js @@ -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); +}