/
test.js
56 lines (47 loc) · 1.31 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
'use strict';
var assert = require('assert');
var fs = require('fs');
var pathExists = require('path-exists');
var Configstore = require('./');
var configstorePath = new Configstore('configstore-test').path;
beforeEach(function () {
fs.unlinkSync(configstorePath);
this.conf = new Configstore('configstore-test');
});
it('.set() and .get()', function () {
this.conf.set('foo', 'bar');
assert.equal(this.conf.get('foo'), 'bar');
});
it('.del()', function () {
this.conf.set('foo', 'bar');
this.conf.del('foo');
assert.notEqual(this.conf.get('foo'), 'bar');
});
it('.clear()', function(){
this.conf.set('foo', 'bar');
this.conf.set('foo1', 'bar1');
this.conf.clear();
assert.equal(this.conf.size, 0);
});
it('.all', function () {
this.conf.set('foo', 'bar');
assert.equal(this.conf.all.foo, 'bar');
});
it('.size', function () {
this.conf.set('foo', 'bar');
assert.equal(this.conf.size, 1);
});
it('.path', function () {
this.conf.set('foo', 'bar');
assert(pathExists.sync(this.conf.path));
});
it('should use default value', function () {
var conf = new Configstore('configstore-test', {foo: 'bar'});
assert.equal(conf.get('foo'), 'bar');
});
it('make sure `.all` is always an object', function () {
fs.unlinkSync(configstorePath);
assert.doesNotThrow(function () {
this.conf.get('foo')
}.bind(this));
});