@villedemontreal/general-utils 5.17.5 → 5.18.0

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 (102) hide show
  1. package/dist/config/configs.d.ts +1 -0
  2. package/dist/config/configs.d.ts.map +1 -0
  3. package/dist/config/configs.js +1 -24
  4. package/dist/config/configs.js.map +1 -1
  5. package/dist/src/apiError.d.ts +1 -0
  6. package/dist/src/apiError.d.ts.map +1 -0
  7. package/dist/src/apiError.js +1 -24
  8. package/dist/src/apiError.js.map +1 -1
  9. package/dist/src/apiError.test.d.ts +1 -0
  10. package/dist/src/apiError.test.d.ts.map +1 -0
  11. package/dist/src/apiError.test.js +32 -41
  12. package/dist/src/apiError.test.js.map +1 -1
  13. package/dist/src/apiErrorBuilder.d.ts +1 -0
  14. package/dist/src/apiErrorBuilder.d.ts.map +1 -0
  15. package/dist/src/apiErrorBuilder.js +1 -24
  16. package/dist/src/apiErrorBuilder.js.map +1 -1
  17. package/dist/src/collectionUtils.d.ts +1 -0
  18. package/dist/src/collectionUtils.d.ts.map +1 -0
  19. package/dist/src/collectionUtils.js +1 -24
  20. package/dist/src/collectionUtils.js.map +1 -1
  21. package/dist/src/collectionUtils.test.d.ts +1 -0
  22. package/dist/src/collectionUtils.test.d.ts.map +1 -0
  23. package/dist/src/collectionUtils.test.js +1 -24
  24. package/dist/src/collectionUtils.test.js.map +1 -1
  25. package/dist/src/config/constants.d.ts +2 -0
  26. package/dist/src/config/constants.d.ts.map +1 -0
  27. package/dist/src/config/constants.js +15 -24
  28. package/dist/src/config/constants.js.map +1 -1
  29. package/dist/src/config/globalConstants.d.ts +1 -0
  30. package/dist/src/config/globalConstants.d.ts.map +1 -0
  31. package/dist/src/dateUtils.d.ts +1 -0
  32. package/dist/src/dateUtils.d.ts.map +1 -0
  33. package/dist/src/dateUtils.js +14 -17
  34. package/dist/src/dateUtils.js.map +1 -1
  35. package/dist/src/dateUtils.test.d.ts +1 -0
  36. package/dist/src/dateUtils.test.d.ts.map +1 -0
  37. package/dist/src/dateUtils.test.js +8 -11
  38. package/dist/src/dateUtils.test.js.map +1 -1
  39. package/dist/src/index.d.ts +1 -0
  40. package/dist/src/index.d.ts.map +1 -0
  41. package/dist/src/logLevel.d.ts +1 -0
  42. package/dist/src/logLevel.d.ts.map +1 -0
  43. package/dist/src/logLevel.js +13 -3
  44. package/dist/src/logLevel.js.map +1 -1
  45. package/dist/src/orderBy.d.ts +1 -0
  46. package/dist/src/orderBy.d.ts.map +1 -0
  47. package/dist/src/orderBy.js +1 -24
  48. package/dist/src/orderBy.js.map +1 -1
  49. package/dist/src/pagination.d.ts +1 -0
  50. package/dist/src/pagination.d.ts.map +1 -0
  51. package/dist/src/pagination.test.d.ts +1 -0
  52. package/dist/src/pagination.test.d.ts.map +1 -0
  53. package/dist/src/pagination.test.js +2 -11
  54. package/dist/src/pagination.test.js.map +1 -1
  55. package/dist/src/stringUtils.d.ts +1 -0
  56. package/dist/src/stringUtils.d.ts.map +1 -0
  57. package/dist/src/stringUtils.js +1 -24
  58. package/dist/src/stringUtils.js.map +1 -1
  59. package/dist/src/stringUtils.test.d.ts +1 -0
  60. package/dist/src/stringUtils.test.d.ts.map +1 -0
  61. package/dist/src/timer.d.ts +1 -0
  62. package/dist/src/timer.d.ts.map +1 -0
  63. package/dist/src/timer.js +1 -24
  64. package/dist/src/timer.js.map +1 -1
  65. package/dist/src/timer.test.d.ts +1 -0
  66. package/dist/src/timer.test.d.ts.map +1 -0
  67. package/dist/src/timer.test.js +32 -47
  68. package/dist/src/timer.test.js.map +1 -1
  69. package/dist/src/utils.d.ts +1 -0
  70. package/dist/src/utils.d.ts.map +1 -0
  71. package/dist/src/utils.js +109 -158
  72. package/dist/src/utils.js.map +1 -1
  73. package/dist/src/utils.test.d.ts +1 -0
  74. package/dist/src/utils.test.d.ts.map +1 -0
  75. package/dist/src/utils.test.js +166 -201
  76. package/dist/src/utils.test.js.map +1 -1
  77. package/dist/test-data/test_throwNotManaged/962a8539-5522-4e44-aa9c-32475e5e537e.d.ts +2 -0
  78. package/dist/test-data/test_throwNotManaged/962a8539-5522-4e44-aa9c-32475e5e537e.d.ts.map +1 -0
  79. package/dist/test-data/test_throwNotManaged/962a8539-5522-4e44-aa9c-32475e5e537e.js +13 -0
  80. package/dist/test-data/test_throwNotManaged/962a8539-5522-4e44-aa9c-32475e5e537e.js.map +1 -0
  81. package/dist/tests-resources/exec/execTest.d.ts +1 -0
  82. package/dist/tests-resources/exec/execTest.d.ts.map +1 -0
  83. package/dist/tests-resources/exec/execTest.js +2 -11
  84. package/dist/tests-resources/exec/execTest.js.map +1 -1
  85. package/dist/tsconfig.tsbuildinfo +1 -1
  86. package/package.json +27 -26
  87. package/src/collectionUtils.ts +1 -1
  88. package/src/config/constants.ts +16 -1
  89. package/src/dateUtils.test.ts +5 -3
  90. package/src/dateUtils.ts +6 -7
  91. package/src/logLevel.ts +13 -3
  92. package/src/utils.test.ts +4 -0
  93. package/src/utils.ts +16 -16
  94. package/dist/scripts/index.d.ts +0 -2
  95. package/dist/scripts/index.js +0 -14
  96. package/dist/scripts/index.js.map +0 -1
  97. package/dist/scripts/lint.d.ts +0 -6
  98. package/dist/scripts/lint.js +0 -31
  99. package/dist/scripts/lint.js.map +0 -1
  100. package/dist/scripts/lintFix.d.ts +0 -6
  101. package/dist/scripts/lintFix.js +0 -40
  102. package/dist/scripts/lintFix.js.map +0 -1
@@ -6,41 +6,9 @@
6
6
  // tslint:disable:max-func-body-length
7
7
  // tslint:disable: prefer-template
8
8
  // ==========================================
9
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- var desc = Object.getOwnPropertyDescriptor(m, k);
12
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
- desc = { enumerable: true, get: function() { return m[k]; } };
14
- }
15
- Object.defineProperty(o, k2, desc);
16
- }) : (function(o, m, k, k2) {
17
- if (k2 === undefined) k2 = k;
18
- o[k2] = m[k];
19
- }));
20
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
- Object.defineProperty(o, "default", { enumerable: true, value: v });
22
- }) : function(o, v) {
23
- o["default"] = v;
24
- });
25
- var __importStar = (this && this.__importStar) || function (mod) {
26
- if (mod && mod.__esModule) return mod;
27
- var result = {};
28
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
29
- __setModuleDefault(result, mod);
30
- return result;
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
- };
41
9
  Object.defineProperty(exports, "__esModule", { value: true });
42
10
  const chai_1 = require("chai");
43
- const fs = __importStar(require("fs-extra"));
11
+ const fs = require("fs-extra");
44
12
  const uuid_1 = require("uuid");
45
13
  const constants_1 = require("./config/constants");
46
14
  const utils_1 = require("./utils");
@@ -48,33 +16,34 @@ const utils_1 = require("./utils");
48
16
  // @see https://github.com/mochajs/mocha/issues/2018
49
17
  // tslint:disable-next-line:only-arrow-functions ter-prefer-arrow-callback
50
18
  describe("App's utilities functions", function () {
19
+ this.beforeAll(() => {
20
+ constants_1.constants.appRoot = constants_1.constants.libRoot; // because our lib is within a monorepo
21
+ });
51
22
  // ==========================================
52
23
  // tsc()
53
24
  // ==========================================
54
25
  describe('tsc', () => {
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
- });
26
+ it("Compiles a TypeScript file using the 'tsc()' utility", async function () {
27
+ if (!fs.existsSync(constants_1.constants.testDataDirPath)) {
28
+ fs.mkdirSync(constants_1.constants.testDataDirPath);
29
+ }
30
+ // May take some time to compile...
31
+ this.timeout(20000);
32
+ const tmpRepPath = constants_1.constants.testDataDirPath + '/test_tsc';
33
+ if (fs.existsSync(tmpRepPath)) {
34
+ fs.removeSync(tmpRepPath);
35
+ }
36
+ fs.mkdirSync(tmpRepPath);
37
+ const fileName = (0, uuid_1.v4)();
38
+ const filesPathPrefix = tmpRepPath + '/' + fileName;
39
+ const tsFilePath = filesPathPrefix + '.ts';
40
+ fs.writeFileSync(tsFilePath, `import * as path from 'path';\nlet t = 'a';\nt = t + path.sep;`);
41
+ const distRepPath = constants_1.constants.libRoot + '/dist';
42
+ await utils_1.utils.tsc([tsFilePath]);
43
+ chai_1.assert.isTrue(fs.existsSync(distRepPath + '/test-data/test_tsc/' + fileName + '.js'));
44
+ chai_1.assert.isTrue(fs.existsSync(distRepPath + '/test-data/test_tsc/' + fileName + '.js.map'));
45
+ chai_1.assert.isTrue(fs.existsSync(distRepPath + '/test-data/test_tsc/' + fileName + '.d.ts'));
46
+ fs.removeSync(distRepPath + '/test-data');
78
47
  });
79
48
  });
80
49
  // ==========================================
@@ -455,19 +424,19 @@ describe("App's utilities functions", function () {
455
424
  // sleep()
456
425
  // ==========================================
457
426
  describe('sleep()', () => {
458
- it("The 'sleep()' function await correctly", () => __awaiter(this, void 0, void 0, function* () {
427
+ it("The 'sleep()' function await correctly", async () => {
459
428
  const start = new Date().getTime();
460
- yield utils_1.utils.sleep(500);
429
+ await utils_1.utils.sleep(500);
461
430
  const end = new Date().getTime();
462
431
  chai_1.assert.isTrue(end - start > 450);
463
- }));
432
+ });
464
433
  });
465
434
  // ==========================================
466
435
  // isSafeToDelete()
467
436
  // ==========================================
468
437
  describe('isSafeToDelete()', () => {
469
438
  const utilsObj = new utils_1.Utils();
470
- it('Safe paths', () => __awaiter(this, void 0, void 0, function* () {
439
+ it('Safe paths', async () => {
471
440
  chai_1.assert.isTrue(utilsObj.isSafeToDelete('/toto/titi'));
472
441
  chai_1.assert.isTrue(utilsObj.isSafeToDelete('/toto/titi.txt'));
473
442
  chai_1.assert.isTrue(utilsObj.isSafeToDelete('/toto/.titi'));
@@ -482,8 +451,8 @@ describe("App's utilities functions", function () {
482
451
  chai_1.assert.isTrue(utilsObj.isSafeToDelete('C:/toto/.titi'));
483
452
  chai_1.assert.isTrue(utilsObj.isSafeToDelete('C:/toto/titi/tutu'));
484
453
  chai_1.assert.isTrue(utilsObj.isSafeToDelete('C:/toto/titi/tutu.txt'));
485
- }));
486
- it('Unsafe paths', () => __awaiter(this, void 0, void 0, function* () {
454
+ });
455
+ it('Unsafe paths', async () => {
487
456
  chai_1.assert.isFalse(utilsObj.isSafeToDelete(undefined));
488
457
  chai_1.assert.isFalse(utilsObj.isSafeToDelete(null));
489
458
  chai_1.assert.isFalse(utilsObj.isSafeToDelete(''));
@@ -520,17 +489,17 @@ describe("App's utilities functions", function () {
520
489
  chai_1.assert.isFalse(utilsObj.isSafeToDelete('\r'));
521
490
  chai_1.assert.isFalse(utilsObj.isSafeToDelete('\n'));
522
491
  chai_1.assert.isFalse(utilsObj.isSafeToDelete('\t'));
523
- }));
492
+ });
524
493
  });
525
494
  // ==========================================
526
495
  // isDir()
527
496
  // ==========================================
528
497
  describe('isDir()', () => {
529
- before(() => __awaiter(this, void 0, void 0, function* () {
498
+ before(async () => {
530
499
  if (!fs.existsSync(constants_1.constants.testDataDirPath)) {
531
500
  fs.mkdirSync(constants_1.constants.testDataDirPath);
532
501
  }
533
- }));
502
+ });
534
503
  it('Is dir', () => {
535
504
  const thePath = constants_1.constants.testDataDirPath + '/' + (0, uuid_1.v4)();
536
505
  chai_1.assert.isFalse(utils_1.utils.isDir(thePath));
@@ -574,34 +543,34 @@ describe("App's utilities functions", function () {
574
543
  // ==========================================
575
544
  // deleteFile()
576
545
  // ==========================================
577
- describe('deleteFile()', () => __awaiter(this, void 0, void 0, function* () {
578
- it('Safe file', () => __awaiter(this, void 0, void 0, function* () {
546
+ describe('deleteFile()', async () => {
547
+ it('Safe file', async () => {
579
548
  const tempFilePath = constants_1.constants.testDataDirPath + '/tmp' + new Date().getTime();
580
549
  chai_1.assert.isFalse(fs.existsSync(tempFilePath));
581
550
  fs.createFileSync(tempFilePath);
582
551
  chai_1.assert.isTrue(fs.existsSync(tempFilePath));
583
- yield utils_1.utils.deleteFile(tempFilePath);
552
+ await utils_1.utils.deleteFile(tempFilePath);
584
553
  chai_1.assert.isFalse(fs.existsSync(tempFilePath));
585
- }));
586
- it('Unsafe file', () => __awaiter(this, void 0, void 0, function* () {
554
+ });
555
+ it('Unsafe file', async () => {
587
556
  // root file
588
557
  const tempFilePath = '/tmp' + new Date().getTime();
589
558
  chai_1.assert.isFalse(fs.existsSync(tempFilePath));
590
559
  let error = false;
591
560
  try {
592
- yield utils_1.utils.deleteFile(tempFilePath);
561
+ await utils_1.utils.deleteFile(tempFilePath);
593
562
  }
594
563
  catch (err) {
595
564
  error = true;
596
565
  }
597
566
  chai_1.assert.isTrue(error);
598
- }));
599
- }));
567
+ });
568
+ });
600
569
  // ==========================================
601
570
  // deleteDir()
602
571
  // ==========================================
603
- describe('deleteDir()', () => __awaiter(this, void 0, void 0, function* () {
604
- it('Safe dir', () => __awaiter(this, void 0, void 0, function* () {
572
+ describe('deleteDir()', async () => {
573
+ it('Safe dir', async () => {
605
574
  const tempFilePath = constants_1.constants.testDataDirPath + '/tmp' + new Date().getTime();
606
575
  chai_1.assert.isFalse(fs.existsSync(tempFilePath));
607
576
  fs.mkdirSync(tempFilePath);
@@ -609,27 +578,27 @@ describe("App's utilities functions", function () {
609
578
  fs.mkdirSync(tempFilePath + '/subDir');
610
579
  fs.createFileSync(tempFilePath + '/subDir/.anotherFile');
611
580
  chai_1.assert.isTrue(fs.existsSync(tempFilePath));
612
- yield utils_1.utils.deleteDir(tempFilePath);
581
+ await utils_1.utils.deleteDir(tempFilePath);
613
582
  chai_1.assert.isFalse(fs.existsSync(tempFilePath));
614
- }));
615
- it('Unsafe dir', () => __awaiter(this, void 0, void 0, function* () {
583
+ });
584
+ it('Unsafe dir', async () => {
616
585
  const tempFilePath = '/tmp' + new Date().getTime();
617
586
  chai_1.assert.isFalse(fs.existsSync(tempFilePath));
618
587
  let error = false;
619
588
  try {
620
- yield utils_1.utils.deleteDir(tempFilePath);
589
+ await utils_1.utils.deleteDir(tempFilePath);
621
590
  }
622
591
  catch (err) {
623
592
  error = true;
624
593
  }
625
594
  chai_1.assert.isTrue(error);
626
- }));
627
- }));
595
+ });
596
+ });
628
597
  // ==========================================
629
598
  // clearDir()
630
599
  // ==========================================
631
- describe('clearDir()', () => __awaiter(this, void 0, void 0, function* () {
632
- it('Safe dir', () => __awaiter(this, void 0, void 0, function* () {
600
+ describe('clearDir()', async () => {
601
+ it('Safe dir', async () => {
633
602
  if (!fs.existsSync(constants_1.constants.testDataDirPath)) {
634
603
  fs.mkdirSync(constants_1.constants.testDataDirPath);
635
604
  }
@@ -645,34 +614,34 @@ describe("App's utilities functions", function () {
645
614
  chai_1.assert.isTrue(fs.existsSync(tempFilePath + '/someFile'));
646
615
  chai_1.assert.isTrue(fs.existsSync(tempFilePath + '/.someFile2'));
647
616
  chai_1.assert.isTrue(fs.existsSync(tempFilePath + '/subDir'));
648
- yield utils_1.utils.clearDir(tempFilePath);
617
+ await utils_1.utils.clearDir(tempFilePath);
649
618
  chai_1.assert.isTrue(fs.existsSync(tempFilePath));
650
619
  chai_1.assert.isFalse(fs.existsSync(tempFilePath + '/someFile'));
651
620
  chai_1.assert.isFalse(fs.existsSync(tempFilePath + '/.someFile2'));
652
621
  chai_1.assert.isFalse(fs.existsSync(tempFilePath + '/subDir'));
653
622
  }
654
623
  finally {
655
- yield utils_1.utils.deleteDir(tempFilePath);
624
+ await utils_1.utils.deleteDir(tempFilePath);
656
625
  }
657
- }));
658
- it('Unsafe dir', () => __awaiter(this, void 0, void 0, function* () {
626
+ });
627
+ it('Unsafe dir', async () => {
659
628
  const tempFilePath = '/tmp' + new Date().getTime();
660
629
  chai_1.assert.isFalse(fs.existsSync(tempFilePath));
661
630
  let error = false;
662
631
  try {
663
- yield utils_1.utils.clearDir(tempFilePath);
632
+ await utils_1.utils.clearDir(tempFilePath);
664
633
  }
665
634
  catch (err) {
666
635
  error = true;
667
636
  }
668
637
  chai_1.assert.isTrue(error);
669
- }));
670
- }));
638
+ });
639
+ });
671
640
  // ==========================================
672
641
  // getDefinedOrNull()
673
642
  // ==========================================
674
- describe('getDefinedOrNull()', () => __awaiter(this, void 0, void 0, function* () {
675
- it('Defined stays untouches', () => __awaiter(this, void 0, void 0, function* () {
643
+ describe('getDefinedOrNull()', async () => {
644
+ it('Defined stays untouches', async () => {
676
645
  let res = utils_1.utils.getDefinedOrNull('abc');
677
646
  chai_1.assert.strictEqual(res, 'abc');
678
647
  res = utils_1.utils.getDefinedOrNull('');
@@ -683,72 +652,72 @@ describe("App's utilities functions", function () {
683
652
  chai_1.assert.deepEqual(res, {});
684
653
  res = utils_1.utils.getDefinedOrNull([]);
685
654
  chai_1.assert.deepEqual(res, []);
686
- }));
687
- it('Null stays Null', () => __awaiter(this, void 0, void 0, function* () {
655
+ });
656
+ it('Null stays Null', async () => {
688
657
  const res = utils_1.utils.getDefinedOrNull(null);
689
658
  chai_1.assert.strictEqual(res, null);
690
- }));
691
- it('Undefined becomes Null', () => __awaiter(this, void 0, void 0, function* () {
659
+ });
660
+ it('Undefined becomes Null', async () => {
692
661
  const res = utils_1.utils.getDefinedOrNull(undefined);
693
662
  chai_1.assert.strictEqual(res, null);
694
- }));
695
- }));
663
+ });
664
+ });
696
665
  describe('findFreePort', () => {
697
- it('', () => __awaiter(this, void 0, void 0, function* () {
698
- const port = yield utils_1.utils.findFreePort();
666
+ it('', async () => {
667
+ const port = await utils_1.utils.findFreePort();
699
668
  chai_1.assert.isOk(port);
700
669
  chai_1.assert.isNumber(port);
701
- }));
670
+ });
702
671
  });
703
672
  describe('isValidDate', () => {
704
- it('valid date - Date', () => __awaiter(this, void 0, void 0, function* () {
673
+ it('valid date - Date', async () => {
705
674
  chai_1.assert.isTrue(utils_1.utils.isValidDate(new Date()));
706
- }));
707
- it('valid date - Date from valid string', () => __awaiter(this, void 0, void 0, function* () {
675
+ });
676
+ it('valid date - Date from valid string', async () => {
708
677
  const date = new Date('2011-04-11T10:20:30Z');
709
678
  chai_1.assert.isTrue(utils_1.utils.isValidDate(date));
710
- }));
711
- it('invalid date - Date from invalid string', () => __awaiter(this, void 0, void 0, function* () {
679
+ });
680
+ it('invalid date - Date from invalid string', async () => {
712
681
  const date = new Date('toto');
713
682
  chai_1.assert.isFalse(utils_1.utils.isValidDate(date));
714
- }));
715
- it('invalid date - various', () => __awaiter(this, void 0, void 0, function* () {
683
+ });
684
+ it('invalid date - various', async () => {
716
685
  for (const date of [[], 123, `toto`, {}, ``, ` `, null, undefined]) {
717
686
  chai_1.assert.isFalse(utils_1.utils.isValidDate(date));
718
687
  }
719
- }));
688
+ });
720
689
  });
721
690
  describe('dateTransformer', () => {
722
- it('valid date as Date', () => __awaiter(this, void 0, void 0, function* () {
691
+ it('valid date as Date', async () => {
723
692
  const date = utils_1.utils.dateTransformer(new Date());
724
693
  chai_1.assert.isOk(date);
725
694
  chai_1.assert.isTrue(utils_1.utils.isValidDate(date));
726
- }));
727
- it('valid date as string', () => __awaiter(this, void 0, void 0, function* () {
695
+ });
696
+ it('valid date as string', async () => {
728
697
  let date = utils_1.utils.dateTransformer('2011-04-11T10:20:30Z');
729
698
  chai_1.assert.isOk(date);
730
699
  chai_1.assert.isTrue(utils_1.utils.isValidDate(date));
731
700
  date = utils_1.utils.dateTransformer('2011-04-11');
732
701
  chai_1.assert.isOk(date);
733
702
  chai_1.assert.isTrue(utils_1.utils.isValidDate(date));
734
- }));
735
- it('empty date', () => __awaiter(this, void 0, void 0, function* () {
703
+ });
704
+ it('empty date', async () => {
736
705
  for (const dateLike of [null, undefined]) {
737
706
  const date = utils_1.utils.dateTransformer(dateLike);
738
707
  chai_1.assert.isNull(date);
739
708
  }
740
- }));
741
- it('invalid date', () => __awaiter(this, void 0, void 0, function* () {
709
+ });
710
+ it('invalid date', async () => {
742
711
  for (const dateLike of [``, ` `, 123, true, [], {}, 'toto']) {
743
712
  const date = utils_1.utils.dateTransformer(dateLike);
744
713
  chai_1.assert.isOk(date);
745
714
  chai_1.assert.isFalse(utils_1.utils.isValidDate(date));
746
715
  }
747
- }));
716
+ });
748
717
  });
749
718
  describe('throwNotManaged', () => {
750
719
  const tmpRepPath = constants_1.constants.testDataDirPath + '/test_throwNotManaged';
751
- before(() => __awaiter(this, void 0, void 0, function* () {
720
+ before(async () => {
752
721
  if (!fs.existsSync(constants_1.constants.testDataDirPath)) {
753
722
  fs.mkdirSync(constants_1.constants.testDataDirPath);
754
723
  }
@@ -756,52 +725,48 @@ describe("App's utilities functions", function () {
756
725
  fs.removeSync(tmpRepPath);
757
726
  }
758
727
  fs.mkdirSync(tmpRepPath);
759
- }));
760
- after(() => __awaiter(this, void 0, void 0, function* () {
728
+ });
729
+ after(async () => {
761
730
  fs.removeSync(constants_1.constants.testDataDirPath);
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);
731
+ });
732
+ it('compile', async function () {
733
+ // May take some time to compile...
734
+ this.timeout(7000);
735
+ const fileName = (0, uuid_1.v4)();
736
+ const filesPathPrefix = tmpRepPath + '/' + fileName;
737
+ const tsFilePath = filesPathPrefix + '.ts';
738
+ const content = fs.readFileSync(constants_1.constants.libRoot + '/tests-resources/throwNotManagedSuccess.txt', {
739
+ encoding: 'utf-8',
778
740
  });
741
+ fs.writeFileSync(tsFilePath, content);
742
+ await utils_1.utils.tsc([tsFilePath]);
743
+ const distRepPath = constants_1.constants.libRoot + '/dist/test-data/test_throwNotManaged';
744
+ chai_1.assert.isTrue(fs.existsSync(distRepPath + '/' + fileName + '.js'));
745
+ fs.removeSync(distRepPath);
779
746
  });
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
- }
747
+ it("doesn't compile", async function () {
748
+ // May take some time to compile...
749
+ this.timeout(7000);
750
+ if (fs.existsSync(tmpRepPath)) {
751
+ fs.removeSync(tmpRepPath);
752
+ }
753
+ fs.mkdirSync(tmpRepPath);
754
+ const fileName = (0, uuid_1.v4)();
755
+ const filesPathPrefix = tmpRepPath + '/' + fileName;
756
+ const tsFilePath = filesPathPrefix + '.ts';
757
+ const content = fs.readFileSync(constants_1.constants.libRoot + '/tests-resources/throwNotManagedFail.txt', {
758
+ encoding: 'utf-8',
802
759
  });
760
+ fs.writeFileSync(tsFilePath, content);
761
+ try {
762
+ await utils_1.utils.tsc([tsFilePath]);
763
+ chai_1.assert.fail();
764
+ }
765
+ catch (err) {
766
+ // ok
767
+ }
803
768
  });
804
- it('throws error', () => __awaiter(this, void 0, void 0, function* () {
769
+ it('throws error', async () => {
805
770
  try {
806
771
  utils_1.utils.throwNotManaged('my message', 'oups');
807
772
  chai_1.assert.fail();
@@ -809,7 +774,7 @@ describe("App's utilities functions", function () {
809
774
  catch (err) {
810
775
  /* ok */
811
776
  }
812
- }));
777
+ });
813
778
  });
814
779
  // ==========================================
815
780
  // isObjectStrict()
@@ -1001,14 +966,14 @@ describe("App's utilities functions", function () {
1001
966
  // ==========================================
1002
967
  describe('exec()', () => {
1003
968
  const dummyJs = `dist/tests-resources/exec/execTest`;
1004
- it('default', () => __awaiter(this, void 0, void 0, function* () {
1005
- const exitCode = yield utils_1.utils.exec(`node`, [dummyJs]);
969
+ it('default', async () => {
970
+ const exitCode = await utils_1.utils.exec(`node`, [dummyJs]);
1006
971
  chai_1.assert.deepEqual(exitCode, 0);
1007
- }));
1008
- it('bin missing', () => __awaiter(this, void 0, void 0, function* () {
972
+ });
973
+ it('bin missing', async () => {
1009
974
  for (const bin of [undefined, null, '']) {
1010
975
  try {
1011
- yield utils_1.utils.exec(bin);
976
+ await utils_1.utils.exec(bin);
1012
977
  }
1013
978
  catch (err) {
1014
979
  chai_1.assert.isTrue(err instanceof utils_1.ExecError);
@@ -1016,31 +981,31 @@ describe("App's utilities functions", function () {
1016
981
  chai_1.assert.notDeepEqual(err.exitCode, 0);
1017
982
  }
1018
983
  }
1019
- }));
1020
- it('invalid bin', () => __awaiter(this, void 0, void 0, function* () {
984
+ });
985
+ it('invalid bin', async () => {
1021
986
  try {
1022
- yield utils_1.utils.exec(`_NOPE`);
987
+ await utils_1.utils.exec(`_NOPE`);
1023
988
  }
1024
989
  catch (err) {
1025
990
  chai_1.assert.isTrue(err instanceof utils_1.ExecError);
1026
991
  chai_1.assert.isNumber(err.exitCode);
1027
992
  chai_1.assert.notDeepEqual(err.exitCode, 0);
1028
993
  }
1029
- }));
1030
- it('file arg error', () => __awaiter(this, void 0, void 0, function* () {
994
+ });
995
+ it('file arg error', async () => {
1031
996
  try {
1032
- yield utils_1.utils.exec(`node`, [`dist/_NOPE`]);
997
+ await utils_1.utils.exec(`node`, [`dist/_NOPE`]);
1033
998
  }
1034
999
  catch (err) {
1035
1000
  chai_1.assert.isTrue(err instanceof utils_1.ExecError);
1036
1001
  chai_1.assert.isNumber(err.exitCode);
1037
1002
  chai_1.assert.notDeepEqual(err.exitCode, 0);
1038
1003
  }
1039
- }));
1040
- it('error', () => __awaiter(this, void 0, void 0, function* () {
1004
+ });
1005
+ it('error', async () => {
1041
1006
  let error;
1042
1007
  try {
1043
- yield utils_1.utils.exec(`node`, [dummyJs, `error`]);
1008
+ await utils_1.utils.exec(`node`, [dummyJs, `error`]);
1044
1009
  }
1045
1010
  catch (err) {
1046
1011
  error = err;
@@ -1051,15 +1016,15 @@ describe("App's utilities functions", function () {
1051
1016
  chai_1.assert.isTrue(error instanceof utils_1.ExecError);
1052
1017
  chai_1.assert.isNumber(error.exitCode);
1053
1018
  chai_1.assert.notDeepEqual(error.exitCode, 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`]);
1019
+ });
1020
+ it('exit code explicitly 0', async () => {
1021
+ const exitCode = await utils_1.utils.exec(`node`, [dummyJs, `customExitCode`, `0`]);
1057
1022
  chai_1.assert.deepEqual(exitCode, 0);
1058
- }));
1059
- it('custom exit code - error', () => __awaiter(this, void 0, void 0, function* () {
1023
+ });
1024
+ it('custom exit code - error', async () => {
1060
1025
  let error;
1061
1026
  try {
1062
- yield utils_1.utils.exec(`node`, [dummyJs, `customExitCode`, `123`]);
1027
+ await utils_1.utils.exec(`node`, [dummyJs, `customExitCode`, `123`]);
1063
1028
  }
1064
1029
  catch (err) {
1065
1030
  error = err;
@@ -1070,25 +1035,25 @@ describe("App's utilities functions", function () {
1070
1035
  chai_1.assert.isTrue(error instanceof utils_1.ExecError);
1071
1036
  chai_1.assert.isNumber(error.exitCode);
1072
1037
  chai_1.assert.deepEqual(error.exitCode, 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`], {
1038
+ });
1039
+ it('custom exit code - success', async () => {
1040
+ const exitCode = await utils_1.utils.exec(`node`, [dummyJs, `customExitCode`, `123`], {
1076
1041
  successExitCodes: 123,
1077
1042
  });
1078
1043
  chai_1.assert.deepEqual(exitCode, 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`], {
1044
+ });
1045
+ it('custom exit code - multiple', async () => {
1046
+ let exitCode = await utils_1.utils.exec(`node`, [dummyJs, `customExitCode`, `123`], {
1082
1047
  successExitCodes: [0, 123],
1083
1048
  });
1084
1049
  chai_1.assert.deepEqual(exitCode, 123);
1085
- exitCode = yield utils_1.utils.exec(`node`, [dummyJs, `success`], {
1050
+ exitCode = await utils_1.utils.exec(`node`, [dummyJs, `success`], {
1086
1051
  successExitCodes: [0, 123],
1087
1052
  });
1088
1053
  chai_1.assert.deepEqual(exitCode, 0);
1089
1054
  let error;
1090
1055
  try {
1091
- yield utils_1.utils.exec(`node`, [dummyJs, `customExitCode`, `1`], {
1056
+ await utils_1.utils.exec(`node`, [dummyJs, `customExitCode`, `1`], {
1092
1057
  successExitCodes: [0, 123],
1093
1058
  });
1094
1059
  }
@@ -1101,8 +1066,8 @@ describe("App's utilities functions", function () {
1101
1066
  chai_1.assert.isTrue(error instanceof utils_1.ExecError);
1102
1067
  chai_1.assert.isNumber(error.exitCode);
1103
1068
  chai_1.assert.deepEqual(error.exitCode, 1);
1104
- }));
1105
- it('output handler', () => __awaiter(this, void 0, void 0, function* () {
1069
+ });
1070
+ it('output handler', async () => {
1106
1071
  let currentOut = '';
1107
1072
  let currentErr = '';
1108
1073
  let execOut = '';
@@ -1118,7 +1083,7 @@ describe("App's utilities functions", function () {
1118
1083
  currentErr += chunk.toString();
1119
1084
  return true;
1120
1085
  };
1121
- yield utils_1.utils.exec(`node`, [dummyJs], {
1086
+ await utils_1.utils.exec(`node`, [dummyJs], {
1122
1087
  outputHandler: (stdoutOutput, stderrOutput) => {
1123
1088
  execOut += stdoutOutput ? stdoutOutput : '';
1124
1089
  execErr += stderrOutput ? stderrOutput : '';
@@ -1137,8 +1102,8 @@ describe("App's utilities functions", function () {
1137
1102
  process.stdout.write = stdOutOriginal;
1138
1103
  process.stderr.write = stdErrOriginal;
1139
1104
  }
1140
- }));
1141
- it('output handler + disableConsoleOutputs', () => __awaiter(this, void 0, void 0, function* () {
1105
+ });
1106
+ it('output handler + disableConsoleOutputs', async () => {
1142
1107
  let currentOut = '';
1143
1108
  let currentErr = '';
1144
1109
  let execOut = '';
@@ -1154,7 +1119,7 @@ describe("App's utilities functions", function () {
1154
1119
  currentErr += chunk.toString();
1155
1120
  return true;
1156
1121
  };
1157
- yield utils_1.utils.exec(`node`, [dummyJs], {
1122
+ await utils_1.utils.exec(`node`, [dummyJs], {
1158
1123
  outputHandler: (stdoutOutput, stderrOutput) => {
1159
1124
  execOut += stdoutOutput ? stdoutOutput : '';
1160
1125
  execErr += stderrOutput ? stderrOutput : '';
@@ -1172,11 +1137,11 @@ describe("App's utilities functions", function () {
1172
1137
  process.stdout.write = stdOutOriginal;
1173
1138
  process.stderr.write = stdErrOriginal;
1174
1139
  }
1175
- }));
1176
- it('execPromisified deprecated but still working', () => __awaiter(this, void 0, void 0, function* () {
1140
+ });
1141
+ it('execPromisified deprecated but still working', async () => {
1177
1142
  let execOut = '';
1178
1143
  let execErr = '';
1179
- const exitCode = yield utils_1.utils.execPromisified(`node`, [dummyJs], (stdoutOutput, stderrOutput) => {
1144
+ const exitCode = await utils_1.utils.execPromisified(`node`, [dummyJs], (stdoutOutput, stderrOutput) => {
1180
1145
  execOut += stdoutOutput ? stdoutOutput : '';
1181
1146
  execErr += stderrOutput ? stderrOutput : '';
1182
1147
  });
@@ -1185,11 +1150,11 @@ describe("App's utilities functions", function () {
1185
1150
  chai_1.assert.isFalse(execOut.includes(`in dummy - error`));
1186
1151
  chai_1.assert.isFalse(execErr.includes(`in dummy - info`));
1187
1152
  chai_1.assert.isTrue(execErr.includes(`in dummy - error`));
1188
- }));
1189
- it('execPromisified deprecated but still working - error', () => __awaiter(this, void 0, void 0, function* () {
1153
+ });
1154
+ it('execPromisified deprecated but still working - error', async () => {
1190
1155
  let error;
1191
1156
  try {
1192
- yield utils_1.utils.execPromisified(`node`, [dummyJs, `error`]);
1157
+ await utils_1.utils.execPromisified(`node`, [dummyJs, `error`]);
1193
1158
  }
1194
1159
  catch (err) {
1195
1160
  error = err;
@@ -1197,7 +1162,7 @@ describe("App's utilities functions", function () {
1197
1162
  if (!error) {
1198
1163
  chai_1.assert.fail();
1199
1164
  }
1200
- }));
1165
+ });
1201
1166
  });
1202
1167
  });
1203
1168
  //# sourceMappingURL=utils.test.js.map