nested-env-vars.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. var seed = Math.random();
  2. var n = 'rc'+ seed;
  3. var N = 'RC'+ seed;
  4. var assert = require('assert')
  5. // Basic usage
  6. process.env[n+'_someOpt__a'] = 42
  7. process.env[n+'_someOpt__x__'] = 99
  8. process.env[n+'_someOpt__a__b'] = 186
  9. process.env[n+'_someOpt__a__b__c'] = 243
  10. process.env[n+'_someOpt__x__y'] = 1862
  11. process.env[n+'_someOpt__z'] = 186577
  12. // Should ignore empty strings from orphaned '__'
  13. process.env[n+'_someOpt__z__x__'] = 18629
  14. process.env[n+'_someOpt__w__w__'] = 18629
  15. // Leading '__' should ignore everything up to 'z'
  16. process.env[n+'___z__i__'] = 9999
  17. // should ignore case for config name section.
  18. process.env[N+'_test_upperCase'] = 187
  19. function testPrefix(prefix) {
  20. var config = require('../')(prefix, {
  21. option: true
  22. })
  23. console.log('\n\n------ nested-env-vars ------\n',{prefix: prefix}, '\n', config);
  24. assert.equal(config.option, true)
  25. assert.equal(config.someOpt.a, 42)
  26. assert.equal(config.someOpt.x, 99)
  27. // Should not override `a` once it's been set
  28. assert.equal(config.someOpt.a/*.b*/, 42)
  29. // Should not override `x` once it's been set
  30. assert.equal(config.someOpt.x/*.y*/, 99)
  31. assert.equal(config.someOpt.z, 186577)
  32. // Should not override `z` once it's been set
  33. assert.equal(config.someOpt.z/*.x*/, 186577)
  34. assert.equal(config.someOpt.w.w, 18629)
  35. assert.equal(config.z.i, 9999)
  36. assert.equal(config.test_upperCase, 187)
  37. }
  38. testPrefix(n);
  39. testPrefix(N);