fileNameFormatter-test.js 16 KB

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