-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
156 lines (126 loc) · 4.34 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
'use strict';
require('mocha');
var path = require('path');
var assert = require('assert');
require('assert-fs')(assert);
var utils = require('./utils');
var Answer = require('./');
var answer;
var dir = utils.resolveDir('~/answers');
function json(filename) {
return require(path.resolve(dir, filename));
}
describe('answer-store', function() {
beforeEach(function() {
answer = new Answer('answer-store-test');
});
afterEach(function() {
answer.erase();
});
describe('instance', function() {
it('should create an instance of Answer', function() {
assert(answer instanceof Answer);
});
it('should expose a "data" property', function() {
assert(answer.data);
assert.equal(typeof answer.data, 'object');
});
it('should expose a "set" method', function() {
assert(answer.data);
assert.equal(typeof answer.set, 'function');
});
it('should expose a "get" method', function() {
assert(answer.data);
assert.equal(typeof answer.get, 'function');
});
it('should expose a "del" method', function() {
assert(answer.data);
assert.equal(typeof answer.del, 'function');
});
it('should expose a "has" method', function() {
assert(answer.data);
assert.equal(typeof answer.has, 'function');
});
});
describe('cwd', function() {
it('should use process.cwd() by default', function() {
assert.equal(answer.cwd, process.cwd());
});
it('should use cwd defined on the constructor options', function() {
answer = new Answer('answer-store-test', {cwd: 'foo'})
assert.equal(answer.cwd, 'foo');
});
it('should update the cwd when directly defined', function() {
answer = new Answer('answer-store-test', {cwd: 'foo'});
answer.cwd = 'bar';
assert.equal(answer.cwd, 'bar');
});
});
describe('set', function() {
beforeEach(function() {
answer = new Answer('answer-store-test', {debug: true});
});
it('should create the `~/answers` directory when an answer is set', function() {
answer.set('foo');
assert.existsSync(utils.resolveDir('~/answers'));
});
it('should create an answer store in the default directory', function() {
answer.set('foo');
assert.existsSync(utils.resolveDir('~/answers/answer-store-test.json'));
});
it('should set a value on [locale][cwd]', function() {
answer.set('foo');
assert(answer.data.locales.en[answer.name]);
});
it('should set a value on the default locale, "en"', function() {
answer.set('foo');
assert(answer.data.locales.en[answer.name]);
});
it('should set a value on the specified locale', function() {
answer.set('bar', 'es');
assert(answer.data.locales.es[answer.name]);
assert.equal(answer.data.locales.es[answer.name], 'bar');
});
});
describe('has', function() {
beforeEach(function() {
answer = new Answer('answer-store-test', {debug: true});
});
it('should return true if a value has been set for the cwd', function() {
answer.set('foo');
assert(answer.has());
});
it('should return true if a value has been set for the default locale', function() {
answer.set('foo');
assert(answer.has());
});
it('should return true if a default value has been set', function() {
answer.set('foo');
answer.setDefault('bar');
assert(answer.hasDefault());
});
it('should return false if a default value has not been set', function() {
answer.set('foo');
assert(!answer.hasDefault());
});
it('should return false if a value has not been set for the default locale', function() {
assert(!answer.has());
});
it('should return true if a value has been set for the given locale', function() {
answer.set('foo', 'es');
assert(answer.has('es'));
});
it('should return false if a value has not been set for the given locale', function() {
answer.set('foo');
assert(!answer.has('es'));
});
it('should return true if a default value has been set for a locale', function() {
answer.setDefault('bar', 'es');
assert(answer.hasDefault('es'));
});
it('should return false if a default value has not been set for a locale', function() {
answer.setDefault('baz');
assert(!answer.hasDefault('es'));
});
});
});