fixed white spacing and added (embarrassing absent) variable declarations

master
midknight41 2013-10-26 20:40:12 +01:00
parent ccd609c1c3
commit 6c1eb5e917
2 changed files with 49 additions and 49 deletions

View File

@ -97,11 +97,11 @@ File.prototype.load = function (callback) {
}
try {
//deals with string that include BOM
stringData = data.toString();
//deals with string that include BOM
var stringData = data.toString();
if (stringData.charAt(0) === '\uFEFF') stringData = stringData.substr(1);
self.store = self.format.parse(stringData);
if (stringData.charAt(0) === '\uFEFF') stringData = stringData.substr(1);
self.store = self.format.parse(stringData);
}
catch (ex) {
@ -130,12 +130,12 @@ File.prototype.loadSync = function () {
// Else, the path exists, read it from disk
//
try {
//deals with file that include BOM
fileData = fs.readFileSync(this.file, 'utf8');
if (fileData.charAt(0) === '\uFEFF') fileData = fileData.substr(1);
//deals with file that include BOM
var fileData = fs.readFileSync(this.file, 'utf8');
if (fileData.charAt(0) === '\uFEFF') fileData = fileData.substr(1);
data = this.format.parse(fileData);
this.store = data;
data = this.format.parse(fileData);
this.store = data;
}
catch (ex) {
throw new Error("Error parsing your JSON configuration file: [" + self.file + '].');

View File

@ -49,54 +49,54 @@ vows.describe('nconf/stores/file').addBatch({
}
},
"with a valid UTF8 JSON file that contains a BOM": {
topic: function () {
var filePath = path.join(__dirname, '..', 'fixtures', 'bom.json');
this.store = store = new nconf.File({ file: filePath });
return null;
},
"the load() method": {
topic: function () {
var filePath = path.join(__dirname, '..', 'fixtures', 'bom.json');
this.store = store = new nconf.File({ file: filePath });
return null;
this.store.load(this.callback);
},
"the load() method": {
topic: function () {
this.store.load(this.callback);
},
"should load the data correctly": function (err, data) {
assert.isNull(err);
assert.deepEqual(data, this.store.store);
}
},
"the loadSync() method": {
topic: function () {
var data = this.store.loadSync();
return data;
},
"should load the data correctly": function (result) {
assert.deepEqual(result, this.store.store);
}
"should load the data correctly": function (err, data) {
assert.isNull(err);
assert.deepEqual(data, this.store.store);
}
},
"the loadSync() method": {
topic: function () {
var data = this.store.loadSync();
return data;
},
"should load the data correctly": function (result) {
assert.deepEqual(result, this.store.store);
}
}
},
"with a valid UTF8 JSON file that contains no BOM": {
topic: function () {
var filePath = path.join(__dirname, '..', 'fixtures', 'no-bom.json');
this.store = store = new nconf.File({ file: filePath });
return null;
},
"the load() method": {
topic: function () {
var filePath = path.join(__dirname, '..', 'fixtures', 'no-bom.json');
this.store = store = new nconf.File({ file: filePath });
return null;
this.store.load(this.callback);
},
"the load() method": {
topic: function () {
this.store.load(this.callback);
},
"should load the data correctly": function (err, data) {
assert.isNull(err);
assert.deepEqual(data, this.store.store)
}
},
"the loadSync() method": {
topic: function () {
var data = this.store.loadSync();
return data;
},
"should load the data correctly": function (result) {
assert.deepEqual(result, this.store.store);
}
"should load the data correctly": function (err, data) {
assert.isNull(err);
assert.deepEqual(data, this.store.store);
}
},
"the loadSync() method": {
topic: function () {
var data = this.store.loadSync();
return data;
},
"should load the data correctly": function (result) {
assert.deepEqual(result, this.store.store);
}
}
}
}
}).addBatch({