[fix test] Update nconf.stores.File to respond with an error when loading malformed JSON async
This commit is contained in:
parent
d7495f8373
commit
76db254740
4 changed files with 27 additions and 3 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,6 +1,7 @@
|
|||
.DS_Store
|
||||
config.json
|
||||
test/fixtures/*.json
|
||||
!test/fixtures/malformed.json
|
||||
node_modules/
|
||||
node_modules/*
|
||||
npm-debug.log
|
|
@ -95,9 +95,14 @@ File.prototype.load = function (callback) {
|
|||
return callback(err);
|
||||
}
|
||||
|
||||
data = self.format.parse(data.toString());
|
||||
self.store = data;
|
||||
try {
|
||||
self.store = self.format.parse(data.toString());
|
||||
callback(null, self.store);
|
||||
}
|
||||
catch (ex) {
|
||||
self.store = {};
|
||||
callback(ex);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -30,6 +30,21 @@ vows.describe('nconf/stores/file').addBatch({
|
|||
assert.deepEqual(data, store.store);
|
||||
}
|
||||
}
|
||||
},
|
||||
"When using the nconf file store": {
|
||||
topic: function () {
|
||||
var filePath = path.join(__dirname, 'fixtures', 'malformed.json');
|
||||
store = new nconf.stores.File({ file: filePath });
|
||||
return null;
|
||||
},
|
||||
"the load() method with a malformed JSON config file": {
|
||||
topic: function () {
|
||||
store.load(this.callback.bind(null, null));
|
||||
},
|
||||
"should respond with an error": function (ign, err) {
|
||||
console.dir(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).addBatch({
|
||||
"When using the nconf file store": {
|
||||
|
|
3
test/fixtures/malformed.json
vendored
Normal file
3
test/fixtures/malformed.json
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"literal": "bazz",
|
||||
}
|
Loading…
Reference in a new issue