Skip to content
This repository has been archived by the owner on Jan 4, 2022. It is now read-only.

fix - issue 302 #1

Merged
merged 1 commit into from
Aug 21, 2020
Merged
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
8 changes: 5 additions & 3 deletions lib/nconf/stores/argv.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,18 @@ Argv.prototype.loadArgv = function () {
}

if (self.separator) {
self.set(common.key.apply(common, key.split(self.separator)), val);
var path = common.path(key, self.separator);

self.set(common.keyed.apply(common, [self.logicalSeparator].concat(path)), val);
}
else {
self.set(key, val);
}
}
});

this.showHelp = yargs.showHelp
this.help = yargs.help
this.showHelp = yargs.showHelp;
this.help = yargs.help;

if (tempWrite) {
this.readOnly = true;
Expand Down
4 changes: 3 additions & 1 deletion lib/nconf/stores/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ Env.prototype.loadEnv = function () {
}

if (self.separator) {
self.set(common.key.apply(common, key.split(self.separator)), val);
var path = common.path(key, self.separator);

self.set(common.keyed.apply(common, [self.logicalSeparator].concat(path)), val);
}
else {
self.set(key, val);
Expand Down
8 changes: 4 additions & 4 deletions test/complete.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@ describe('nconf/multiple-stores', () => {
nconf.env({lowerCase: true});
done();
})
})
});
it("env vars keys also available as lower case", () => {
Object.keys(process.env).forEach(function (key) {
expect(nconf.get(key.toLowerCase())).toEqual(process.env[key]);
});
})
});
afterAll(() => nconf.remove('env'))
});

Expand All @@ -136,7 +136,7 @@ describe('nconf/multiple-stores', () => {
nconf.env({parseValues: true});
done();
})
})
});
it("JSON keys properly parsed", () => {
Object.keys(process.env).forEach(function (key) {
var val = process.env[key];
Expand All @@ -147,7 +147,7 @@ describe('nconf/multiple-stores', () => {
}

expect(nconf.get(key)).toEqual(val);
})
});
afterAll(() => nconf.remove('env'))
});

Expand Down
1 change: 0 additions & 1 deletion test/hierarchy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ describe('nconf/hierarchy, When using nconf', () => {
});

child.on('close', function () {
console.log(data);
expect(JSON.parse(data)).toEqual({
apples: true,
candy: {
Expand Down
16 changes: 15 additions & 1 deletion test/stores/argv.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
var yargs = require('yargs');
var nconf = require('../../lib/nconf');

process.env.DEEP__NESTED__VALUE = 'foo';

describe('nconf/stores/argv, An instance of nconf.Argv', () => {

it("should have the correct methods defined", () => {
Expand All @@ -17,6 +19,18 @@ describe('nconf/stores/argv, An instance of nconf.Argv', () => {
expect(argv.options).toEqual({});
});

it("should be able to retrieve a value using the logical separator", () => {
var argv = new nconf.Argv({
deep__nested__value: {alias: 'nv', default: 'foo'},
logicalSeparator: '.',
separator: '__'
});
argv.loadSync();

expect(argv.logicalSeparator).toBe('.');
expect(argv.get('deep.nested.value')).toBe('foo');
});

describe("can be created with a custom yargs", () => {
var yargsInstance = yargs.alias('s', 'somearg').default('s', 'false');

Expand Down Expand Up @@ -55,7 +69,7 @@ describe('nconf/stores/argv, An instance of nconf.Argv', () => {
});
});
describe("can be created with readOnly set to be false", () => {

it("readOnly is actually false", () => {
var argv = new nconf.Argv({readOnly: false});
expect(argv.readOnly).toBe(false);
Expand Down
9 changes: 9 additions & 0 deletions test/stores/env.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

var nconf = require('../../lib/nconf');

process.env.DEEP__NESTED__VALUE = 'foo';

describe('nconf/stores/env, An instance of nconf.Env', () => {
it("should have the correct methods defined", () => {
var env = new nconf.Env();
Expand All @@ -25,4 +27,11 @@ describe('nconf/stores/env, An instance of nconf.Env', () => {
expect(env.separator).toEqual('');
expect(env.readOnly).toBe(false);
});
it("should be able to retrieve a value using the logical separator", () => {
var env = new nconf.Env({logicalSeparator: '.', separator: '__'});
env.loadSync();

expect(env.logicalSeparator).toBe('.');
expect(env.get('DEEP.NESTED.VALUE')).toBe('foo');
})
});