[fix test] Fix overwritten tests in file-store-test.js
This commit is contained in:
parent
f4f1fdf464
commit
a9c354032b
1 changed files with 32 additions and 30 deletions
|
@ -15,34 +15,36 @@ var fs = require('fs'),
|
||||||
|
|
||||||
vows.describe('nconf/stores/file').addBatch({
|
vows.describe('nconf/stores/file').addBatch({
|
||||||
"When using the nconf file store": {
|
"When using the nconf file store": {
|
||||||
topic: function () {
|
"with a valid JSON file": {
|
||||||
var filePath = path.join(__dirname, '..', 'fixtures', 'store.json');
|
|
||||||
fs.writeFileSync(filePath, JSON.stringify(data, null, 2));
|
|
||||||
store = new nconf.File({ file: filePath });
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
"the load() method": {
|
|
||||||
topic: function () {
|
topic: function () {
|
||||||
store.load(this.callback);
|
var filePath = path.join(__dirname, '..', 'fixtures', 'store.json');
|
||||||
|
fs.writeFileSync(filePath, JSON.stringify(data, null, 2));
|
||||||
|
this.store = store = new nconf.File({ file: filePath });
|
||||||
|
return null;
|
||||||
},
|
},
|
||||||
"should load the data correctly": function (err, data) {
|
"the load() method": {
|
||||||
assert.isNull(err);
|
topic: function () {
|
||||||
assert.deepEqual(data, store.store);
|
this.store.load(this.callback);
|
||||||
|
},
|
||||||
|
"should load the data correctly": function (err, data) {
|
||||||
|
assert.isNull(err);
|
||||||
|
assert.deepEqual(data, this.store.store);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
|
||||||
"When using the nconf file store": {
|
|
||||||
topic: function () {
|
|
||||||
var filePath = path.join(__dirname, '..', 'fixtures', 'malformed.json');
|
|
||||||
store = new nconf.File({ file: filePath });
|
|
||||||
return null;
|
|
||||||
},
|
},
|
||||||
"the load() method with a malformed JSON config file": {
|
"with a malformed JSON file": {
|
||||||
topic: function () {
|
topic: function () {
|
||||||
store.load(this.callback.bind(null, null));
|
var filePath = path.join(__dirname, '..', 'fixtures', 'malformed.json');
|
||||||
|
this.store = new nconf.File({ file: filePath });
|
||||||
|
return null;
|
||||||
},
|
},
|
||||||
"should respond with an error": function (ign, err) {
|
"the load() method with a malformed JSON config file": {
|
||||||
assert.isTrue(!!err);
|
topic: function () {
|
||||||
|
this.store.load(this.callback.bind(null, null));
|
||||||
|
},
|
||||||
|
"should respond with an error": function (_, err) {
|
||||||
|
assert.isTrue(!!err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,19 +59,19 @@ vows.describe('nconf/stores/file').addBatch({
|
||||||
topic: function (tmpStore) {
|
topic: function (tmpStore) {
|
||||||
var that = this;
|
var that = this;
|
||||||
|
|
||||||
Object.keys(store.store).forEach(function (key) {
|
Object.keys(data).forEach(function (key) {
|
||||||
tmpStore.set(key, store.store[key]);
|
tmpStore.set(key, data[key]);
|
||||||
});
|
});
|
||||||
|
|
||||||
tmpStore.save(function () {
|
tmpStore.save(function () {
|
||||||
fs.readFile(tmpStore.file, function (err, data) {
|
fs.readFile(tmpStore.file, function (err, d) {
|
||||||
return err ? that.callback(err) : that.callback(err, JSON.parse(data.toString()));
|
return err ? that.callback(err) : that.callback(err, JSON.parse(d.toString()));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
"should save the data correctly": function (err, data) {
|
"should save the data correctly": function (err, read) {
|
||||||
assert.isNull(err);
|
assert.isNull(err);
|
||||||
assert.deepEqual(data, store.store);
|
assert.deepEqual(read, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue