|
@@ -0,0 +1,324 @@
|
|
1
|
+var tape = require("tape"),
|
|
2
|
+ path = require("path"),
|
|
3
|
+ validateSettings = require("../lib/settings/validate-settings.js"),
|
|
4
|
+ validateThemes = require("../lib/settings/validate-themes.js"),
|
|
5
|
+ load = require("../lib/settings/load.js");
|
|
6
|
+
|
|
7
|
+tape("Load test", function(test) {
|
|
8
|
+
|
|
9
|
+ test.throws(function(){
|
|
10
|
+ load("settings/blah.js");
|
|
11
|
+ }, /No .+ file found/);
|
|
12
|
+
|
|
13
|
+ test.throws(function(){
|
|
14
|
+ load("README.md");
|
|
15
|
+ }, /SyntaxError/);
|
|
16
|
+
|
|
17
|
+ test.doesNotThrow(function(){
|
|
18
|
+ load("settings/themes.json");
|
|
19
|
+ });
|
|
20
|
+
|
|
21
|
+ test.doesNotThrow(function(){
|
|
22
|
+ load("settings/index.js");
|
|
23
|
+ });
|
|
24
|
+
|
|
25
|
+ test.end();
|
|
26
|
+
|
|
27
|
+});
|
|
28
|
+
|
|
29
|
+tape("Required fields", function(test) {
|
|
30
|
+
|
|
31
|
+ test.throws(function(){
|
|
32
|
+ validateSettings({});
|
|
33
|
+ }, /settings.workingDirectory is required/);
|
|
34
|
+
|
|
35
|
+ test.throws(function(){
|
|
36
|
+ validateSettings({ workingDirectory: 1 });
|
|
37
|
+ }, /settings.workingDirectory is required/);
|
|
38
|
+
|
|
39
|
+ test.throws(function(){
|
|
40
|
+ validateSettings({ workingDirectory: "" });
|
|
41
|
+ }, /settings.storagePath/);
|
|
42
|
+
|
|
43
|
+ test.throws(function(){
|
|
44
|
+ validateSettings({ workingDirectory: "", storagePath: 1 });
|
|
45
|
+ }, /settings.storagePath/);
|
|
46
|
+
|
|
47
|
+ test.doesNotThrow(function(){
|
|
48
|
+ validateSettings({ workingDirectory: path.join(__dirname), storagePath: path.join(__dirname) });
|
|
49
|
+ }, /settings.storagePath/);
|
|
50
|
+
|
|
51
|
+ test.doesNotThrow(function(){
|
|
52
|
+ validateSettings({ workingDirectory: path.join(__dirname), s3Bucket: "bucket" });
|
|
53
|
+ }, /settings.storagePath/);
|
|
54
|
+
|
|
55
|
+ test.end();
|
|
56
|
+
|
|
57
|
+});
|
|
58
|
+
|
|
59
|
+tape("Max upload size", function(test) {
|
|
60
|
+
|
|
61
|
+ test.throws(function(){
|
|
62
|
+ validateSettings({ workingDirectory: path.join(__dirname), storagePath: path.join(__dirname), maxUploadSize: "a lot" });
|
|
63
|
+ }, /settings.maxUploadSize/);
|
|
64
|
+
|
|
65
|
+ test.end();
|
|
66
|
+
|
|
67
|
+});
|
|
68
|
+
|
|
69
|
+tape("Normalizing paths", function(test) {
|
|
70
|
+
|
|
71
|
+ var relative = validateSettings({
|
|
72
|
+ storagePath: "test/",
|
|
73
|
+ workingDirectory: "test/"
|
|
74
|
+ });
|
|
75
|
+
|
|
76
|
+ var absolute = validateSettings({
|
|
77
|
+ storagePath: path.join(__dirname),
|
|
78
|
+ workingDirectory: path.join(__dirname)
|
|
79
|
+ });
|
|
80
|
+
|
|
81
|
+ var relative2 = validateSettings({
|
|
82
|
+ storagePath: "test",
|
|
83
|
+ workingDirectory: "test"
|
|
84
|
+ });
|
|
85
|
+
|
|
86
|
+ test.equal(path.relative(relative.storagePath, absolute.storagePath), "");
|
|
87
|
+ test.equal(path.relative(relative.workingDirectory, absolute.workingDirectory), "");
|
|
88
|
+ test.equal(path.relative(relative2.storagePath, absolute.storagePath), "");
|
|
89
|
+ test.equal(path.relative(relative2.workingDirectory, absolute.workingDirectory), "");
|
|
90
|
+
|
|
91
|
+ test.end();
|
|
92
|
+
|
|
93
|
+});
|
|
94
|
+
|
|
95
|
+tape("Normalize S3 bucket", function(test) {
|
|
96
|
+
|
|
97
|
+ var settings = validateSettings({
|
|
98
|
+ s3Bucket: "bucket",
|
|
99
|
+ workingDirectory: "test/"
|
|
100
|
+ });
|
|
101
|
+
|
|
102
|
+ test.equal(settings.s3Bucket, "bucket");
|
|
103
|
+ test.equal(settings.storagePath, "");
|
|
104
|
+
|
|
105
|
+ var settings = validateSettings({
|
|
106
|
+ s3Bucket: "s3://bucket",
|
|
107
|
+ workingDirectory: "test/"
|
|
108
|
+ });
|
|
109
|
+
|
|
110
|
+ test.equal(settings.s3Bucket, "bucket");
|
|
111
|
+ test.equal(settings.storagePath, "");
|
|
112
|
+
|
|
113
|
+ settings = validateSettings({
|
|
114
|
+ s3Bucket: "s3://bucket/",
|
|
115
|
+ workingDirectory: "test/"
|
|
116
|
+ });
|
|
117
|
+
|
|
118
|
+ test.equal(settings.s3Bucket, "bucket");
|
|
119
|
+ test.equal(settings.storagePath, "");
|
|
120
|
+
|
|
121
|
+ settings = validateSettings({
|
|
122
|
+ s3Bucket: "s3://bucket/",
|
|
123
|
+ storagePath: "/",
|
|
124
|
+ workingDirectory: "test/"
|
|
125
|
+ });
|
|
126
|
+
|
|
127
|
+ test.equal(settings.s3Bucket, "bucket");
|
|
128
|
+ test.equal(settings.storagePath, "");
|
|
129
|
+
|
|
130
|
+ settings = validateSettings({
|
|
131
|
+ s3Bucket: "s3://bucket/",
|
|
132
|
+ storagePath: "dir",
|
|
133
|
+ workingDirectory: "test/"
|
|
134
|
+ });
|
|
135
|
+
|
|
136
|
+ test.equal(settings.s3Bucket, "bucket");
|
|
137
|
+ test.equal(settings.storagePath, "dir/");
|
|
138
|
+
|
|
139
|
+ settings = validateSettings({
|
|
140
|
+ s3Bucket: "s3://bucket/",
|
|
141
|
+ storagePath: "dir/",
|
|
142
|
+ workingDirectory: "test/"
|
|
143
|
+ });
|
|
144
|
+
|
|
145
|
+ test.equal(settings.s3Bucket, "bucket");
|
|
146
|
+ test.equal(settings.storagePath, "dir/");
|
|
147
|
+
|
|
148
|
+ settings = validateSettings({
|
|
149
|
+ s3Bucket: "s3://bucket/",
|
|
150
|
+ storagePath: "/dir/",
|
|
151
|
+ workingDirectory: "test/"
|
|
152
|
+ });
|
|
153
|
+
|
|
154
|
+ test.equal(settings.s3Bucket, "bucket");
|
|
155
|
+ test.equal(settings.storagePath, "dir/");
|
|
156
|
+
|
|
157
|
+ test.end();
|
|
158
|
+
|
|
159
|
+});
|
|
160
|
+
|
|
161
|
+tape("Fonts", function(test) {
|
|
162
|
+
|
|
163
|
+ test.throws(function(){
|
|
164
|
+ validateSettings({
|
|
165
|
+ s3Bucket: "bucket",
|
|
166
|
+ workingDirectory: "test/",
|
|
167
|
+ fonts: 1
|
|
168
|
+ });
|
|
169
|
+ }, /settings.fonts/);
|
|
170
|
+
|
|
171
|
+ test.throws(function(){
|
|
172
|
+ validateSettings({
|
|
173
|
+ s3Bucket: "bucket",
|
|
174
|
+ workingDirectory: "test/",
|
|
175
|
+ fonts: {}
|
|
176
|
+ });
|
|
177
|
+ }, /settings.fonts/);
|
|
178
|
+
|
|
179
|
+ doesWarn(test, function(){
|
|
180
|
+ validateSettings({
|
|
181
|
+ s3Bucket: "bucket",
|
|
182
|
+ workingDirectory: "test/",
|
|
183
|
+ fonts: [
|
|
184
|
+ {}
|
|
185
|
+ ]
|
|
186
|
+ });
|
|
187
|
+ }, /settings.fonts.+missing/);
|
|
188
|
+
|
|
189
|
+ doesWarn(test, function(){
|
|
190
|
+ validateSettings({
|
|
191
|
+ s3Bucket: "bucket",
|
|
192
|
+ workingDirectory: "test/",
|
|
193
|
+ fonts: [
|
|
194
|
+ { family: "" }
|
|
195
|
+ ]
|
|
196
|
+ });
|
|
197
|
+ }, /settings.fonts.+missing/);
|
|
198
|
+
|
|
199
|
+ doesWarn(test, function(){
|
|
200
|
+ validateSettings({
|
|
201
|
+ s3Bucket: "bucket",
|
|
202
|
+ workingDirectory: "test/",
|
|
203
|
+ fonts: [
|
|
204
|
+ { file: "" }
|
|
205
|
+ ]
|
|
206
|
+ });
|
|
207
|
+ }, /settings.fonts.+missing/);
|
|
208
|
+
|
|
209
|
+ doesWarn(test, function(){
|
|
210
|
+ validateSettings({
|
|
211
|
+ s3Bucket: "bucket",
|
|
212
|
+ workingDirectory: "test/",
|
|
213
|
+ fonts: [
|
|
214
|
+ { file: "notarealfont.ttf", family: "fake" }
|
|
215
|
+ ]
|
|
216
|
+ });
|
|
217
|
+ }, /Font file.+does not exist/);
|
|
218
|
+
|
|
219
|
+ doesNotWarn(test, function(){
|
|
220
|
+ validateSettings({
|
|
221
|
+ s3Bucket: "bucket",
|
|
222
|
+ workingDirectory: "test/",
|
|
223
|
+ fonts: [
|
|
224
|
+ { file: "settings/fonts/SourceSansPro-Light.ttf", family: "Source Sans Pro" },
|
|
225
|
+ { file: path.join(__dirname, "..", "settings/fonts/SourceSansPro-Bold.ttf"), family: "Source Sans Pro", weight: "bold" }
|
|
226
|
+ ]
|
|
227
|
+ });
|
|
228
|
+ });
|
|
229
|
+
|
|
230
|
+ test.end();
|
|
231
|
+
|
|
232
|
+});
|
|
233
|
+
|
|
234
|
+tape("Themes", function(test) {
|
|
235
|
+
|
|
236
|
+ doesWarn(test, function(){
|
|
237
|
+ validateThemes({});
|
|
238
|
+ }, /No themes/);
|
|
239
|
+
|
|
240
|
+ doesWarn(test, function(){
|
|
241
|
+ validateThemes([]);
|
|
242
|
+ }, /No themes/);
|
|
243
|
+
|
|
244
|
+ doesWarn(test, function(){
|
|
245
|
+ validateThemes({ "default": {} });
|
|
246
|
+ }, /No themes/);
|
|
247
|
+
|
|
248
|
+ doesNotWarn(test, function(){
|
|
249
|
+ validateThemes({ "default": { width: 0, height: 0, framesPerSecond: 0, samplesPerFrame: 0 }, "theme": {} });
|
|
250
|
+ });
|
|
251
|
+
|
|
252
|
+ doesNotWarn(test, function(){
|
|
253
|
+ validateThemes({ "default": { framesPerSecond: 0, samplesPerFrame: 0 }, "theme": { width: 0, height: 0 } });
|
|
254
|
+ });
|
|
255
|
+
|
|
256
|
+ doesWarn(test, function(){
|
|
257
|
+ validateThemes({ "default": { height: 0, framesPerSecond: 0, samplesPerFrame: 0 }, "theme": {} });
|
|
258
|
+ }, /required property 'width'/);
|
|
259
|
+
|
|
260
|
+ doesWarn(test, function(){
|
|
261
|
+ validateThemes({ "default": { width: 0, framesPerSecond: 0, samplesPerFrame: 0 }, "theme": {} });
|
|
262
|
+ }, /required property 'height'/);
|
|
263
|
+
|
|
264
|
+ doesWarn(test, function(){
|
|
265
|
+ validateThemes({ "default": { width: 0, height: 0, samplesPerFrame: 0 }, "theme": {} });
|
|
266
|
+ }, /required property 'framesPerSecond'/);
|
|
267
|
+
|
|
268
|
+ doesWarn(test, function(){
|
|
269
|
+ validateThemes({ "default": { width: 0, height: 0, framesPerSecond: 0 }, "theme": {} });
|
|
270
|
+ }, /required property 'samplesPerFrame'/);
|
|
271
|
+
|
|
272
|
+ doesWarn(test, function(){
|
|
273
|
+ validateThemes({ "default": { width: 0, height: 0, framesPerSecond: 0, samplesPerFrame: 0 }, "theme": { backgroundImage: "doesnotexist.jpg" } });
|
|
274
|
+ }, /Background image.+does not exist/);
|
|
275
|
+
|
|
276
|
+ doesNotWarn(test, function(){
|
|
277
|
+ validateThemes({ "default": { width: 0, height: 0, framesPerSecond: 0, samplesPerFrame: 0 }, "theme": { backgroundImage: "subway.jpg" } });
|
|
278
|
+ });
|
|
279
|
+
|
|
280
|
+ doesNotWarn(test, function(){
|
|
281
|
+ validateThemes({ "default": { width: 0, height: 0, framesPerSecond: 0, samplesPerFrame: 0 }, "theme": { backgroundImage: path.join(__dirname, "..", "settings/backgrounds/subway.jpg") } });
|
|
282
|
+ });
|
|
283
|
+
|
|
284
|
+ test.end();
|
|
285
|
+
|
|
286
|
+});
|
|
287
|
+
|
|
288
|
+function doesNotWarn(test, fn) {
|
|
289
|
+ doesWarn(test, fn, "");
|
|
290
|
+}
|
|
291
|
+
|
|
292
|
+function doesWarn(test, fn, regexp) {
|
|
293
|
+
|
|
294
|
+ var output = capture();
|
|
295
|
+
|
|
296
|
+ fn();
|
|
297
|
+
|
|
298
|
+ if (arguments.length > 2) {
|
|
299
|
+ if (typeof regexp === "string") {
|
|
300
|
+ test.equal(output(), regexp);
|
|
301
|
+ } else {
|
|
302
|
+ test.assert(regexp.test(output()));
|
|
303
|
+ }
|
|
304
|
+ } else {
|
|
305
|
+ test.assert(output().length);
|
|
306
|
+ }
|
|
307
|
+
|
|
308
|
+}
|
|
309
|
+
|
|
310
|
+function capture(){
|
|
311
|
+
|
|
312
|
+ var write = process.stderr.write,
|
|
313
|
+ out = "";
|
|
314
|
+
|
|
315
|
+ process.stderr.write = function(str) {
|
|
316
|
+ out += str;
|
|
317
|
+ };
|
|
318
|
+
|
|
319
|
+ return function(){
|
|
320
|
+ process.stderr.write = write;
|
|
321
|
+ return out;
|
|
322
|
+ }
|
|
323
|
+
|
|
324
|
+}
|