From 6c1eb5e917e38cb79dfd83cda5693b7a68979905 Mon Sep 17 00:00:00 2001 From: midknight41 Date: Sat, 26 Oct 2013 20:40:12 +0100 Subject: [PATCH] fixed white spacing and added (embarrassing absent) variable declarations --- lib/nconf/stores/file.js | 18 ++++---- test/stores/file-store-test.js | 80 +++++++++++++++++----------------- 2 files changed, 49 insertions(+), 49 deletions(-) diff --git a/lib/nconf/stores/file.js b/lib/nconf/stores/file.js index b4c31f1..6c1a56f 100644 --- a/lib/nconf/stores/file.js +++ b/lib/nconf/stores/file.js @@ -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 + '].'); diff --git a/test/stores/file-store-test.js b/test/stores/file-store-test.js index e2f068f..c83943f 100644 --- a/test/stores/file-store-test.js +++ b/test/stores/file-store-test.js @@ -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({