@villedemontreal/general-utils 5.17.2 → 5.17.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/dist/config/configs.d.ts +16 -0
  2. package/dist/config/configs.js +38 -0
  3. package/dist/config/configs.js.map +1 -0
  4. package/dist/scripts/index.d.ts +2 -0
  5. package/dist/scripts/index.js +14 -0
  6. package/dist/scripts/index.js.map +1 -0
  7. package/dist/scripts/lint.d.ts +6 -0
  8. package/dist/scripts/lint.js +31 -0
  9. package/dist/scripts/lint.js.map +1 -0
  10. package/dist/scripts/lintFix.d.ts +6 -0
  11. package/dist/scripts/lintFix.js +40 -0
  12. package/dist/scripts/lintFix.js.map +1 -0
  13. package/dist/src/apiError.d.ts +3 -3
  14. package/dist/src/apiError.js +3 -3
  15. package/dist/src/apiError.js.map +1 -1
  16. package/dist/src/apiError.test.js +57 -48
  17. package/dist/src/apiError.test.js.map +1 -1
  18. package/dist/src/apiErrorBuilder.d.ts +1 -1
  19. package/dist/src/apiErrorBuilder.js +2 -2
  20. package/dist/src/apiErrorBuilder.js.map +1 -1
  21. package/dist/src/collectionUtils.js +2 -2
  22. package/dist/src/collectionUtils.js.map +1 -1
  23. package/dist/src/collectionUtils.test.js +12 -4
  24. package/dist/src/collectionUtils.test.js.map +1 -1
  25. package/dist/src/config/constants.d.ts +1 -1
  26. package/dist/src/config/constants.js.map +1 -1
  27. package/dist/src/config/globalConstants.d.ts +1 -1
  28. package/dist/src/config/globalConstants.js +7 -7
  29. package/dist/src/config/globalConstants.js.map +1 -1
  30. package/dist/src/dateUtils.js +6 -2
  31. package/dist/src/dateUtils.js.map +1 -1
  32. package/dist/src/dateUtils.test.js +31 -16
  33. package/dist/src/dateUtils.test.js.map +1 -1
  34. package/dist/src/pagination.d.ts +1 -1
  35. package/dist/src/pagination.js +1 -1
  36. package/dist/src/pagination.js.map +1 -1
  37. package/dist/src/pagination.test.js +14 -5
  38. package/dist/src/pagination.test.js.map +1 -1
  39. package/dist/src/stringUtils.js +4 -1
  40. package/dist/src/stringUtils.js.map +1 -1
  41. package/dist/src/stringUtils.test.js.map +1 -1
  42. package/dist/src/timer.js.map +1 -1
  43. package/dist/src/timer.test.js +47 -32
  44. package/dist/src/timer.test.js.map +1 -1
  45. package/dist/src/utils.d.ts +1 -1
  46. package/dist/src/utils.js +118 -97
  47. package/dist/src/utils.js.map +1 -1
  48. package/dist/src/utils.test.js +219 -196
  49. package/dist/src/utils.test.js.map +1 -1
  50. package/dist/tests-resources/exec/execTest.js +11 -2
  51. package/dist/tests-resources/exec/execTest.js.map +1 -1
  52. package/package.json +8 -4
  53. package/src/apiError.test.ts +57 -27
  54. package/src/apiError.ts +5 -5
  55. package/src/apiErrorBuilder.ts +21 -12
  56. package/src/collectionUtils.test.ts +13 -5
  57. package/src/collectionUtils.ts +11 -7
  58. package/src/config/constants.ts +1 -1
  59. package/src/config/globalConstants.ts +8 -8
  60. package/src/dateUtils.test.ts +40 -20
  61. package/src/dateUtils.ts +25 -11
  62. package/src/logLevel.ts +1 -1
  63. package/src/orderBy.ts +1 -1
  64. package/src/pagination.test.ts +3 -3
  65. package/src/pagination.ts +1 -1
  66. package/src/stringUtils.test.ts +16 -6
  67. package/src/stringUtils.ts +7 -2
  68. package/src/timer.test.ts +3 -3
  69. package/src/timer.ts +1 -1
  70. package/src/utils.test.ts +64 -47
  71. package/src/utils.ts +14 -11
@@ -29,6 +29,15 @@ var __importStar = (this && this.__importStar) || function (mod) {
29
29
  __setModuleDefault(result, mod);
30
30
  return result;
31
31
  };
32
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
33
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
34
+ return new (P || (P = Promise))(function (resolve, reject) {
35
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
36
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
37
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
38
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
39
+ });
40
+ };
32
41
  Object.defineProperty(exports, "__esModule", { value: true });
33
42
  const chai_1 = require("chai");
34
43
  const fs = __importStar(require("fs-extra"));
@@ -43,27 +52,29 @@ describe("App's utilities functions", function () {
43
52
  // tsc()
44
53
  // ==========================================
45
54
  describe('tsc', () => {
46
- it("Compiles a TypeScript file using the 'tsc()' utility", async function () {
47
- if (!fs.existsSync(constants_1.constants.testDataDirPath)) {
48
- fs.mkdirSync(constants_1.constants.testDataDirPath);
49
- }
50
- // May take some time to compile...
51
- this.timeout(20000);
52
- const tmpRepPath = constants_1.constants.testDataDirPath + '/test_tsc';
53
- if (fs.existsSync(tmpRepPath)) {
54
- fs.removeSync(tmpRepPath);
55
- }
56
- fs.mkdirSync(tmpRepPath);
57
- const fileName = (0, uuid_1.v4)();
58
- const filesPathPrefix = tmpRepPath + '/' + fileName;
59
- const tsFilePath = filesPathPrefix + '.ts';
60
- fs.writeFileSync(tsFilePath, `import * as path from 'path';\nlet t = 'a';\nt = t + path.sep;`);
61
- const distRepPath = constants_1.constants.libRoot + '/dist';
62
- await utils_1.utils.tsc([tsFilePath]);
63
- chai_1.assert.isTrue(fs.existsSync(distRepPath + '/test-data/test_tsc/' + fileName + '.js'));
64
- chai_1.assert.isTrue(fs.existsSync(distRepPath + '/test-data/test_tsc/' + fileName + '.js.map'));
65
- chai_1.assert.isTrue(fs.existsSync(distRepPath + '/test-data/test_tsc/' + fileName + '.d.ts'));
66
- fs.removeSync(distRepPath + '/test-data');
55
+ it("Compiles a TypeScript file using the 'tsc()' utility", function () {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ if (!fs.existsSync(constants_1.constants.testDataDirPath)) {
58
+ fs.mkdirSync(constants_1.constants.testDataDirPath);
59
+ }
60
+ // May take some time to compile...
61
+ this.timeout(20000);
62
+ const tmpRepPath = constants_1.constants.testDataDirPath + '/test_tsc';
63
+ if (fs.existsSync(tmpRepPath)) {
64
+ fs.removeSync(tmpRepPath);
65
+ }
66
+ fs.mkdirSync(tmpRepPath);
67
+ const fileName = (0, uuid_1.v4)();
68
+ const filesPathPrefix = tmpRepPath + '/' + fileName;
69
+ const tsFilePath = filesPathPrefix + '.ts';
70
+ fs.writeFileSync(tsFilePath, `import * as path from 'path';\nlet t = 'a';\nt = t + path.sep;`);
71
+ const distRepPath = constants_1.constants.libRoot + '/dist';
72
+ yield utils_1.utils.tsc([tsFilePath]);
73
+ chai_1.assert.isTrue(fs.existsSync(distRepPath + '/test-data/test_tsc/' + fileName + '.js'));
74
+ chai_1.assert.isTrue(fs.existsSync(distRepPath + '/test-data/test_tsc/' + fileName + '.js.map'));
75
+ chai_1.assert.isTrue(fs.existsSync(distRepPath + '/test-data/test_tsc/' + fileName + '.d.ts'));
76
+ fs.removeSync(distRepPath + '/test-data');
77
+ });
67
78
  });
68
79
  });
69
80
  // ==========================================
@@ -229,9 +240,17 @@ describe("App's utilities functions", function () {
229
240
  chai_1.assert.isFalse(result);
230
241
  result = utils_1.utils.isIntegerValue(['string', 2, false]);
231
242
  chai_1.assert.isFalse(result);
232
- result = utils_1.utils.isIntegerValue({ firstStringValue: 'a', secondStringValue: 'b', thirdStringValue: 'c' });
243
+ result = utils_1.utils.isIntegerValue({
244
+ firstStringValue: 'a',
245
+ secondStringValue: 'b',
246
+ thirdStringValue: 'c',
247
+ });
233
248
  chai_1.assert.isFalse(result);
234
- result = utils_1.utils.isIntegerValue({ firstNumberValue: 1, secondNumberValue: 2, thirdNumberValue: 3 });
249
+ result = utils_1.utils.isIntegerValue({
250
+ firstNumberValue: 1,
251
+ secondNumberValue: 2,
252
+ thirdNumberValue: 3,
253
+ });
235
254
  chai_1.assert.isFalse(result);
236
255
  result = utils_1.utils.isIntegerValue({ stringValue: 'string', numberValue: 2, booleanValue: false });
237
256
  chai_1.assert.isFalse(result);
@@ -436,19 +455,19 @@ describe("App's utilities functions", function () {
436
455
  // sleep()
437
456
  // ==========================================
438
457
  describe('sleep()', () => {
439
- it("The 'sleep()' function await correctly", async () => {
458
+ it("The 'sleep()' function await correctly", () => __awaiter(this, void 0, void 0, function* () {
440
459
  const start = new Date().getTime();
441
- await utils_1.utils.sleep(500);
460
+ yield utils_1.utils.sleep(500);
442
461
  const end = new Date().getTime();
443
462
  chai_1.assert.isTrue(end - start > 450);
444
- });
463
+ }));
445
464
  });
446
465
  // ==========================================
447
466
  // isSafeToDelete()
448
467
  // ==========================================
449
468
  describe('isSafeToDelete()', () => {
450
469
  const utilsObj = new utils_1.Utils();
451
- it('Safe paths', async () => {
470
+ it('Safe paths', () => __awaiter(this, void 0, void 0, function* () {
452
471
  chai_1.assert.isTrue(utilsObj.isSafeToDelete('/toto/titi'));
453
472
  chai_1.assert.isTrue(utilsObj.isSafeToDelete('/toto/titi.txt'));
454
473
  chai_1.assert.isTrue(utilsObj.isSafeToDelete('/toto/.titi'));
@@ -463,8 +482,8 @@ describe("App's utilities functions", function () {
463
482
  chai_1.assert.isTrue(utilsObj.isSafeToDelete('C:/toto/.titi'));
464
483
  chai_1.assert.isTrue(utilsObj.isSafeToDelete('C:/toto/titi/tutu'));
465
484
  chai_1.assert.isTrue(utilsObj.isSafeToDelete('C:/toto/titi/tutu.txt'));
466
- });
467
- it('Unsafe paths', async () => {
485
+ }));
486
+ it('Unsafe paths', () => __awaiter(this, void 0, void 0, function* () {
468
487
  chai_1.assert.isFalse(utilsObj.isSafeToDelete(undefined));
469
488
  chai_1.assert.isFalse(utilsObj.isSafeToDelete(null));
470
489
  chai_1.assert.isFalse(utilsObj.isSafeToDelete(''));
@@ -501,17 +520,17 @@ describe("App's utilities functions", function () {
501
520
  chai_1.assert.isFalse(utilsObj.isSafeToDelete('\r'));
502
521
  chai_1.assert.isFalse(utilsObj.isSafeToDelete('\n'));
503
522
  chai_1.assert.isFalse(utilsObj.isSafeToDelete('\t'));
504
- });
523
+ }));
505
524
  });
506
525
  // ==========================================
507
526
  // isDir()
508
527
  // ==========================================
509
528
  describe('isDir()', () => {
510
- before(async () => {
529
+ before(() => __awaiter(this, void 0, void 0, function* () {
511
530
  if (!fs.existsSync(constants_1.constants.testDataDirPath)) {
512
531
  fs.mkdirSync(constants_1.constants.testDataDirPath);
513
532
  }
514
- });
533
+ }));
515
534
  it('Is dir', () => {
516
535
  const thePath = constants_1.constants.testDataDirPath + '/' + (0, uuid_1.v4)();
517
536
  chai_1.assert.isFalse(utils_1.utils.isDir(thePath));
@@ -555,34 +574,34 @@ describe("App's utilities functions", function () {
555
574
  // ==========================================
556
575
  // deleteFile()
557
576
  // ==========================================
558
- describe('deleteFile()', async () => {
559
- it('Safe file', async () => {
577
+ describe('deleteFile()', () => __awaiter(this, void 0, void 0, function* () {
578
+ it('Safe file', () => __awaiter(this, void 0, void 0, function* () {
560
579
  const tempFilePath = constants_1.constants.testDataDirPath + '/tmp' + new Date().getTime();
561
580
  chai_1.assert.isFalse(fs.existsSync(tempFilePath));
562
581
  fs.createFileSync(tempFilePath);
563
582
  chai_1.assert.isTrue(fs.existsSync(tempFilePath));
564
- await utils_1.utils.deleteFile(tempFilePath);
583
+ yield utils_1.utils.deleteFile(tempFilePath);
565
584
  chai_1.assert.isFalse(fs.existsSync(tempFilePath));
566
- });
567
- it('Unsafe file', async () => {
585
+ }));
586
+ it('Unsafe file', () => __awaiter(this, void 0, void 0, function* () {
568
587
  // root file
569
588
  const tempFilePath = '/tmp' + new Date().getTime();
570
589
  chai_1.assert.isFalse(fs.existsSync(tempFilePath));
571
590
  let error = false;
572
591
  try {
573
- await utils_1.utils.deleteFile(tempFilePath);
592
+ yield utils_1.utils.deleteFile(tempFilePath);
574
593
  }
575
594
  catch (err) {
576
595
  error = true;
577
596
  }
578
597
  chai_1.assert.isTrue(error);
579
- });
580
- });
598
+ }));
599
+ }));
581
600
  // ==========================================
582
601
  // deleteDir()
583
602
  // ==========================================
584
- describe('deleteDir()', async () => {
585
- it('Safe dir', async () => {
603
+ describe('deleteDir()', () => __awaiter(this, void 0, void 0, function* () {
604
+ it('Safe dir', () => __awaiter(this, void 0, void 0, function* () {
586
605
  const tempFilePath = constants_1.constants.testDataDirPath + '/tmp' + new Date().getTime();
587
606
  chai_1.assert.isFalse(fs.existsSync(tempFilePath));
588
607
  fs.mkdirSync(tempFilePath);
@@ -590,27 +609,27 @@ describe("App's utilities functions", function () {
590
609
  fs.mkdirSync(tempFilePath + '/subDir');
591
610
  fs.createFileSync(tempFilePath + '/subDir/.anotherFile');
592
611
  chai_1.assert.isTrue(fs.existsSync(tempFilePath));
593
- await utils_1.utils.deleteDir(tempFilePath);
612
+ yield utils_1.utils.deleteDir(tempFilePath);
594
613
  chai_1.assert.isFalse(fs.existsSync(tempFilePath));
595
- });
596
- it('Unsafe dir', async () => {
614
+ }));
615
+ it('Unsafe dir', () => __awaiter(this, void 0, void 0, function* () {
597
616
  const tempFilePath = '/tmp' + new Date().getTime();
598
617
  chai_1.assert.isFalse(fs.existsSync(tempFilePath));
599
618
  let error = false;
600
619
  try {
601
- await utils_1.utils.deleteDir(tempFilePath);
620
+ yield utils_1.utils.deleteDir(tempFilePath);
602
621
  }
603
622
  catch (err) {
604
623
  error = true;
605
624
  }
606
625
  chai_1.assert.isTrue(error);
607
- });
608
- });
626
+ }));
627
+ }));
609
628
  // ==========================================
610
629
  // clearDir()
611
630
  // ==========================================
612
- describe('clearDir()', async () => {
613
- it('Safe dir', async () => {
631
+ describe('clearDir()', () => __awaiter(this, void 0, void 0, function* () {
632
+ it('Safe dir', () => __awaiter(this, void 0, void 0, function* () {
614
633
  if (!fs.existsSync(constants_1.constants.testDataDirPath)) {
615
634
  fs.mkdirSync(constants_1.constants.testDataDirPath);
616
635
  }
@@ -626,34 +645,34 @@ describe("App's utilities functions", function () {
626
645
  chai_1.assert.isTrue(fs.existsSync(tempFilePath + '/someFile'));
627
646
  chai_1.assert.isTrue(fs.existsSync(tempFilePath + '/.someFile2'));
628
647
  chai_1.assert.isTrue(fs.existsSync(tempFilePath + '/subDir'));
629
- await utils_1.utils.clearDir(tempFilePath);
648
+ yield utils_1.utils.clearDir(tempFilePath);
630
649
  chai_1.assert.isTrue(fs.existsSync(tempFilePath));
631
650
  chai_1.assert.isFalse(fs.existsSync(tempFilePath + '/someFile'));
632
651
  chai_1.assert.isFalse(fs.existsSync(tempFilePath + '/.someFile2'));
633
652
  chai_1.assert.isFalse(fs.existsSync(tempFilePath + '/subDir'));
634
653
  }
635
654
  finally {
636
- await utils_1.utils.deleteDir(tempFilePath);
655
+ yield utils_1.utils.deleteDir(tempFilePath);
637
656
  }
638
- });
639
- it('Unsafe dir', async () => {
657
+ }));
658
+ it('Unsafe dir', () => __awaiter(this, void 0, void 0, function* () {
640
659
  const tempFilePath = '/tmp' + new Date().getTime();
641
660
  chai_1.assert.isFalse(fs.existsSync(tempFilePath));
642
661
  let error = false;
643
662
  try {
644
- await utils_1.utils.clearDir(tempFilePath);
663
+ yield utils_1.utils.clearDir(tempFilePath);
645
664
  }
646
665
  catch (err) {
647
666
  error = true;
648
667
  }
649
668
  chai_1.assert.isTrue(error);
650
- });
651
- });
669
+ }));
670
+ }));
652
671
  // ==========================================
653
672
  // getDefinedOrNull()
654
673
  // ==========================================
655
- describe('getDefinedOrNull()', async () => {
656
- it('Defined stays untouches', async () => {
674
+ describe('getDefinedOrNull()', () => __awaiter(this, void 0, void 0, function* () {
675
+ it('Defined stays untouches', () => __awaiter(this, void 0, void 0, function* () {
657
676
  let res = utils_1.utils.getDefinedOrNull('abc');
658
677
  chai_1.assert.strictEqual(res, 'abc');
659
678
  res = utils_1.utils.getDefinedOrNull('');
@@ -664,72 +683,72 @@ describe("App's utilities functions", function () {
664
683
  chai_1.assert.deepEqual(res, {});
665
684
  res = utils_1.utils.getDefinedOrNull([]);
666
685
  chai_1.assert.deepEqual(res, []);
667
- });
668
- it('Null stays Null', async () => {
686
+ }));
687
+ it('Null stays Null', () => __awaiter(this, void 0, void 0, function* () {
669
688
  const res = utils_1.utils.getDefinedOrNull(null);
670
689
  chai_1.assert.strictEqual(res, null);
671
- });
672
- it('Undefined becomes Null', async () => {
690
+ }));
691
+ it('Undefined becomes Null', () => __awaiter(this, void 0, void 0, function* () {
673
692
  const res = utils_1.utils.getDefinedOrNull(undefined);
674
693
  chai_1.assert.strictEqual(res, null);
675
- });
676
- });
694
+ }));
695
+ }));
677
696
  describe('findFreePort', () => {
678
- it('', async () => {
679
- const port = await utils_1.utils.findFreePort();
697
+ it('', () => __awaiter(this, void 0, void 0, function* () {
698
+ const port = yield utils_1.utils.findFreePort();
680
699
  chai_1.assert.isOk(port);
681
700
  chai_1.assert.isNumber(port);
682
- });
701
+ }));
683
702
  });
684
703
  describe('isValidDate', () => {
685
- it('valid date - Date', async () => {
704
+ it('valid date - Date', () => __awaiter(this, void 0, void 0, function* () {
686
705
  chai_1.assert.isTrue(utils_1.utils.isValidDate(new Date()));
687
- });
688
- it('valid date - Date from valid string', async () => {
706
+ }));
707
+ it('valid date - Date from valid string', () => __awaiter(this, void 0, void 0, function* () {
689
708
  const date = new Date('2011-04-11T10:20:30Z');
690
709
  chai_1.assert.isTrue(utils_1.utils.isValidDate(date));
691
- });
692
- it('invalid date - Date from invalid string', async () => {
710
+ }));
711
+ it('invalid date - Date from invalid string', () => __awaiter(this, void 0, void 0, function* () {
693
712
  const date = new Date('toto');
694
713
  chai_1.assert.isFalse(utils_1.utils.isValidDate(date));
695
- });
696
- it('invalid date - various', async () => {
714
+ }));
715
+ it('invalid date - various', () => __awaiter(this, void 0, void 0, function* () {
697
716
  for (const date of [[], 123, `toto`, {}, ``, ` `, null, undefined]) {
698
717
  chai_1.assert.isFalse(utils_1.utils.isValidDate(date));
699
718
  }
700
- });
719
+ }));
701
720
  });
702
721
  describe('dateTransformer', () => {
703
- it('valid date as Date', async () => {
722
+ it('valid date as Date', () => __awaiter(this, void 0, void 0, function* () {
704
723
  const date = utils_1.utils.dateTransformer(new Date());
705
724
  chai_1.assert.isOk(date);
706
725
  chai_1.assert.isTrue(utils_1.utils.isValidDate(date));
707
- });
708
- it('valid date as string', async () => {
726
+ }));
727
+ it('valid date as string', () => __awaiter(this, void 0, void 0, function* () {
709
728
  let date = utils_1.utils.dateTransformer('2011-04-11T10:20:30Z');
710
729
  chai_1.assert.isOk(date);
711
730
  chai_1.assert.isTrue(utils_1.utils.isValidDate(date));
712
731
  date = utils_1.utils.dateTransformer('2011-04-11');
713
732
  chai_1.assert.isOk(date);
714
733
  chai_1.assert.isTrue(utils_1.utils.isValidDate(date));
715
- });
716
- it('empty date', async () => {
734
+ }));
735
+ it('empty date', () => __awaiter(this, void 0, void 0, function* () {
717
736
  for (const dateLike of [null, undefined]) {
718
737
  const date = utils_1.utils.dateTransformer(dateLike);
719
738
  chai_1.assert.isNull(date);
720
739
  }
721
- });
722
- it('invalid date', async () => {
740
+ }));
741
+ it('invalid date', () => __awaiter(this, void 0, void 0, function* () {
723
742
  for (const dateLike of [``, ` `, 123, true, [], {}, 'toto']) {
724
743
  const date = utils_1.utils.dateTransformer(dateLike);
725
744
  chai_1.assert.isOk(date);
726
745
  chai_1.assert.isFalse(utils_1.utils.isValidDate(date));
727
746
  }
728
- });
747
+ }));
729
748
  });
730
749
  describe('throwNotManaged', () => {
731
750
  const tmpRepPath = constants_1.constants.testDataDirPath + '/test_throwNotManaged';
732
- before(async () => {
751
+ before(() => __awaiter(this, void 0, void 0, function* () {
733
752
  if (!fs.existsSync(constants_1.constants.testDataDirPath)) {
734
753
  fs.mkdirSync(constants_1.constants.testDataDirPath);
735
754
  }
@@ -737,48 +756,52 @@ describe("App's utilities functions", function () {
737
756
  fs.removeSync(tmpRepPath);
738
757
  }
739
758
  fs.mkdirSync(tmpRepPath);
740
- });
741
- after(async () => {
759
+ }));
760
+ after(() => __awaiter(this, void 0, void 0, function* () {
742
761
  fs.removeSync(constants_1.constants.testDataDirPath);
743
- });
744
- it('compile', async function () {
745
- // May take some time to compile...
746
- this.timeout(7000);
747
- const fileName = (0, uuid_1.v4)();
748
- const filesPathPrefix = tmpRepPath + '/' + fileName;
749
- const tsFilePath = filesPathPrefix + '.ts';
750
- const content = fs.readFileSync(constants_1.constants.libRoot + '/tests-resources/throwNotManagedSuccess.txt', {
751
- encoding: 'utf-8'
762
+ }));
763
+ it('compile', function () {
764
+ return __awaiter(this, void 0, void 0, function* () {
765
+ // May take some time to compile...
766
+ this.timeout(7000);
767
+ const fileName = (0, uuid_1.v4)();
768
+ const filesPathPrefix = tmpRepPath + '/' + fileName;
769
+ const tsFilePath = filesPathPrefix + '.ts';
770
+ const content = fs.readFileSync(constants_1.constants.libRoot + '/tests-resources/throwNotManagedSuccess.txt', {
771
+ encoding: 'utf-8',
772
+ });
773
+ fs.writeFileSync(tsFilePath, content);
774
+ yield utils_1.utils.tsc([tsFilePath]);
775
+ const distRepPath = constants_1.constants.libRoot + '/dist/test-data/test_throwNotManaged';
776
+ chai_1.assert.isTrue(fs.existsSync(distRepPath + '/' + fileName + '.js'));
777
+ fs.removeSync(distRepPath);
752
778
  });
753
- fs.writeFileSync(tsFilePath, content);
754
- await utils_1.utils.tsc([tsFilePath]);
755
- const distRepPath = constants_1.constants.libRoot + '/dist/test-data/test_throwNotManaged';
756
- chai_1.assert.isTrue(fs.existsSync(distRepPath + '/' + fileName + '.js'));
757
- fs.removeSync(distRepPath);
758
779
  });
759
- it("doesn't compile", async function () {
760
- // May take some time to compile...
761
- this.timeout(7000);
762
- if (fs.existsSync(tmpRepPath)) {
763
- fs.removeSync(tmpRepPath);
764
- }
765
- fs.mkdirSync(tmpRepPath);
766
- const fileName = (0, uuid_1.v4)();
767
- const filesPathPrefix = tmpRepPath + '/' + fileName;
768
- const tsFilePath = filesPathPrefix + '.ts';
769
- const content = fs.readFileSync(constants_1.constants.libRoot + '/tests-resources/throwNotManagedFail.txt', {
770
- encoding: 'utf-8'
780
+ it("doesn't compile", function () {
781
+ return __awaiter(this, void 0, void 0, function* () {
782
+ // May take some time to compile...
783
+ this.timeout(7000);
784
+ if (fs.existsSync(tmpRepPath)) {
785
+ fs.removeSync(tmpRepPath);
786
+ }
787
+ fs.mkdirSync(tmpRepPath);
788
+ const fileName = (0, uuid_1.v4)();
789
+ const filesPathPrefix = tmpRepPath + '/' + fileName;
790
+ const tsFilePath = filesPathPrefix + '.ts';
791
+ const content = fs.readFileSync(constants_1.constants.libRoot + '/tests-resources/throwNotManagedFail.txt', {
792
+ encoding: 'utf-8',
793
+ });
794
+ fs.writeFileSync(tsFilePath, content);
795
+ try {
796
+ yield utils_1.utils.tsc([tsFilePath]);
797
+ chai_1.assert.fail();
798
+ }
799
+ catch (err) {
800
+ // ok
801
+ }
771
802
  });
772
- fs.writeFileSync(tsFilePath, content);
773
- try {
774
- await utils_1.utils.tsc([tsFilePath]);
775
- chai_1.assert.fail();
776
- }
777
- catch (err) {
778
- // ok
779
- }
780
803
  });
781
- it('throws error', async () => {
804
+ it('throws error', () => __awaiter(this, void 0, void 0, function* () {
782
805
  try {
783
806
  utils_1.utils.throwNotManaged('my message', 'oups');
784
807
  chai_1.assert.fail();
@@ -786,7 +809,7 @@ describe("App's utilities functions", function () {
786
809
  catch (err) {
787
810
  /* ok */
788
811
  }
789
- });
812
+ }));
790
813
  });
791
814
  // ==========================================
792
815
  // isObjectStrict()
@@ -802,7 +825,7 @@ describe("App's utilities functions", function () {
802
825
  [],
803
826
  [123],
804
827
  // tslint:disable-next-line:prefer-array-literal
805
- new Array(),
828
+ [],
806
829
  null,
807
830
  undefined,
808
831
  '',
@@ -812,7 +835,7 @@ describe("App's utilities functions", function () {
812
835
  new Date(),
813
836
  () => {
814
837
  /* ok */
815
- }
838
+ },
816
839
  ]) {
817
840
  chai_1.assert.isFalse(utils_1.utils.isObjectStrict(value));
818
841
  }
@@ -826,8 +849,8 @@ describe("App's utilities functions", function () {
826
849
  const array = [
827
850
  {
828
851
  aaa: 123,
829
- myKey: 'myValue'
830
- }
852
+ myKey: 'myValue',
853
+ },
831
854
  ];
832
855
  chai_1.assert.isTrue(utils_1.utils.arrayContainsObjectWithKeyEqualsTo(array, 'myKey', 'myValue'));
833
856
  });
@@ -835,8 +858,8 @@ describe("App's utilities functions", function () {
835
858
  const array = [
836
859
  {
837
860
  aaa: 123,
838
- myKey: 12345
839
- }
861
+ myKey: 12345,
862
+ },
840
863
  ];
841
864
  chai_1.assert.isTrue(utils_1.utils.arrayContainsObjectWithKeyEqualsTo(array, 'myKey', 12345));
842
865
  });
@@ -845,8 +868,8 @@ describe("App's utilities functions", function () {
845
868
  const array = [
846
869
  {
847
870
  aaa: 123,
848
- myKey: someDate
849
- }
871
+ myKey: someDate,
872
+ },
850
873
  ];
851
874
  chai_1.assert.isTrue(utils_1.utils.arrayContainsObjectWithKeyEqualsTo(array, 'myKey', someDate));
852
875
  });
@@ -860,16 +883,16 @@ describe("App's utilities functions", function () {
860
883
  '',
861
884
  null,
862
885
  {
863
- juju: 123.45
864
- }
886
+ juju: 123.45,
887
+ },
865
888
  ],
866
- tata: undefined
889
+ tata: undefined,
867
890
  };
868
891
  const array = [
869
892
  {
870
893
  aaa: 123,
871
- myKey: obj
872
- }
894
+ myKey: obj,
895
+ },
873
896
  ];
874
897
  chai_1.assert.isTrue(utils_1.utils.arrayContainsObjectWithKeyEqualsTo(array, 'myKey', obj));
875
898
  });
@@ -883,16 +906,16 @@ describe("App's utilities functions", function () {
883
906
  '',
884
907
  null,
885
908
  {
886
- juju: 123.45
887
- }
909
+ juju: 123.45,
910
+ },
888
911
  ],
889
- tata: undefined
912
+ tata: undefined,
890
913
  };
891
914
  const array = [
892
915
  {
893
916
  aaa: 123,
894
- nope: obj
895
- }
917
+ nope: obj,
918
+ },
896
919
  ];
897
920
  chai_1.assert.isFalse(utils_1.utils.arrayContainsObjectWithKeyEqualsTo(array, 'myKey', obj));
898
921
  });
@@ -906,16 +929,16 @@ describe("App's utilities functions", function () {
906
929
  '',
907
930
  null,
908
931
  {
909
- juju: 123.45
910
- }
932
+ juju: 123.45,
933
+ },
911
934
  ],
912
- tata: undefined
935
+ tata: undefined,
913
936
  };
914
937
  const array = [
915
938
  {
916
939
  aaa: 123,
917
- myKey: obj
918
- }
940
+ myKey: obj,
941
+ },
919
942
  ];
920
943
  chai_1.assert.isFalse(utils_1.utils.arrayContainsObjectWithKeyEqualsTo(array, 'myKey', {
921
944
  titi: '123',
@@ -925,10 +948,10 @@ describe("App's utilities functions", function () {
925
948
  '',
926
949
  null,
927
950
  {
928
- juju: 123.45
929
- }
951
+ juju: 123.45,
952
+ },
930
953
  ],
931
- tata: undefined
954
+ tata: undefined,
932
955
  }));
933
956
  });
934
957
  // ==========================================
@@ -978,14 +1001,14 @@ describe("App's utilities functions", function () {
978
1001
  // ==========================================
979
1002
  describe('exec()', () => {
980
1003
  const dummyJs = `dist/tests-resources/exec/execTest`;
981
- it('default', async () => {
982
- const exitCode = await utils_1.utils.exec(`node`, [dummyJs]);
1004
+ it('default', () => __awaiter(this, void 0, void 0, function* () {
1005
+ const exitCode = yield utils_1.utils.exec(`node`, [dummyJs]);
983
1006
  chai_1.assert.deepEqual(exitCode, 0);
984
- });
985
- it('bin missing', async () => {
1007
+ }));
1008
+ it('bin missing', () => __awaiter(this, void 0, void 0, function* () {
986
1009
  for (const bin of [undefined, null, '']) {
987
1010
  try {
988
- await utils_1.utils.exec(bin);
1011
+ yield utils_1.utils.exec(bin);
989
1012
  }
990
1013
  catch (err) {
991
1014
  chai_1.assert.isTrue(err instanceof utils_1.ExecError);
@@ -993,31 +1016,31 @@ describe("App's utilities functions", function () {
993
1016
  chai_1.assert.notDeepEqual(err.exitCode, 0);
994
1017
  }
995
1018
  }
996
- });
997
- it('invalid bin', async () => {
1019
+ }));
1020
+ it('invalid bin', () => __awaiter(this, void 0, void 0, function* () {
998
1021
  try {
999
- await utils_1.utils.exec(`_NOPE`);
1022
+ yield utils_1.utils.exec(`_NOPE`);
1000
1023
  }
1001
1024
  catch (err) {
1002
1025
  chai_1.assert.isTrue(err instanceof utils_1.ExecError);
1003
1026
  chai_1.assert.isNumber(err.exitCode);
1004
1027
  chai_1.assert.notDeepEqual(err.exitCode, 0);
1005
1028
  }
1006
- });
1007
- it('file arg error', async () => {
1029
+ }));
1030
+ it('file arg error', () => __awaiter(this, void 0, void 0, function* () {
1008
1031
  try {
1009
- await utils_1.utils.exec(`node`, [`dist/_NOPE`]);
1032
+ yield utils_1.utils.exec(`node`, [`dist/_NOPE`]);
1010
1033
  }
1011
1034
  catch (err) {
1012
1035
  chai_1.assert.isTrue(err instanceof utils_1.ExecError);
1013
1036
  chai_1.assert.isNumber(err.exitCode);
1014
1037
  chai_1.assert.notDeepEqual(err.exitCode, 0);
1015
1038
  }
1016
- });
1017
- it('error', async () => {
1039
+ }));
1040
+ it('error', () => __awaiter(this, void 0, void 0, function* () {
1018
1041
  let error;
1019
1042
  try {
1020
- await utils_1.utils.exec(`node`, [dummyJs, `error`]);
1043
+ yield utils_1.utils.exec(`node`, [dummyJs, `error`]);
1021
1044
  }
1022
1045
  catch (err) {
1023
1046
  error = err;
@@ -1028,15 +1051,15 @@ describe("App's utilities functions", function () {
1028
1051
  chai_1.assert.isTrue(error instanceof utils_1.ExecError);
1029
1052
  chai_1.assert.isNumber(error.exitCode);
1030
1053
  chai_1.assert.notDeepEqual(error.exitCode, 0);
1031
- });
1032
- it('exit code explicitly 0', async () => {
1033
- const exitCode = await utils_1.utils.exec(`node`, [dummyJs, `customExitCode`, `0`]);
1054
+ }));
1055
+ it('exit code explicitly 0', () => __awaiter(this, void 0, void 0, function* () {
1056
+ const exitCode = yield utils_1.utils.exec(`node`, [dummyJs, `customExitCode`, `0`]);
1034
1057
  chai_1.assert.deepEqual(exitCode, 0);
1035
- });
1036
- it('custom exit code - error', async () => {
1058
+ }));
1059
+ it('custom exit code - error', () => __awaiter(this, void 0, void 0, function* () {
1037
1060
  let error;
1038
1061
  try {
1039
- await utils_1.utils.exec(`node`, [dummyJs, `customExitCode`, `123`]);
1062
+ yield utils_1.utils.exec(`node`, [dummyJs, `customExitCode`, `123`]);
1040
1063
  }
1041
1064
  catch (err) {
1042
1065
  error = err;
@@ -1047,26 +1070,26 @@ describe("App's utilities functions", function () {
1047
1070
  chai_1.assert.isTrue(error instanceof utils_1.ExecError);
1048
1071
  chai_1.assert.isNumber(error.exitCode);
1049
1072
  chai_1.assert.deepEqual(error.exitCode, 123);
1050
- });
1051
- it('custom exit code - success', async () => {
1052
- const exitCode = await utils_1.utils.exec(`node`, [dummyJs, `customExitCode`, `123`], {
1053
- successExitCodes: 123
1073
+ }));
1074
+ it('custom exit code - success', () => __awaiter(this, void 0, void 0, function* () {
1075
+ const exitCode = yield utils_1.utils.exec(`node`, [dummyJs, `customExitCode`, `123`], {
1076
+ successExitCodes: 123,
1054
1077
  });
1055
1078
  chai_1.assert.deepEqual(exitCode, 123);
1056
- });
1057
- it('custom exit code - multiple', async () => {
1058
- let exitCode = await utils_1.utils.exec(`node`, [dummyJs, `customExitCode`, `123`], {
1059
- successExitCodes: [0, 123]
1079
+ }));
1080
+ it('custom exit code - multiple', () => __awaiter(this, void 0, void 0, function* () {
1081
+ let exitCode = yield utils_1.utils.exec(`node`, [dummyJs, `customExitCode`, `123`], {
1082
+ successExitCodes: [0, 123],
1060
1083
  });
1061
1084
  chai_1.assert.deepEqual(exitCode, 123);
1062
- exitCode = await utils_1.utils.exec(`node`, [dummyJs, `success`], {
1063
- successExitCodes: [0, 123]
1085
+ exitCode = yield utils_1.utils.exec(`node`, [dummyJs, `success`], {
1086
+ successExitCodes: [0, 123],
1064
1087
  });
1065
1088
  chai_1.assert.deepEqual(exitCode, 0);
1066
1089
  let error;
1067
1090
  try {
1068
- await utils_1.utils.exec(`node`, [dummyJs, `customExitCode`, `1`], {
1069
- successExitCodes: [0, 123]
1091
+ yield utils_1.utils.exec(`node`, [dummyJs, `customExitCode`, `1`], {
1092
+ successExitCodes: [0, 123],
1070
1093
  });
1071
1094
  }
1072
1095
  catch (err) {
@@ -1078,8 +1101,8 @@ describe("App's utilities functions", function () {
1078
1101
  chai_1.assert.isTrue(error instanceof utils_1.ExecError);
1079
1102
  chai_1.assert.isNumber(error.exitCode);
1080
1103
  chai_1.assert.deepEqual(error.exitCode, 1);
1081
- });
1082
- it('output handler', async () => {
1104
+ }));
1105
+ it('output handler', () => __awaiter(this, void 0, void 0, function* () {
1083
1106
  let currentOut = '';
1084
1107
  let currentErr = '';
1085
1108
  let execOut = '';
@@ -1095,11 +1118,11 @@ describe("App's utilities functions", function () {
1095
1118
  currentErr += chunk.toString();
1096
1119
  return true;
1097
1120
  };
1098
- await utils_1.utils.exec(`node`, [dummyJs], {
1121
+ yield utils_1.utils.exec(`node`, [dummyJs], {
1099
1122
  outputHandler: (stdoutOutput, stderrOutput) => {
1100
1123
  execOut += stdoutOutput ? stdoutOutput : '';
1101
1124
  execErr += stderrOutput ? stderrOutput : '';
1102
- }
1125
+ },
1103
1126
  });
1104
1127
  chai_1.assert.isTrue(execOut.includes(`in dummy - info`));
1105
1128
  chai_1.assert.isFalse(execOut.includes(`in dummy - error`));
@@ -1114,8 +1137,8 @@ describe("App's utilities functions", function () {
1114
1137
  process.stdout.write = stdOutOriginal;
1115
1138
  process.stderr.write = stdErrOriginal;
1116
1139
  }
1117
- });
1118
- it('output handler + disableConsoleOutputs', async () => {
1140
+ }));
1141
+ it('output handler + disableConsoleOutputs', () => __awaiter(this, void 0, void 0, function* () {
1119
1142
  let currentOut = '';
1120
1143
  let currentErr = '';
1121
1144
  let execOut = '';
@@ -1131,12 +1154,12 @@ describe("App's utilities functions", function () {
1131
1154
  currentErr += chunk.toString();
1132
1155
  return true;
1133
1156
  };
1134
- await utils_1.utils.exec(`node`, [dummyJs], {
1157
+ yield utils_1.utils.exec(`node`, [dummyJs], {
1135
1158
  outputHandler: (stdoutOutput, stderrOutput) => {
1136
1159
  execOut += stdoutOutput ? stdoutOutput : '';
1137
1160
  execErr += stderrOutput ? stderrOutput : '';
1138
1161
  },
1139
- disableConsoleOutputs: true
1162
+ disableConsoleOutputs: true,
1140
1163
  });
1141
1164
  chai_1.assert.isTrue(execOut.includes(`in dummy - info`));
1142
1165
  chai_1.assert.isFalse(execOut.includes(`in dummy - error`));
@@ -1149,11 +1172,11 @@ describe("App's utilities functions", function () {
1149
1172
  process.stdout.write = stdOutOriginal;
1150
1173
  process.stderr.write = stdErrOriginal;
1151
1174
  }
1152
- });
1153
- it('execPromisified deprecated but still working', async () => {
1175
+ }));
1176
+ it('execPromisified deprecated but still working', () => __awaiter(this, void 0, void 0, function* () {
1154
1177
  let execOut = '';
1155
1178
  let execErr = '';
1156
- const exitCode = await utils_1.utils.execPromisified(`node`, [dummyJs], (stdoutOutput, stderrOutput) => {
1179
+ const exitCode = yield utils_1.utils.execPromisified(`node`, [dummyJs], (stdoutOutput, stderrOutput) => {
1157
1180
  execOut += stdoutOutput ? stdoutOutput : '';
1158
1181
  execErr += stderrOutput ? stderrOutput : '';
1159
1182
  });
@@ -1162,11 +1185,11 @@ describe("App's utilities functions", function () {
1162
1185
  chai_1.assert.isFalse(execOut.includes(`in dummy - error`));
1163
1186
  chai_1.assert.isFalse(execErr.includes(`in dummy - info`));
1164
1187
  chai_1.assert.isTrue(execErr.includes(`in dummy - error`));
1165
- });
1166
- it('execPromisified deprecated but still working - error', async () => {
1188
+ }));
1189
+ it('execPromisified deprecated but still working - error', () => __awaiter(this, void 0, void 0, function* () {
1167
1190
  let error;
1168
1191
  try {
1169
- await utils_1.utils.execPromisified(`node`, [dummyJs, `error`]);
1192
+ yield utils_1.utils.execPromisified(`node`, [dummyJs, `error`]);
1170
1193
  }
1171
1194
  catch (err) {
1172
1195
  error = err;
@@ -1174,7 +1197,7 @@ describe("App's utilities functions", function () {
1174
1197
  if (!error) {
1175
1198
  chai_1.assert.fail();
1176
1199
  }
1177
- });
1200
+ }));
1178
1201
  });
1179
1202
  });
1180
1203
  //# sourceMappingURL=utils.test.js.map