Skip to content
This repository has been archived by the owner on Jul 18, 2021. It is now read-only.

Commit

Permalink
Replaced deprecated fs.existsSync() call by fs.accessSync();
Browse files Browse the repository at this point in the history
Updated dependencies;
Updated unit test to match latest `shouldjs` API;
  • Loading branch information
Pavel Lobodinský committed Jun 17, 2016
1 parent 6a98b5d commit 4c0615a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 22 deletions.
6 changes: 6 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 1.0.0 / 2016-06-17

* Replaced deprecated `fs.existsSync()` call by `fs.accessSync()`. `fs.existsSync()` was deprecated since Node.js v1.0.0.
* Updated `mocha` and `should` dependencies
* Proven stable enough to be finally called version 1.0.0

# 0.1.5 / 2016-04-09

* Updated to latest package versions
Expand Down
13 changes: 9 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var LOG = process.env.NODE_CONFIG_LOG !== undefined;
* SYNCHRONOUSLY fetches all environments available. Generally, returns the list of sub-directories under the CONFIG_DIR.
* @returns {Array} List of environments available or an empty array in case there is no environment sub-directory
*/
function getEnvs() {
function getEnvs() {
if (LOG)
console.info('Reading environments available in', path.resolve(CONFIG_DIR));

Expand Down Expand Up @@ -84,9 +84,14 @@ function getConfigs(env) {


// check for non-existence of configuration directory
if (!fs.existsSync(CONFIG_DIR)) {
if (LOG || HALT) // always print the error if halting the app
console.error('Configuration directory for the app is missing. Expected location is', CONFIG_DIR);
try {
fs.accessSync(CONFIG_DIR, fs.R_OK);
}
catch (e) {
if (LOG || HALT) { // always print the error if halting the app
console.error('Configuration directory for the app is either missing or non-readable. Expected location is', CONFIG_DIR);
console.error(e);
}
if (HALT) {
console.error('Halting the app.');
process.exit(-1);
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "app-config",
"version": "0.1.5",
"version": "1.0.0",
"description": "Simple utility for Node.js to load configuration files depending on your environment",
"main": "./index.js",
"scripts": {
Expand All @@ -22,10 +22,13 @@
"bugs": {
"url": "https://github.com/lobodpav/node-app-config/issues?state=open"
},
"engines" : {
"node" : ">=6.1.0"
},
"readmeFilename": "README.md",
"license": "MIT",
"devDependencies": {
"mocha": "~2.4.5",
"should": "~8.3.0"
"mocha": "~2.5.3",
"should": "~9.0.2"
}
}
30 changes: 15 additions & 15 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ describe(modName, function() {
process.env.NODE_ENV = 'blah';

var config = require(modFile);
should(config).equal(null);
should(config).be.equal(null);
});

it('should fail to load configs in non-existing directory', function() {
process.env.NODE_CONFIG_DIR = 'blah';

var config = require(modFile);
should(config).equal(null);
should(config).be.equal(null);
});

it('should fail to load non-existing config for DEV environment in default directory', function() {
Expand All @@ -52,7 +52,7 @@ describe(modName, function() {
process.env.NODE_CONFIG_DIR = processDir + '/config1';

var config = require(modFile);
should(config).equal(null);
should(config).be.equal(null);
});

it('should halt the app on failure', function() {
Expand All @@ -70,12 +70,12 @@ describe(modName, function() {
var warn = console.warn;

// mock the process.exit() function to catch its call
process.exit = function(code) {
process.exit = function() {
halted = true;
}
};

// mocks to suppress logging attempts when HATL is being enabled
console.error = console.info = console.warn = function() {}
console.error = console.info = console.warn = function() {};


require(modFile);
Expand All @@ -87,15 +87,15 @@ describe(modName, function() {
console.info = info;
console.warn = warn;

halted.should.be.true;
halted.should.be.true();
});

it('should not halt the app on failure', function() {
// set the environment to non-existing one to cause an error
process.env.NODE_ENV = 'blah';

var config = require(modFile);
should(config).equal(null);
should(config).be.equal(null);
});
});

Expand All @@ -107,8 +107,8 @@ describe(modName, function() {

config = config.db;
should.exist(config);
config.should.be.an.Object;
config.should.have.a.property('dbURI', 'mongodb://localhost:27017/dev-db');
config.should.be.an.Object();
config.should.have.property('dbURI', 'mongodb://localhost:27017/dev-db');
});

it('should load LOG config for PROD environment in default directory', function() {
Expand All @@ -118,7 +118,7 @@ describe(modName, function() {

config = config.log;
should.exist(config);
config.should.be.an.Object;
config.should.be.an.Object();
config.should.have.properties('fileLogConfig', 'consoleLogConfig');
config.fileLogConfig.should.have.property('filename', '/var/log/server-prod.log');
config.consoleLogConfig.should.have.property('level', 'error');
Expand All @@ -132,8 +132,8 @@ describe(modName, function() {

config = config.db;
should.exist(config);
config.should.be.an.Object;
config.should.have.a.property('dbURI', 'mongodb://localhost:27017/dev-db-config1');
config.should.be.an.Object();
config.should.have.property('dbURI', 'mongodb://localhost:27017/dev-db-config1');
});

it('should print out log information', function() {
Expand All @@ -155,7 +155,7 @@ describe(modName, function() {
console.info = info;
console.warn = warn;

log.should.be.true;
log.should.be.true();
});

it('should not print out log information', function() {
Expand All @@ -173,7 +173,7 @@ describe(modName, function() {
console.error = err;
console.info = info;

log.should.be.false;
log.should.be.false();
});

it('should reload config files when `app-config` is deleted from `require.cache`', function() {
Expand Down

0 comments on commit 4c0615a

Please sign in to comment.