source: trip-planner-front/node_modules/streamroller/test/fileNameFormatter-test.js@ b738035

Last change on this file since b738035 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 15.7 KB
RevLine 
[6a3a178]1require("should");
2const { normalize } = require("path");
3
4describe("fileNameFormatter", () => {
5 describe("without a date", () => {
6 const fileNameFormatter = require("../lib/fileNameFormatter")({
7 file: {
8 dir: "/path/to/file",
9 base: "thefile.log",
10 ext: ".log",
11 name: "thefile"
12 }
13 });
14 it("should take an index and return a filename", () => {
15 fileNameFormatter({
16 index: 0
17 }).should.eql(normalize("/path/to/file/thefile.log"));
18 fileNameFormatter({ index: 1, date: "" }).should.eql(
19 normalize("/path/to/file/thefile.log.1")
20 );
21 fileNameFormatter({ index: 15, date: undefined }).should.eql(
22 normalize("/path/to/file/thefile.log.15")
23 );
24 fileNameFormatter({ index: 15 }).should.eql(
25 normalize("/path/to/file/thefile.log.15")
26 );
27 });
28 });
29
30 describe("with a date", () => {
31 const fileNameFormatter = require("../lib/fileNameFormatter")({
32 file: {
33 dir: "/path/to/file",
34 base: "thefile.log",
35 ext: ".log",
36 name: "thefile"
37 }
38 });
39 it("should take an index, date and return a filename", () => {
40 fileNameFormatter({ index: 0, date: "2019-07-15" }).should.eql(
41 normalize("/path/to/file/thefile.log")
42 );
43 fileNameFormatter({
44 index: 2,
45 date: "2019-07-16"
46 }).should.eql(normalize("/path/to/file/thefile.log.2019-07-16"));
47 });
48 });
49
50 describe("with the alwaysIncludeDate option", () => {
51 const fileNameFormatter = require("../lib/fileNameFormatter")({
52 file: {
53 dir: "/path/to/file",
54 base: "thefile.log",
55 ext: ".log",
56 name: "thefile"
57 },
58 alwaysIncludeDate: true
59 });
60 it("should take an index, date and return a filename", () => {
61 fileNameFormatter({
62 index: 0,
63 date: "2019-07-15"
64 }).should.eql(normalize("/path/to/file/thefile.log.2019-07-15"));
65 fileNameFormatter({ index: 0, date: "2019-07-15" }).should.eql(
66 normalize("/path/to/file/thefile.log.2019-07-15")
67 );
68 fileNameFormatter({
69 index: 2,
70 date: "2019-07-16"
71 }).should.eql(normalize("/path/to/file/thefile.log.2019-07-16"));
72 });
73 });
74
75 describe("with the keepFileExt option", () => {
76 const fileNameFormatter = require("../lib/fileNameFormatter")({
77 file: {
78 dir: "/path/to/file",
79 base: "thefile.log",
80 ext: ".log",
81 name: "thefile"
82 },
83 keepFileExt: true
84 });
85 it("should take an index, date and return a filename", () => {
86 fileNameFormatter({
87 index: 0,
88 date: "2019-07-15"
89 }).should.eql(normalize("/path/to/file/thefile.log"));
90 fileNameFormatter({ index: 1 }).should.eql(normalize("/path/to/file/thefile.1.log"));
91 fileNameFormatter({ index: 2 }).should.eql(normalize("/path/to/file/thefile.2.log"));
92 fileNameFormatter({ index: 15 }).should.eql(
93 normalize("/path/to/file/thefile.15.log")
94 );
95 });
96 });
97
98 describe("with the keepFileExt option and a date", () => {
99 const fileNameFormatter = require("../lib/fileNameFormatter")({
100 file: {
101 dir: "/path/to/file",
102 base: "thefile.log",
103 ext: ".log",
104 name: "thefile"
105 },
106 keepFileExt: true
107 });
108 it("should take an index, date and return a filename", () => {
109 fileNameFormatter({
110 index: 0,
111 date: "2019-07-15"
112 }).should.eql(normalize("/path/to/file/thefile.log"));
113 fileNameFormatter({ index: 1, date: "2019-07-15" }).should.eql(
114 normalize("/path/to/file/thefile.2019-07-15.log")
115 );
116 fileNameFormatter({
117 index: 2,
118 date: "2019-07-16"
119 }).should.eql(normalize("/path/to/file/thefile.2019-07-16.log"));
120 });
121 });
122
123 describe("with the keepFileExt, alwaysIncludeDate options", () => {
124 const fileNameFormatter = require("../lib/fileNameFormatter")({
125 file: {
126 dir: "/path/to/file",
127 base: "thefile.log",
128 ext: ".log",
129 name: "thefile"
130 },
131 keepFileExt: true,
132 alwaysIncludeDate: true
133 });
134 it("should take an index, date and return a filename", () => {
135 fileNameFormatter({
136 index: 0,
137 date: "2019-07-15"
138 }).should.eql(normalize("/path/to/file/thefile.2019-07-15.log"));
139 fileNameFormatter({ index: 1, date: "2019-07-15" }).should.eql(
140 normalize("/path/to/file/thefile.2019-07-15.log")
141 );
142 fileNameFormatter({
143 index: 2,
144 date: "2019-07-16"
145 }).should.eql(normalize("/path/to/file/thefile.2019-07-16.log"));
146 });
147 });
148
149 describe("with the compress option", () => {
150 const fileNameFormatter = require("../lib/fileNameFormatter")({
151 file: {
152 dir: "/path/to/file",
153 base: "thefile.log",
154 ext: ".log",
155 name: "thefile"
156 },
157 compress: true
158 });
159 it("should take an index and return a filename", () => {
160 fileNameFormatter({
161 index: 0,
162 date: "2019-07-15"
163 }).should.eql(normalize("/path/to/file/thefile.log"));
164 fileNameFormatter({ index: 1 }).should.eql(
165 normalize("/path/to/file/thefile.log.1.gz")
166 );
167 fileNameFormatter({
168 index: 2
169 }).should.eql(normalize("/path/to/file/thefile.log.2.gz"));
170 });
171 });
172
173 describe("with the compress option and a date", () => {
174 const fileNameFormatter = require("../lib/fileNameFormatter")({
175 file: {
176 dir: "/path/to/file",
177 base: "thefile.log",
178 ext: ".log",
179 name: "thefile"
180 },
181 compress: true
182 });
183 it("should take an index, date and return a filename", () => {
184 fileNameFormatter({
185 index: 0,
186 date: "2019-07-15"
187 }).should.eql(normalize("/path/to/file/thefile.log"));
188 fileNameFormatter({ index: 1, date: "2019-07-15" }).should.eql(
189 normalize("/path/to/file/thefile.log.2019-07-15.gz")
190 );
191 fileNameFormatter({
192 index: 2,
193 date: "2019-07-16"
194 }).should.eql(normalize("/path/to/file/thefile.log.2019-07-16.gz"));
195 });
196 });
197
198 describe("with the compress, alwaysIncludeDate option and a date", () => {
199 const fileNameFormatter = require("../lib/fileNameFormatter")({
200 file: {
201 dir: "/path/to/file",
202 base: "thefile.log",
203 ext: ".log",
204 name: "thefile"
205 },
206 compress: true,
207 alwaysIncludeDate: true
208 });
209 it("should take an index, date and return a filename", () => {
210 fileNameFormatter({
211 index: 0,
212 date: "2019-07-15"
213 }).should.eql(normalize("/path/to/file/thefile.log.2019-07-15"));
214 fileNameFormatter({ index: 1, date: "2019-07-15" }).should.eql(
215 normalize("/path/to/file/thefile.log.2019-07-15.gz")
216 );
217 fileNameFormatter({
218 index: 2,
219 date: "2019-07-16"
220 }).should.eql(normalize("/path/to/file/thefile.log.2019-07-16.gz"));
221 });
222 });
223
224 describe("with the compress, alwaysIncludeDate, keepFileExt option and a date", () => {
225 const fileNameFormatter = require("../lib/fileNameFormatter")({
226 file: {
227 dir: "/path/to/file",
228 base: "thefile.log",
229 ext: ".log",
230 name: "thefile"
231 },
232 compress: true,
233 alwaysIncludeDate: true,
234 keepFileExt: true
235 });
236 it("should take an index, date and return a filename", () => {
237 fileNameFormatter({
238 index: 0,
239 date: "2019-07-15"
240 }).should.eql(normalize("/path/to/file/thefile.2019-07-15.log"));
241 fileNameFormatter({ index: 1, date: "2019-07-15" }).should.eql(
242 normalize("/path/to/file/thefile.2019-07-15.log.gz")
243 );
244 fileNameFormatter({
245 index: 2,
246 date: "2019-07-16"
247 }).should.eql(normalize("/path/to/file/thefile.2019-07-16.log.gz"));
248 });
249 });
250
251 describe("with the needsIndex option", () => {
252 const fileNameFormatter = require("../lib/fileNameFormatter")({
253 file: {
254 dir: "/path/to/file",
255 base: "thefile.log",
256 ext: ".log",
257 name: "thefile"
258 },
259 compress: true,
260 needsIndex: true,
261 alwaysIncludeDate: true,
262 keepFileExt: true
263 });
264 it("should take an index, date and return a filename", () => {
265 fileNameFormatter({
266 index: 0,
267 date: "2019-07-15"
268 }).should.eql(normalize("/path/to/file/thefile.2019-07-15.log"));
269 fileNameFormatter({ index: 1, date: "2019-07-15" }).should.eql(
270 normalize("/path/to/file/thefile.2019-07-15.1.log.gz")
271 );
272 fileNameFormatter({
273 index: 2,
274 date: "2019-07-16"
275 }).should.eql(normalize("/path/to/file/thefile.2019-07-16.2.log.gz"));
276 });
277 });
278
279 describe("with a date and needsIndex", () => {
280 const fileNameFormatter = require("../lib/fileNameFormatter")({
281 file: {
282 dir: "/path/to/file",
283 base: "thefile.log",
284 ext: ".log",
285 name: "thefile"
286 },
287 needsIndex: true
288 });
289 it("should take an index, date and return a filename", () => {
290 fileNameFormatter({ index: 0, date: "2019-07-15" }).should.eql(
291 normalize("/path/to/file/thefile.log")
292 );
293 fileNameFormatter({
294 index: 2,
295 date: "2019-07-16"
296 }).should.eql(normalize("/path/to/file/thefile.log.2019-07-16.2"));
297 });
298 });
299
300 describe("with the alwaysIncludeDate, needsIndex option", () => {
301 const fileNameFormatter = require("../lib/fileNameFormatter")({
302 file: {
303 dir: "/path/to/file",
304 base: "thefile.log",
305 ext: ".log",
306 name: "thefile"
307 },
308 needsIndex: true,
309 alwaysIncludeDate: true
310 });
311 it("should take an index, date and return a filename", () => {
312 fileNameFormatter({
313 index: 0,
314 date: "2019-07-15"
315 }).should.eql(normalize("/path/to/file/thefile.log.2019-07-15"));
316 fileNameFormatter({ index: 0, date: "2019-07-15" }).should.eql(
317 normalize("/path/to/file/thefile.log.2019-07-15")
318 );
319 fileNameFormatter({
320 index: 2,
321 date: "2019-07-16"
322 }).should.eql(normalize("/path/to/file/thefile.log.2019-07-16.2"));
323 });
324 });
325
326 describe("with the keepFileExt, needsIndex option", () => {
327 const fileNameFormatter = require("../lib/fileNameFormatter")({
328 file: {
329 dir: "/path/to/file",
330 base: "thefile.log",
331 ext: ".log",
332 name: "thefile"
333 },
334 needsIndex: true,
335 keepFileExt: true
336 });
337 it("should take an index, date and return a filename", () => {
338 fileNameFormatter({
339 index: 0,
340 date: "2019-07-15"
341 }).should.eql(normalize("/path/to/file/thefile.log"));
342 fileNameFormatter({ index: 1 }).should.eql(normalize("/path/to/file/thefile.1.log"));
343 fileNameFormatter({ index: 2 }).should.eql(normalize("/path/to/file/thefile.2.log"));
344 fileNameFormatter({ index: 15 }).should.eql(
345 normalize("/path/to/file/thefile.15.log")
346 );
347 });
348 });
349
350 describe("with the keepFileExt, needsIndex option and a date", () => {
351 const fileNameFormatter = require("../lib/fileNameFormatter")({
352 file: {
353 dir: "/path/to/file",
354 base: "thefile.log",
355 ext: ".log",
356 name: "thefile"
357 },
358 needsIndex: true,
359 keepFileExt: true
360 });
361 it("should take an index, date and return a filename", () => {
362 fileNameFormatter({
363 index: 0,
364 date: "2019-07-15"
365 }).should.eql(normalize("/path/to/file/thefile.log"));
366 fileNameFormatter({ index: 1, date: "2019-07-15" }).should.eql(
367 normalize("/path/to/file/thefile.2019-07-15.1.log")
368 );
369 fileNameFormatter({
370 index: 2,
371 date: "2019-07-16"
372 }).should.eql(normalize("/path/to/file/thefile.2019-07-16.2.log"));
373 });
374 });
375
376 describe("with the keepFileExt, needsIndex, alwaysIncludeDate options", () => {
377 const fileNameFormatter = require("../lib/fileNameFormatter")({
378 file: {
379 dir: "/path/to/file",
380 base: "thefile.log",
381 ext: ".log",
382 name: "thefile"
383 },
384 needsIndex: true,
385 keepFileExt: true,
386 alwaysIncludeDate: true
387 });
388 it("should take an index, date and return a filename", () => {
389 fileNameFormatter({
390 index: 0,
391 date: "2019-07-15"
392 }).should.eql(normalize("/path/to/file/thefile.2019-07-15.log"));
393 fileNameFormatter({ index: 1, date: "2019-07-15" }).should.eql(
394 normalize("/path/to/file/thefile.2019-07-15.1.log")
395 );
396 fileNameFormatter({
397 index: 2,
398 date: "2019-07-16"
399 }).should.eql(normalize("/path/to/file/thefile.2019-07-16.2.log"));
400 });
401 });
402
403 describe("with the compress, needsIndex option", () => {
404 const fileNameFormatter = require("../lib/fileNameFormatter")({
405 file: {
406 dir: "/path/to/file",
407 base: "thefile.log",
408 ext: ".log",
409 name: "thefile"
410 },
411 needsIndex: true,
412 compress: true
413 });
414 it("should take an index and return a filename", () => {
415 fileNameFormatter({
416 index: 0,
417 date: "2019-07-15"
418 }).should.eql(normalize("/path/to/file/thefile.log"));
419 fileNameFormatter({ index: 1 }).should.eql(
420 normalize("/path/to/file/thefile.log.1.gz")
421 );
422 fileNameFormatter({
423 index: 2
424 }).should.eql(normalize("/path/to/file/thefile.log.2.gz"));
425 });
426 });
427
428 describe("with the compress, needsIndex option and a date", () => {
429 const fileNameFormatter = require("../lib/fileNameFormatter")({
430 file: {
431 dir: "/path/to/file",
432 base: "thefile.log",
433 ext: ".log",
434 name: "thefile"
435 },
436 needsIndex: true,
437 compress: true
438 });
439 it("should take an index, date and return a filename", () => {
440 fileNameFormatter({
441 index: 0,
442 date: "2019-07-15"
443 }).should.eql(normalize("/path/to/file/thefile.log"));
444 fileNameFormatter({ index: 1, date: "2019-07-15" }).should.eql(
445 normalize("/path/to/file/thefile.log.2019-07-15.1.gz")
446 );
447 fileNameFormatter({
448 index: 2,
449 date: "2019-07-16"
450 }).should.eql(normalize("/path/to/file/thefile.log.2019-07-16.2.gz"));
451 });
452 });
453
454 describe("with the compress, alwaysIncludeDate, needsIndex option and a date", () => {
455 const fileNameFormatter = require("../lib/fileNameFormatter")({
456 file: {
457 dir: "/path/to/file",
458 base: "thefile.log",
459 ext: ".log",
460 name: "thefile"
461 },
462 needsIndex: true,
463 compress: true,
464 alwaysIncludeDate: true
465 });
466 it("should take an index, date and return a filename", () => {
467 fileNameFormatter({
468 index: 0,
469 date: "2019-07-15"
470 }).should.eql(normalize("/path/to/file/thefile.log.2019-07-15"));
471 fileNameFormatter({ index: 1, date: "2019-07-15" }).should.eql(
472 normalize("/path/to/file/thefile.log.2019-07-15.1.gz")
473 );
474 fileNameFormatter({
475 index: 2,
476 date: "2019-07-16"
477 }).should.eql(normalize("/path/to/file/thefile.log.2019-07-16.2.gz"));
478 });
479 });
480
481 describe("with the compress, alwaysIncludeDate, keepFileExt, needsIndex option and a date", () => {
482 const fileNameFormatter = require("../lib/fileNameFormatter")({
483 file: {
484 dir: "/path/to/file",
485 base: "thefile.log",
486 ext: ".log",
487 name: "thefile"
488 },
489 needsIndex: true,
490 compress: true,
491 alwaysIncludeDate: true,
492 keepFileExt: true
493 });
494 it("should take an index, date and return a filename", () => {
495 fileNameFormatter({
496 index: 0,
497 date: "2019-07-15"
498 }).should.eql(normalize("/path/to/file/thefile.2019-07-15.log"));
499 fileNameFormatter({ index: 1, date: "2019-07-15" }).should.eql(
500 normalize("/path/to/file/thefile.2019-07-15.1.log.gz")
501 );
502 fileNameFormatter({
503 index: 2,
504 date: "2019-07-16"
505 }).should.eql(normalize("/path/to/file/thefile.2019-07-16.2.log.gz"));
506 });
507 });
508});
Note: See TracBrowser for help on using the repository browser.