-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c13d71
commit f985831
Showing
17 changed files
with
1,435 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
extends: "airbnb/base" | ||
|
||
env: | ||
node: true | ||
mocha: true | ||
|
||
ecmaFeatures: | ||
modules: false | ||
|
||
rules: | ||
strict: [2, global] | ||
no-param-reassign: 0 | ||
no-shadow: 1 | ||
comma-dangle: [2, never] | ||
no-unused-vars: 1 | ||
space-before-function-paren: 0 | ||
new-cap: 0 | ||
eol-last: 0 | ||
|
||
# Node Rules | ||
no-new-require: 2 | ||
no-path-concat: 2 | ||
no-process-exit: 2 | ||
no-sync: 2 | ||
no-mixed-requires: 1 | ||
callback-return: 0 | ||
handle-callback-err: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const { exec } = require('child_process'); | ||
const { expect } = require('chai'); | ||
const { developmentConfigPath } = require('./fixtures/paths'); | ||
|
||
describe('configuration', () => { | ||
describe('nconf options', () => { | ||
it('should faciliate nconf `.env()` options', function(done) { | ||
exec( | ||
`echo " | ||
const appfig = require('./'); | ||
const config = appfig('${developmentConfigPath}', { | ||
nconf: { | ||
env: { | ||
whitelist: ['NODE_ENV'] | ||
} | ||
} | ||
}); | ||
console.log(config.get('NODE_ENV')); | ||
console.log(config.get('OTHER_ENV')); | ||
" | NODE_ENV=dev OTHER_ENV=true node`, | ||
(err, stdout, stderr) => { | ||
expect(stdout).to.match(/^dev\sundefined\s$/); | ||
done(); | ||
} | ||
); | ||
}); | ||
|
||
it('should faciliate nconf `.argv()` options', function(done) { | ||
exec( | ||
`echo " | ||
const appfig = require('./'); | ||
const config = appfig('${developmentConfigPath}', { | ||
nconf: { | ||
argv: { | ||
foo: { | ||
default: 'bar' | ||
} | ||
} | ||
} | ||
}); | ||
console.log(config.get('foo')); | ||
" | node`, | ||
(err, stdout, stderr) => { | ||
expect(stdout).to.match(/^bar\s$/); | ||
done(); | ||
} | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const path = require('path'); | ||
const { expect } = require('chai'); | ||
const appfig = require('../'); | ||
|
||
const { | ||
developmentConfigPath, | ||
orphanedConfigPath, | ||
invalidConfigPath | ||
} = require('./fixtures/paths'); | ||
|
||
describe('errors', () => { | ||
describe('file error handling', () => { | ||
it('should throw an exception when dependent file cannot be found', () => { | ||
const errorMessage = `Parent config "non-existent" not found for child ${orphanedConfigPath}`; | ||
expect(appfig.bind(null, orphanedConfigPath)).to.throw(errorMessage); | ||
}); | ||
|
||
it('should throw an exception when a file is not valid JSON', () => { | ||
const errorMessage = `Config file "${invalidConfigPath}" invalid JSON`; | ||
expect(appfig.bind(null, invalidConfigPath)).to.throw(errorMessage); | ||
}); | ||
}); | ||
|
||
describe('options error handling', () => { | ||
it('should not throw validation exception when `options.configDirPath` is not provided', () => { | ||
expect(appfig.bind(null, developmentConfigPath)).to.not.throw(); | ||
}); | ||
|
||
it('should throw validation exception when `options.configDirPath` is provided and is not a absolute path', () => { | ||
expect( | ||
appfig.bind(null, developmentConfigPath, { | ||
configDirPath: 'not/absolute/path' | ||
}) | ||
).to.throw( | ||
'Optional configuration `options.configDirPath` must be an absolute path when provided.' | ||
); | ||
}); | ||
|
||
it('should not throw validation exception when `options.configDirPath` is an absolute path', () => { | ||
expect( | ||
appfig.bind(null, developmentConfigPath, { | ||
configDirPath: path.join(__dirname, './fixtures/config') | ||
}) | ||
).to.not.throw(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "base", | ||
"base": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "intermediary", | ||
"name": "development", | ||
"development": true, | ||
"foo": { | ||
"bar": "baa" | ||
}, | ||
"recurp": "${foo.bar}-baz" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"extends": "base", | ||
"name": "intermediary", | ||
"intermediary": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"some: "invalid json" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "non-existent" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const path = require('path'); | ||
|
||
module.exports = { | ||
baseConfigPath: path.join(__dirname, 'config/base.json'), | ||
developmentConfigPath: path.join(__dirname, 'config/development.json'), | ||
invalidConfigPath: path.join(__dirname, 'config/invalid.json'), | ||
orphanedConfigPath: path.join(__dirname, 'config/orphaned.json'), | ||
secondaryConfigPath: path.join(__dirname, 'secondary.json') | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"extends": "./config/base", | ||
"name": "other", | ||
"other": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const { exec } = require('child_process'); | ||
const { expect } = require('chai'); | ||
const appfig = require('../'); | ||
|
||
const { baseConfigPath, developmentConfigPath, secondaryConfigPath } = require('./fixtures/paths'); | ||
|
||
describe('loading', () => { | ||
it('should load configuration files', () => { | ||
const config = appfig(baseConfigPath); | ||
|
||
expect(config.get('name')).to.equal('base'); | ||
}); | ||
|
||
it('should load configuration files from varying locations', () => { | ||
const config = appfig(secondaryConfigPath); | ||
|
||
expect(config.get('name')).to.equal('other'); | ||
expect(config.get('other')).to.be.true; | ||
expect(config.get('base')).to.be.true; | ||
}); | ||
|
||
it('should load shell environment variables', function(done) { | ||
exec( | ||
`echo " | ||
const appfig = require('./'); | ||
const config = appfig('${developmentConfigPath}'); | ||
console.log(config.get('FOO')); | ||
" | FOO=envbar node`, | ||
(err, stdout, stderr) => { | ||
expect(stdout).to.match(/^envbar\s$/); | ||
done(); | ||
} | ||
); | ||
}); | ||
|
||
it('should load command arguments', function(done) { | ||
exec( | ||
`echo " | ||
const appfig = require('./'); | ||
const config = appfig('${developmentConfigPath}'); | ||
console.log(config.get('FOO')); | ||
" | node - --FOO=argvbar`, | ||
(err, stdout, stderr) => { | ||
expect(stdout).to.match(/^argvbar\s$/); | ||
done(); | ||
} | ||
); | ||
}); | ||
}); |
Oops, something went wrong.