Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@venncity/nested-config

Package Overview
Dependencies
Maintainers
1
Versions
114
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@venncity/nested-config - npm Package Compare versions

Comparing version 1.2.0 to 1.2.1

11

CHANGELOG.md

@@ -6,2 +6,13 @@ # Change Log

## [1.2.1](https://github.com/venn-city/npm-shelf/compare/@venncity/nested-config@1.2.0...@venncity/nested-config@1.2.1) (2019-08-20)
### Bug Fixes
* **nested-config:** added has method ([eb15303](https://github.com/venn-city/npm-shelf/commit/eb15303))
# [1.2.0](https://github.com/venn-city/npm-shelf/compare/@venncity/nested-config@1.1.0...@venncity/nested-config@1.2.0) (2019-07-01)

@@ -8,0 +19,0 @@

4

package.json
{
"name": "@venncity/nested-config",
"version": "1.2.0",
"version": "1.2.1",
"author": "Venn Engineering",

@@ -44,3 +44,3 @@ "main": "src/nestedConfig.js",

},
"gitHead": "0b2b6ba67cc007508439a90e03010e3e493410c4"
"gitHead": "06cdf2e342eb415e6e87fa23e05fb3c07647fd05"
}

@@ -18,49 +18,71 @@ /* eslint-disable no-underscore-dangle,global-require */

test('should merge inner and parent config', async () => {
await createFileAtPath('/inner/config/test.json', '{ "prop": "inner" }');
await createFileAtPath('/inner/package.json', '{ "prop": "123" }');
const innerModulePath = await createFileAtPath('/inner/src/module.js', '{ "prop": "123" }');
describe('get', () => {
test('should merge inner and parent config', async () => {
await createFileAtPath('/inner/config/test.json', '{ "prop": "inner" }');
await createFileAtPath('/inner/package.json', '{ "prop": "123" }');
const innerModulePath = await createFileAtPath('/inner/src/module.js', '{ "prop": "123" }');
const nestedConfig = require('./nestedConfig')(innerModulePath);
const testValue = nestedConfig.get('prop');
expect(testValue).toEqual('inner');
});
const nestedConfig = require('./nestedConfig')(innerModulePath);
const testValue = nestedConfig.get('prop');
expect(testValue).toEqual('inner');
});
test('should put two configs from different packages with same name under different config keys', async () => {
await createFileAtPath('/inner/config/test.json', '{ "prop": "inner1" }');
await createFileAtPath('/inner/package.json', '{ "prop": "123" }');
const firstInnerModulePath = await createFileAtPath('/inner/src/module1.js', '{ "prop": "123" }');
test('should put two configs from different packages with same name under different config keys', async () => {
await createFileAtPath('/inner/config/test.json', '{ "prop": "inner1" }');
await createFileAtPath('/inner/package.json', '{ "prop": "123" }');
const firstInnerModulePath = await createFileAtPath('/inner/src/module1.js', '{ "prop": "123" }');
await createFileAtPath('/node_modules/inner/config/test.json', '{ "prop": "inner2" }');
await createFileAtPath('/node_modules/inner/package.json', '{ "prop": "123" }');
const secondInnerModulePath = await createFileAtPath('/node_modules/inner/src/module2.js', '{ "prop": "123" }');
await createFileAtPath('/node_modules/inner/config/test.json', '{ "prop": "inner2" }');
await createFileAtPath('/node_modules/inner/package.json', '{ "prop": "123" }');
const secondInnerModulePath = await createFileAtPath('/node_modules/inner/src/module2.js', '{ "prop": "123" }');
let nestedConfig = require('./nestedConfig')(firstInnerModulePath);
const testValue1 = nestedConfig.get('prop');
expect(testValue1).toEqual('inner1');
let nestedConfig = require('./nestedConfig')(firstInnerModulePath);
const testValue1 = nestedConfig.get('prop');
expect(testValue1).toEqual('inner1');
nestedConfig = require('./nestedConfig')(secondInnerModulePath);
const testValue2 = nestedConfig.get('prop');
expect(testValue2).toEqual('inner2');
nestedConfig = require('./nestedConfig')(secondInnerModulePath);
const testValue2 = nestedConfig.get('prop');
expect(testValue2).toEqual('inner2');
});
test('should not load or fail when no config found', async () => {
await createFileAtPath('/inner/package.json', '{ "prop": "123" }');
const innerModulePath = await createFileAtPath('/inner/src/module.js', '{ "prop": "123" }');
const nestedConfig = rewire(path.join(__dirname, 'nestedConfig.js'));
const spy = spyOn(nestedConfig, 'setModuleConfig');
nestedConfig(innerModulePath);
sinon.assert.notCalled(spy);
});
test('should load parent value when get called with parent flag true', async () => {
await createFileAtPath('/inner/config/test.json', '{ "prop": "inner" }');
await createFileAtPath('/inner/package.json', '{ "prop": "123" }');
const innerModulePath = await createFileAtPath('/inner/src/module.js', '{ "prop": "123" }');
const nestedConfig = require('./nestedConfig')(innerModulePath);
const testValue = nestedConfig.get('prop', { getConfigFromParent: true });
expect(testValue).toEqual('outer');
});
});
test('should not load or fail when no config found', async () => {
await createFileAtPath('/inner/package.json', '{ "prop": "123" }');
const innerModulePath = await createFileAtPath('/inner/src/module.js', '{ "prop": "123" }');
const nestedConfig = rewire(path.join(__dirname, 'nestedConfig.js'));
const spy = spyOn(nestedConfig, 'setModuleConfig');
nestedConfig(innerModulePath);
sinon.assert.notCalled(spy);
describe('has', () => {
test('should return true when parameter found at parent', async () => {
await createFileAtPath('/inner/config/test.json', '{ "prop2": "inner" }');
await createFileAtPath('/inner/package.json', '{ "prop": "123" }');
const innerModulePath = await createFileAtPath('/inner/src/module.js', '{ "prop2": "123" }');
const nestedConfig = require('./nestedConfig')(innerModulePath);
const testValue = nestedConfig.has('prop', { getConfigFromParent: true });
expect(testValue).toBeTruthy();
});
test('should return true when parameter found at inner module', async () => {
await createFileAtPath('/inner/config/test.json', '{ "prop2": "inner" }');
await createFileAtPath('/inner/package.json', '{ "prop": "123" }');
const innerModulePath = await createFileAtPath('/inner/src/module.js', '{ "prop2": "123" }');
const nestedConfig = require('./nestedConfig')(innerModulePath);
const testValue = nestedConfig.has('prop2');
expect(testValue).toBeTruthy();
});
});
test('should load parent value when get called with parent flag true', async () => {
await createFileAtPath('/inner/config/test.json', '{ "prop": "inner" }');
await createFileAtPath('/inner/package.json', '{ "prop": "123" }');
const innerModulePath = await createFileAtPath('/inner/src/module.js', '{ "prop": "123" }');
const nestedConfig = require('./nestedConfig')(innerModulePath);
const testValue = nestedConfig.get('prop', { parentConf: true });
expect(testValue).toEqual('outer');
});
describe('caching tests', () => {

@@ -67,0 +89,0 @@ let config;

@@ -38,8 +38,14 @@ process.env.ALLOW_CONFIG_MUTATIONS = true;

get: (key, options = { getConfigFromParent: false }) => {
if (options.parentConf) {
if (options.getConfigFromParent) {
return config.get(key);
}
return config.get(`${packagePathToConfigKeyPrefix.get(packagePath)}.${key}`);
},
has: (key, options = { getConfigFromParent: false }) => {
if (options.getConfigFromParent) {
return config.has(key);
}
return config.has(`${packagePathToConfigKeyPrefix.get(packagePath)}.${key}`);
}
};
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc