Skip to content

Commit 74d0d27

Browse files
author
craigparra
committed
Testing how config env vars work - they are loaded very early.
1 parent 2eb8673 commit 74d0d27

File tree

8 files changed

+33
-13
lines changed

8 files changed

+33
-13
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"providedEnvVar": "PROVIDED_ENV_VAR",
3+
"missingEnvVar": "MISSING_ENV_VAR"
4+
}

config/custom-enviropnment-variables.json

Whitespace-only changes.

config/default.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"providedEnvVar": "provided-default-value",
3+
"missingEnvVar": "missing-default-value"
4+
}

config/local-development.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@
99
"placeholder": "start.${one}.${nested.two}.end",
1010
"encrypted" : "enc.pxQ6z9s/LRpGB+4ddJ8bsq8RqELmhVU2",
1111
"encryptedWithSecret" : "enc./emLGkD3cbfqoSPijGZ0jh1p1SYIHQeJ"
12-
}
12+
},
13+
"providedEnvVar": "provided-local-value",
14+
"missingEnvVar": "missing-local-value"
1315
}

package-lock.json

Lines changed: 12 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"lint": "npx eslint \"./*.js\" \"./test/**/*.js\" --fix",
3030
"test": "npm run test:unit",
3131
"test:unit": "npm run test:tdd",
32-
"test:tdd": "mocha --require test/fixtures",
32+
"test:tdd": "cross-env NODE_ENV=npm PROVIDED_ENV_VAR=provided-ext-value mocha --require test/fixtures",
3333
"test:bdd": "npm run cucumber",
3434
"coverage": "npm run nyc",
3535
"mocha": "mocha --require test/fixtures",
@@ -49,6 +49,7 @@
4949
"@cucumber/cucumber": "^7.3.0",
5050
"babel-eslint": "^10.1.0",
5151
"chai": "^4.3.4",
52+
"cross-env": "^7.0.3",
5253
"cucumber": "^7.0.0-rc.0",
5354
"eslint": "^7.30.0",
5455
"eslint-config-airbnb-base": "^14.2.1",

test/fixtures/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
exports.mochaGlobalSetup = async function setup() {
22
// console.log(`mocha global setup: started`);
3-
// ...
3+
// ...
44
// console.log(`mocha global setup: completed`);
55
};
66

test/index.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
process.env.PROVIDED_ENV_VAR = 'provided-index-value';
12
const npmconfig = require('config');
23
const { assert } = require('chai');
34
const {
@@ -61,4 +62,10 @@ describe('Simple encrypted properties and placeholders', () => {
6162
assert.equal(config.get('placeholder'), 'start.one.two.end', 'config placeholder == start.one.two.end');
6263
assert.equal(config.get('placeholderEncrypted'), 'start.hello world.end', 'config placeholderEncrypted == start.hello world.end');
6364
});
65+
66+
it('local-development env vars are resolved ', () => {
67+
//assert.equal(npmconfig.get('providedEnvVar'), 'system', 'config.get(\'providedEnvVar\') == system');
68+
assert.equal(process.env.PROVIDED_ENV_VAR, 'provided-index-value', 'process.env.PROVIDED_ENV_VAR == provided-index-value');
69+
assert.equal(npmconfig.get('missingEnvVar'), 'missing-local-value', 'config.get(\'missingEnvVar\') == missing-local-dev-value');
70+
});
6471
});

0 commit comments

Comments
 (0)