[fix test] Update nconf.stores.File to respond with an error when loading malformed JSON async

master
indexzero 2011-06-08 00:06:58 -04:00
parent d7495f8373
commit 76db254740
4 changed files with 27 additions and 3 deletions

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
.DS_Store
config.json
test/fixtures/*.json
!test/fixtures/malformed.json
node_modules/
node_modules/*
npm-debug.log

View File

@ -95,9 +95,14 @@ File.prototype.load = function (callback) {
return callback(err);
}
data = self.format.parse(data.toString());
self.store = data;
callback(null, self.store);
try {
self.store = self.format.parse(data.toString());
callback(null, self.store);
}
catch (ex) {
self.store = {};
callback(ex);
}
});
};

View File

@ -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
View File

@ -0,0 +1,3 @@
{
"literal": "bazz",
}