@villedemontreal/general-utils 5.17.5 → 5.17.6
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.
- package/dist/src/apiError.test.js +32 -41
- package/dist/src/apiError.test.js.map +1 -1
- package/dist/src/dateUtils.js.map +1 -1
- package/dist/src/dateUtils.test.js.map +1 -1
- package/dist/src/pagination.test.js +2 -11
- package/dist/src/pagination.test.js.map +1 -1
- package/dist/src/timer.test.js +32 -47
- package/dist/src/timer.test.js.map +1 -1
- package/dist/src/utils.js +95 -117
- package/dist/src/utils.js.map +1 -1
- package/dist/src/utils.test.js +165 -177
- package/dist/src/utils.test.js.map +1 -1
- package/dist/test-data/test_throwNotManaged/99039260-e610-4019-91c3-9ef4255a214b.d.ts +1 -0
- package/dist/test-data/test_throwNotManaged/99039260-e610-4019-91c3-9ef4255a214b.js +13 -0
- package/dist/test-data/test_throwNotManaged/99039260-e610-4019-91c3-9ef4255a214b.js.map +1 -0
- package/dist/tests-resources/exec/execTest.js +2 -11
- package/dist/tests-resources/exec/execTest.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +17 -17
- package/src/dateUtils.test.ts +3 -1
- package/src/dateUtils.ts +0 -1
- package/src/utils.test.ts +4 -0
- package/dist/scripts/index.d.ts +0 -2
- package/dist/scripts/index.js +0 -14
- package/dist/scripts/index.js.map +0 -1
- package/dist/scripts/lint.d.ts +0 -6
- package/dist/scripts/lint.js +0 -31
- package/dist/scripts/lint.js.map +0 -1
- package/dist/scripts/lintFix.d.ts +0 -6
- package/dist/scripts/lintFix.js +0 -40
- package/dist/scripts/lintFix.js.map +0 -1
package/dist/src/utils.test.js
CHANGED
|
@@ -29,15 +29,6 @@ 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
|
-
};
|
|
41
32
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
33
|
const chai_1 = require("chai");
|
|
43
34
|
const fs = __importStar(require("fs-extra"));
|
|
@@ -48,33 +39,34 @@ const utils_1 = require("./utils");
|
|
|
48
39
|
// @see https://github.com/mochajs/mocha/issues/2018
|
|
49
40
|
// tslint:disable-next-line:only-arrow-functions ter-prefer-arrow-callback
|
|
50
41
|
describe("App's utilities functions", function () {
|
|
42
|
+
this.beforeAll(() => {
|
|
43
|
+
constants_1.constants.appRoot = constants_1.constants.libRoot; // because our lib is within a monorepo
|
|
44
|
+
});
|
|
51
45
|
// ==========================================
|
|
52
46
|
// tsc()
|
|
53
47
|
// ==========================================
|
|
54
48
|
describe('tsc', () => {
|
|
55
|
-
it("Compiles a TypeScript file using the 'tsc()' utility", function () {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
fs.removeSync(distRepPath + '/test-data');
|
|
77
|
-
});
|
|
49
|
+
it("Compiles a TypeScript file using the 'tsc()' utility", async function () {
|
|
50
|
+
if (!fs.existsSync(constants_1.constants.testDataDirPath)) {
|
|
51
|
+
fs.mkdirSync(constants_1.constants.testDataDirPath);
|
|
52
|
+
}
|
|
53
|
+
// May take some time to compile...
|
|
54
|
+
this.timeout(20000);
|
|
55
|
+
const tmpRepPath = constants_1.constants.testDataDirPath + '/test_tsc';
|
|
56
|
+
if (fs.existsSync(tmpRepPath)) {
|
|
57
|
+
fs.removeSync(tmpRepPath);
|
|
58
|
+
}
|
|
59
|
+
fs.mkdirSync(tmpRepPath);
|
|
60
|
+
const fileName = (0, uuid_1.v4)();
|
|
61
|
+
const filesPathPrefix = tmpRepPath + '/' + fileName;
|
|
62
|
+
const tsFilePath = filesPathPrefix + '.ts';
|
|
63
|
+
fs.writeFileSync(tsFilePath, `import * as path from 'path';\nlet t = 'a';\nt = t + path.sep;`);
|
|
64
|
+
const distRepPath = constants_1.constants.libRoot + '/dist';
|
|
65
|
+
await utils_1.utils.tsc([tsFilePath]);
|
|
66
|
+
chai_1.assert.isTrue(fs.existsSync(distRepPath + '/test-data/test_tsc/' + fileName + '.js'));
|
|
67
|
+
chai_1.assert.isTrue(fs.existsSync(distRepPath + '/test-data/test_tsc/' + fileName + '.js.map'));
|
|
68
|
+
chai_1.assert.isTrue(fs.existsSync(distRepPath + '/test-data/test_tsc/' + fileName + '.d.ts'));
|
|
69
|
+
fs.removeSync(distRepPath + '/test-data');
|
|
78
70
|
});
|
|
79
71
|
});
|
|
80
72
|
// ==========================================
|
|
@@ -455,19 +447,19 @@ describe("App's utilities functions", function () {
|
|
|
455
447
|
// sleep()
|
|
456
448
|
// ==========================================
|
|
457
449
|
describe('sleep()', () => {
|
|
458
|
-
it("The 'sleep()' function await correctly", () =>
|
|
450
|
+
it("The 'sleep()' function await correctly", async () => {
|
|
459
451
|
const start = new Date().getTime();
|
|
460
|
-
|
|
452
|
+
await utils_1.utils.sleep(500);
|
|
461
453
|
const end = new Date().getTime();
|
|
462
454
|
chai_1.assert.isTrue(end - start > 450);
|
|
463
|
-
})
|
|
455
|
+
});
|
|
464
456
|
});
|
|
465
457
|
// ==========================================
|
|
466
458
|
// isSafeToDelete()
|
|
467
459
|
// ==========================================
|
|
468
460
|
describe('isSafeToDelete()', () => {
|
|
469
461
|
const utilsObj = new utils_1.Utils();
|
|
470
|
-
it('Safe paths', () =>
|
|
462
|
+
it('Safe paths', async () => {
|
|
471
463
|
chai_1.assert.isTrue(utilsObj.isSafeToDelete('/toto/titi'));
|
|
472
464
|
chai_1.assert.isTrue(utilsObj.isSafeToDelete('/toto/titi.txt'));
|
|
473
465
|
chai_1.assert.isTrue(utilsObj.isSafeToDelete('/toto/.titi'));
|
|
@@ -482,8 +474,8 @@ describe("App's utilities functions", function () {
|
|
|
482
474
|
chai_1.assert.isTrue(utilsObj.isSafeToDelete('C:/toto/.titi'));
|
|
483
475
|
chai_1.assert.isTrue(utilsObj.isSafeToDelete('C:/toto/titi/tutu'));
|
|
484
476
|
chai_1.assert.isTrue(utilsObj.isSafeToDelete('C:/toto/titi/tutu.txt'));
|
|
485
|
-
})
|
|
486
|
-
it('Unsafe paths', () =>
|
|
477
|
+
});
|
|
478
|
+
it('Unsafe paths', async () => {
|
|
487
479
|
chai_1.assert.isFalse(utilsObj.isSafeToDelete(undefined));
|
|
488
480
|
chai_1.assert.isFalse(utilsObj.isSafeToDelete(null));
|
|
489
481
|
chai_1.assert.isFalse(utilsObj.isSafeToDelete(''));
|
|
@@ -520,17 +512,17 @@ describe("App's utilities functions", function () {
|
|
|
520
512
|
chai_1.assert.isFalse(utilsObj.isSafeToDelete('\r'));
|
|
521
513
|
chai_1.assert.isFalse(utilsObj.isSafeToDelete('\n'));
|
|
522
514
|
chai_1.assert.isFalse(utilsObj.isSafeToDelete('\t'));
|
|
523
|
-
})
|
|
515
|
+
});
|
|
524
516
|
});
|
|
525
517
|
// ==========================================
|
|
526
518
|
// isDir()
|
|
527
519
|
// ==========================================
|
|
528
520
|
describe('isDir()', () => {
|
|
529
|
-
before(() =>
|
|
521
|
+
before(async () => {
|
|
530
522
|
if (!fs.existsSync(constants_1.constants.testDataDirPath)) {
|
|
531
523
|
fs.mkdirSync(constants_1.constants.testDataDirPath);
|
|
532
524
|
}
|
|
533
|
-
})
|
|
525
|
+
});
|
|
534
526
|
it('Is dir', () => {
|
|
535
527
|
const thePath = constants_1.constants.testDataDirPath + '/' + (0, uuid_1.v4)();
|
|
536
528
|
chai_1.assert.isFalse(utils_1.utils.isDir(thePath));
|
|
@@ -574,34 +566,34 @@ describe("App's utilities functions", function () {
|
|
|
574
566
|
// ==========================================
|
|
575
567
|
// deleteFile()
|
|
576
568
|
// ==========================================
|
|
577
|
-
describe('deleteFile()', () =>
|
|
578
|
-
it('Safe file', () =>
|
|
569
|
+
describe('deleteFile()', async () => {
|
|
570
|
+
it('Safe file', async () => {
|
|
579
571
|
const tempFilePath = constants_1.constants.testDataDirPath + '/tmp' + new Date().getTime();
|
|
580
572
|
chai_1.assert.isFalse(fs.existsSync(tempFilePath));
|
|
581
573
|
fs.createFileSync(tempFilePath);
|
|
582
574
|
chai_1.assert.isTrue(fs.existsSync(tempFilePath));
|
|
583
|
-
|
|
575
|
+
await utils_1.utils.deleteFile(tempFilePath);
|
|
584
576
|
chai_1.assert.isFalse(fs.existsSync(tempFilePath));
|
|
585
|
-
})
|
|
586
|
-
it('Unsafe file', () =>
|
|
577
|
+
});
|
|
578
|
+
it('Unsafe file', async () => {
|
|
587
579
|
// root file
|
|
588
580
|
const tempFilePath = '/tmp' + new Date().getTime();
|
|
589
581
|
chai_1.assert.isFalse(fs.existsSync(tempFilePath));
|
|
590
582
|
let error = false;
|
|
591
583
|
try {
|
|
592
|
-
|
|
584
|
+
await utils_1.utils.deleteFile(tempFilePath);
|
|
593
585
|
}
|
|
594
586
|
catch (err) {
|
|
595
587
|
error = true;
|
|
596
588
|
}
|
|
597
589
|
chai_1.assert.isTrue(error);
|
|
598
|
-
})
|
|
599
|
-
})
|
|
590
|
+
});
|
|
591
|
+
});
|
|
600
592
|
// ==========================================
|
|
601
593
|
// deleteDir()
|
|
602
594
|
// ==========================================
|
|
603
|
-
describe('deleteDir()', () =>
|
|
604
|
-
it('Safe dir', () =>
|
|
595
|
+
describe('deleteDir()', async () => {
|
|
596
|
+
it('Safe dir', async () => {
|
|
605
597
|
const tempFilePath = constants_1.constants.testDataDirPath + '/tmp' + new Date().getTime();
|
|
606
598
|
chai_1.assert.isFalse(fs.existsSync(tempFilePath));
|
|
607
599
|
fs.mkdirSync(tempFilePath);
|
|
@@ -609,27 +601,27 @@ describe("App's utilities functions", function () {
|
|
|
609
601
|
fs.mkdirSync(tempFilePath + '/subDir');
|
|
610
602
|
fs.createFileSync(tempFilePath + '/subDir/.anotherFile');
|
|
611
603
|
chai_1.assert.isTrue(fs.existsSync(tempFilePath));
|
|
612
|
-
|
|
604
|
+
await utils_1.utils.deleteDir(tempFilePath);
|
|
613
605
|
chai_1.assert.isFalse(fs.existsSync(tempFilePath));
|
|
614
|
-
})
|
|
615
|
-
it('Unsafe dir', () =>
|
|
606
|
+
});
|
|
607
|
+
it('Unsafe dir', async () => {
|
|
616
608
|
const tempFilePath = '/tmp' + new Date().getTime();
|
|
617
609
|
chai_1.assert.isFalse(fs.existsSync(tempFilePath));
|
|
618
610
|
let error = false;
|
|
619
611
|
try {
|
|
620
|
-
|
|
612
|
+
await utils_1.utils.deleteDir(tempFilePath);
|
|
621
613
|
}
|
|
622
614
|
catch (err) {
|
|
623
615
|
error = true;
|
|
624
616
|
}
|
|
625
617
|
chai_1.assert.isTrue(error);
|
|
626
|
-
})
|
|
627
|
-
})
|
|
618
|
+
});
|
|
619
|
+
});
|
|
628
620
|
// ==========================================
|
|
629
621
|
// clearDir()
|
|
630
622
|
// ==========================================
|
|
631
|
-
describe('clearDir()', () =>
|
|
632
|
-
it('Safe dir', () =>
|
|
623
|
+
describe('clearDir()', async () => {
|
|
624
|
+
it('Safe dir', async () => {
|
|
633
625
|
if (!fs.existsSync(constants_1.constants.testDataDirPath)) {
|
|
634
626
|
fs.mkdirSync(constants_1.constants.testDataDirPath);
|
|
635
627
|
}
|
|
@@ -645,34 +637,34 @@ describe("App's utilities functions", function () {
|
|
|
645
637
|
chai_1.assert.isTrue(fs.existsSync(tempFilePath + '/someFile'));
|
|
646
638
|
chai_1.assert.isTrue(fs.existsSync(tempFilePath + '/.someFile2'));
|
|
647
639
|
chai_1.assert.isTrue(fs.existsSync(tempFilePath + '/subDir'));
|
|
648
|
-
|
|
640
|
+
await utils_1.utils.clearDir(tempFilePath);
|
|
649
641
|
chai_1.assert.isTrue(fs.existsSync(tempFilePath));
|
|
650
642
|
chai_1.assert.isFalse(fs.existsSync(tempFilePath + '/someFile'));
|
|
651
643
|
chai_1.assert.isFalse(fs.existsSync(tempFilePath + '/.someFile2'));
|
|
652
644
|
chai_1.assert.isFalse(fs.existsSync(tempFilePath + '/subDir'));
|
|
653
645
|
}
|
|
654
646
|
finally {
|
|
655
|
-
|
|
647
|
+
await utils_1.utils.deleteDir(tempFilePath);
|
|
656
648
|
}
|
|
657
|
-
})
|
|
658
|
-
it('Unsafe dir', () =>
|
|
649
|
+
});
|
|
650
|
+
it('Unsafe dir', async () => {
|
|
659
651
|
const tempFilePath = '/tmp' + new Date().getTime();
|
|
660
652
|
chai_1.assert.isFalse(fs.existsSync(tempFilePath));
|
|
661
653
|
let error = false;
|
|
662
654
|
try {
|
|
663
|
-
|
|
655
|
+
await utils_1.utils.clearDir(tempFilePath);
|
|
664
656
|
}
|
|
665
657
|
catch (err) {
|
|
666
658
|
error = true;
|
|
667
659
|
}
|
|
668
660
|
chai_1.assert.isTrue(error);
|
|
669
|
-
})
|
|
670
|
-
})
|
|
661
|
+
});
|
|
662
|
+
});
|
|
671
663
|
// ==========================================
|
|
672
664
|
// getDefinedOrNull()
|
|
673
665
|
// ==========================================
|
|
674
|
-
describe('getDefinedOrNull()', () =>
|
|
675
|
-
it('Defined stays untouches', () =>
|
|
666
|
+
describe('getDefinedOrNull()', async () => {
|
|
667
|
+
it('Defined stays untouches', async () => {
|
|
676
668
|
let res = utils_1.utils.getDefinedOrNull('abc');
|
|
677
669
|
chai_1.assert.strictEqual(res, 'abc');
|
|
678
670
|
res = utils_1.utils.getDefinedOrNull('');
|
|
@@ -683,72 +675,72 @@ describe("App's utilities functions", function () {
|
|
|
683
675
|
chai_1.assert.deepEqual(res, {});
|
|
684
676
|
res = utils_1.utils.getDefinedOrNull([]);
|
|
685
677
|
chai_1.assert.deepEqual(res, []);
|
|
686
|
-
})
|
|
687
|
-
it('Null stays Null', () =>
|
|
678
|
+
});
|
|
679
|
+
it('Null stays Null', async () => {
|
|
688
680
|
const res = utils_1.utils.getDefinedOrNull(null);
|
|
689
681
|
chai_1.assert.strictEqual(res, null);
|
|
690
|
-
})
|
|
691
|
-
it('Undefined becomes Null', () =>
|
|
682
|
+
});
|
|
683
|
+
it('Undefined becomes Null', async () => {
|
|
692
684
|
const res = utils_1.utils.getDefinedOrNull(undefined);
|
|
693
685
|
chai_1.assert.strictEqual(res, null);
|
|
694
|
-
})
|
|
695
|
-
})
|
|
686
|
+
});
|
|
687
|
+
});
|
|
696
688
|
describe('findFreePort', () => {
|
|
697
|
-
it('', () =>
|
|
698
|
-
const port =
|
|
689
|
+
it('', async () => {
|
|
690
|
+
const port = await utils_1.utils.findFreePort();
|
|
699
691
|
chai_1.assert.isOk(port);
|
|
700
692
|
chai_1.assert.isNumber(port);
|
|
701
|
-
})
|
|
693
|
+
});
|
|
702
694
|
});
|
|
703
695
|
describe('isValidDate', () => {
|
|
704
|
-
it('valid date - Date', () =>
|
|
696
|
+
it('valid date - Date', async () => {
|
|
705
697
|
chai_1.assert.isTrue(utils_1.utils.isValidDate(new Date()));
|
|
706
|
-
})
|
|
707
|
-
it('valid date - Date from valid string', () =>
|
|
698
|
+
});
|
|
699
|
+
it('valid date - Date from valid string', async () => {
|
|
708
700
|
const date = new Date('2011-04-11T10:20:30Z');
|
|
709
701
|
chai_1.assert.isTrue(utils_1.utils.isValidDate(date));
|
|
710
|
-
})
|
|
711
|
-
it('invalid date - Date from invalid string', () =>
|
|
702
|
+
});
|
|
703
|
+
it('invalid date - Date from invalid string', async () => {
|
|
712
704
|
const date = new Date('toto');
|
|
713
705
|
chai_1.assert.isFalse(utils_1.utils.isValidDate(date));
|
|
714
|
-
})
|
|
715
|
-
it('invalid date - various', () =>
|
|
706
|
+
});
|
|
707
|
+
it('invalid date - various', async () => {
|
|
716
708
|
for (const date of [[], 123, `toto`, {}, ``, ` `, null, undefined]) {
|
|
717
709
|
chai_1.assert.isFalse(utils_1.utils.isValidDate(date));
|
|
718
710
|
}
|
|
719
|
-
})
|
|
711
|
+
});
|
|
720
712
|
});
|
|
721
713
|
describe('dateTransformer', () => {
|
|
722
|
-
it('valid date as Date', () =>
|
|
714
|
+
it('valid date as Date', async () => {
|
|
723
715
|
const date = utils_1.utils.dateTransformer(new Date());
|
|
724
716
|
chai_1.assert.isOk(date);
|
|
725
717
|
chai_1.assert.isTrue(utils_1.utils.isValidDate(date));
|
|
726
|
-
})
|
|
727
|
-
it('valid date as string', () =>
|
|
718
|
+
});
|
|
719
|
+
it('valid date as string', async () => {
|
|
728
720
|
let date = utils_1.utils.dateTransformer('2011-04-11T10:20:30Z');
|
|
729
721
|
chai_1.assert.isOk(date);
|
|
730
722
|
chai_1.assert.isTrue(utils_1.utils.isValidDate(date));
|
|
731
723
|
date = utils_1.utils.dateTransformer('2011-04-11');
|
|
732
724
|
chai_1.assert.isOk(date);
|
|
733
725
|
chai_1.assert.isTrue(utils_1.utils.isValidDate(date));
|
|
734
|
-
})
|
|
735
|
-
it('empty date', () =>
|
|
726
|
+
});
|
|
727
|
+
it('empty date', async () => {
|
|
736
728
|
for (const dateLike of [null, undefined]) {
|
|
737
729
|
const date = utils_1.utils.dateTransformer(dateLike);
|
|
738
730
|
chai_1.assert.isNull(date);
|
|
739
731
|
}
|
|
740
|
-
})
|
|
741
|
-
it('invalid date', () =>
|
|
732
|
+
});
|
|
733
|
+
it('invalid date', async () => {
|
|
742
734
|
for (const dateLike of [``, ` `, 123, true, [], {}, 'toto']) {
|
|
743
735
|
const date = utils_1.utils.dateTransformer(dateLike);
|
|
744
736
|
chai_1.assert.isOk(date);
|
|
745
737
|
chai_1.assert.isFalse(utils_1.utils.isValidDate(date));
|
|
746
738
|
}
|
|
747
|
-
})
|
|
739
|
+
});
|
|
748
740
|
});
|
|
749
741
|
describe('throwNotManaged', () => {
|
|
750
742
|
const tmpRepPath = constants_1.constants.testDataDirPath + '/test_throwNotManaged';
|
|
751
|
-
before(() =>
|
|
743
|
+
before(async () => {
|
|
752
744
|
if (!fs.existsSync(constants_1.constants.testDataDirPath)) {
|
|
753
745
|
fs.mkdirSync(constants_1.constants.testDataDirPath);
|
|
754
746
|
}
|
|
@@ -756,52 +748,48 @@ describe("App's utilities functions", function () {
|
|
|
756
748
|
fs.removeSync(tmpRepPath);
|
|
757
749
|
}
|
|
758
750
|
fs.mkdirSync(tmpRepPath);
|
|
759
|
-
})
|
|
760
|
-
after(() =>
|
|
751
|
+
});
|
|
752
|
+
after(async () => {
|
|
761
753
|
fs.removeSync(constants_1.constants.testDataDirPath);
|
|
762
|
-
})
|
|
763
|
-
it('compile', function () {
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
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);
|
|
754
|
+
});
|
|
755
|
+
it('compile', async function () {
|
|
756
|
+
// May take some time to compile...
|
|
757
|
+
this.timeout(7000);
|
|
758
|
+
const fileName = (0, uuid_1.v4)();
|
|
759
|
+
const filesPathPrefix = tmpRepPath + '/' + fileName;
|
|
760
|
+
const tsFilePath = filesPathPrefix + '.ts';
|
|
761
|
+
const content = fs.readFileSync(constants_1.constants.libRoot + '/tests-resources/throwNotManagedSuccess.txt', {
|
|
762
|
+
encoding: 'utf-8',
|
|
778
763
|
});
|
|
764
|
+
fs.writeFileSync(tsFilePath, content);
|
|
765
|
+
await utils_1.utils.tsc([tsFilePath]);
|
|
766
|
+
const distRepPath = constants_1.constants.libRoot + '/dist/test-data/test_throwNotManaged';
|
|
767
|
+
chai_1.assert.isTrue(fs.existsSync(distRepPath + '/' + fileName + '.js'));
|
|
768
|
+
fs.removeSync(distRepPath);
|
|
779
769
|
});
|
|
780
|
-
it("doesn't compile", function () {
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
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
|
-
}
|
|
770
|
+
it("doesn't compile", async function () {
|
|
771
|
+
// May take some time to compile...
|
|
772
|
+
this.timeout(7000);
|
|
773
|
+
if (fs.existsSync(tmpRepPath)) {
|
|
774
|
+
fs.removeSync(tmpRepPath);
|
|
775
|
+
}
|
|
776
|
+
fs.mkdirSync(tmpRepPath);
|
|
777
|
+
const fileName = (0, uuid_1.v4)();
|
|
778
|
+
const filesPathPrefix = tmpRepPath + '/' + fileName;
|
|
779
|
+
const tsFilePath = filesPathPrefix + '.ts';
|
|
780
|
+
const content = fs.readFileSync(constants_1.constants.libRoot + '/tests-resources/throwNotManagedFail.txt', {
|
|
781
|
+
encoding: 'utf-8',
|
|
802
782
|
});
|
|
783
|
+
fs.writeFileSync(tsFilePath, content);
|
|
784
|
+
try {
|
|
785
|
+
await utils_1.utils.tsc([tsFilePath]);
|
|
786
|
+
chai_1.assert.fail();
|
|
787
|
+
}
|
|
788
|
+
catch (err) {
|
|
789
|
+
// ok
|
|
790
|
+
}
|
|
803
791
|
});
|
|
804
|
-
it('throws error', () =>
|
|
792
|
+
it('throws error', async () => {
|
|
805
793
|
try {
|
|
806
794
|
utils_1.utils.throwNotManaged('my message', 'oups');
|
|
807
795
|
chai_1.assert.fail();
|
|
@@ -809,7 +797,7 @@ describe("App's utilities functions", function () {
|
|
|
809
797
|
catch (err) {
|
|
810
798
|
/* ok */
|
|
811
799
|
}
|
|
812
|
-
})
|
|
800
|
+
});
|
|
813
801
|
});
|
|
814
802
|
// ==========================================
|
|
815
803
|
// isObjectStrict()
|
|
@@ -1001,14 +989,14 @@ describe("App's utilities functions", function () {
|
|
|
1001
989
|
// ==========================================
|
|
1002
990
|
describe('exec()', () => {
|
|
1003
991
|
const dummyJs = `dist/tests-resources/exec/execTest`;
|
|
1004
|
-
it('default', () =>
|
|
1005
|
-
const exitCode =
|
|
992
|
+
it('default', async () => {
|
|
993
|
+
const exitCode = await utils_1.utils.exec(`node`, [dummyJs]);
|
|
1006
994
|
chai_1.assert.deepEqual(exitCode, 0);
|
|
1007
|
-
})
|
|
1008
|
-
it('bin missing', () =>
|
|
995
|
+
});
|
|
996
|
+
it('bin missing', async () => {
|
|
1009
997
|
for (const bin of [undefined, null, '']) {
|
|
1010
998
|
try {
|
|
1011
|
-
|
|
999
|
+
await utils_1.utils.exec(bin);
|
|
1012
1000
|
}
|
|
1013
1001
|
catch (err) {
|
|
1014
1002
|
chai_1.assert.isTrue(err instanceof utils_1.ExecError);
|
|
@@ -1016,31 +1004,31 @@ describe("App's utilities functions", function () {
|
|
|
1016
1004
|
chai_1.assert.notDeepEqual(err.exitCode, 0);
|
|
1017
1005
|
}
|
|
1018
1006
|
}
|
|
1019
|
-
})
|
|
1020
|
-
it('invalid bin', () =>
|
|
1007
|
+
});
|
|
1008
|
+
it('invalid bin', async () => {
|
|
1021
1009
|
try {
|
|
1022
|
-
|
|
1010
|
+
await utils_1.utils.exec(`_NOPE`);
|
|
1023
1011
|
}
|
|
1024
1012
|
catch (err) {
|
|
1025
1013
|
chai_1.assert.isTrue(err instanceof utils_1.ExecError);
|
|
1026
1014
|
chai_1.assert.isNumber(err.exitCode);
|
|
1027
1015
|
chai_1.assert.notDeepEqual(err.exitCode, 0);
|
|
1028
1016
|
}
|
|
1029
|
-
})
|
|
1030
|
-
it('file arg error', () =>
|
|
1017
|
+
});
|
|
1018
|
+
it('file arg error', async () => {
|
|
1031
1019
|
try {
|
|
1032
|
-
|
|
1020
|
+
await utils_1.utils.exec(`node`, [`dist/_NOPE`]);
|
|
1033
1021
|
}
|
|
1034
1022
|
catch (err) {
|
|
1035
1023
|
chai_1.assert.isTrue(err instanceof utils_1.ExecError);
|
|
1036
1024
|
chai_1.assert.isNumber(err.exitCode);
|
|
1037
1025
|
chai_1.assert.notDeepEqual(err.exitCode, 0);
|
|
1038
1026
|
}
|
|
1039
|
-
})
|
|
1040
|
-
it('error', () =>
|
|
1027
|
+
});
|
|
1028
|
+
it('error', async () => {
|
|
1041
1029
|
let error;
|
|
1042
1030
|
try {
|
|
1043
|
-
|
|
1031
|
+
await utils_1.utils.exec(`node`, [dummyJs, `error`]);
|
|
1044
1032
|
}
|
|
1045
1033
|
catch (err) {
|
|
1046
1034
|
error = err;
|
|
@@ -1051,15 +1039,15 @@ describe("App's utilities functions", function () {
|
|
|
1051
1039
|
chai_1.assert.isTrue(error instanceof utils_1.ExecError);
|
|
1052
1040
|
chai_1.assert.isNumber(error.exitCode);
|
|
1053
1041
|
chai_1.assert.notDeepEqual(error.exitCode, 0);
|
|
1054
|
-
})
|
|
1055
|
-
it('exit code explicitly 0', () =>
|
|
1056
|
-
const exitCode =
|
|
1042
|
+
});
|
|
1043
|
+
it('exit code explicitly 0', async () => {
|
|
1044
|
+
const exitCode = await utils_1.utils.exec(`node`, [dummyJs, `customExitCode`, `0`]);
|
|
1057
1045
|
chai_1.assert.deepEqual(exitCode, 0);
|
|
1058
|
-
})
|
|
1059
|
-
it('custom exit code - error', () =>
|
|
1046
|
+
});
|
|
1047
|
+
it('custom exit code - error', async () => {
|
|
1060
1048
|
let error;
|
|
1061
1049
|
try {
|
|
1062
|
-
|
|
1050
|
+
await utils_1.utils.exec(`node`, [dummyJs, `customExitCode`, `123`]);
|
|
1063
1051
|
}
|
|
1064
1052
|
catch (err) {
|
|
1065
1053
|
error = err;
|
|
@@ -1070,25 +1058,25 @@ describe("App's utilities functions", function () {
|
|
|
1070
1058
|
chai_1.assert.isTrue(error instanceof utils_1.ExecError);
|
|
1071
1059
|
chai_1.assert.isNumber(error.exitCode);
|
|
1072
1060
|
chai_1.assert.deepEqual(error.exitCode, 123);
|
|
1073
|
-
})
|
|
1074
|
-
it('custom exit code - success', () =>
|
|
1075
|
-
const exitCode =
|
|
1061
|
+
});
|
|
1062
|
+
it('custom exit code - success', async () => {
|
|
1063
|
+
const exitCode = await utils_1.utils.exec(`node`, [dummyJs, `customExitCode`, `123`], {
|
|
1076
1064
|
successExitCodes: 123,
|
|
1077
1065
|
});
|
|
1078
1066
|
chai_1.assert.deepEqual(exitCode, 123);
|
|
1079
|
-
})
|
|
1080
|
-
it('custom exit code - multiple', () =>
|
|
1081
|
-
let exitCode =
|
|
1067
|
+
});
|
|
1068
|
+
it('custom exit code - multiple', async () => {
|
|
1069
|
+
let exitCode = await utils_1.utils.exec(`node`, [dummyJs, `customExitCode`, `123`], {
|
|
1082
1070
|
successExitCodes: [0, 123],
|
|
1083
1071
|
});
|
|
1084
1072
|
chai_1.assert.deepEqual(exitCode, 123);
|
|
1085
|
-
exitCode =
|
|
1073
|
+
exitCode = await utils_1.utils.exec(`node`, [dummyJs, `success`], {
|
|
1086
1074
|
successExitCodes: [0, 123],
|
|
1087
1075
|
});
|
|
1088
1076
|
chai_1.assert.deepEqual(exitCode, 0);
|
|
1089
1077
|
let error;
|
|
1090
1078
|
try {
|
|
1091
|
-
|
|
1079
|
+
await utils_1.utils.exec(`node`, [dummyJs, `customExitCode`, `1`], {
|
|
1092
1080
|
successExitCodes: [0, 123],
|
|
1093
1081
|
});
|
|
1094
1082
|
}
|
|
@@ -1101,8 +1089,8 @@ describe("App's utilities functions", function () {
|
|
|
1101
1089
|
chai_1.assert.isTrue(error instanceof utils_1.ExecError);
|
|
1102
1090
|
chai_1.assert.isNumber(error.exitCode);
|
|
1103
1091
|
chai_1.assert.deepEqual(error.exitCode, 1);
|
|
1104
|
-
})
|
|
1105
|
-
it('output handler', () =>
|
|
1092
|
+
});
|
|
1093
|
+
it('output handler', async () => {
|
|
1106
1094
|
let currentOut = '';
|
|
1107
1095
|
let currentErr = '';
|
|
1108
1096
|
let execOut = '';
|
|
@@ -1118,7 +1106,7 @@ describe("App's utilities functions", function () {
|
|
|
1118
1106
|
currentErr += chunk.toString();
|
|
1119
1107
|
return true;
|
|
1120
1108
|
};
|
|
1121
|
-
|
|
1109
|
+
await utils_1.utils.exec(`node`, [dummyJs], {
|
|
1122
1110
|
outputHandler: (stdoutOutput, stderrOutput) => {
|
|
1123
1111
|
execOut += stdoutOutput ? stdoutOutput : '';
|
|
1124
1112
|
execErr += stderrOutput ? stderrOutput : '';
|
|
@@ -1137,8 +1125,8 @@ describe("App's utilities functions", function () {
|
|
|
1137
1125
|
process.stdout.write = stdOutOriginal;
|
|
1138
1126
|
process.stderr.write = stdErrOriginal;
|
|
1139
1127
|
}
|
|
1140
|
-
})
|
|
1141
|
-
it('output handler + disableConsoleOutputs', () =>
|
|
1128
|
+
});
|
|
1129
|
+
it('output handler + disableConsoleOutputs', async () => {
|
|
1142
1130
|
let currentOut = '';
|
|
1143
1131
|
let currentErr = '';
|
|
1144
1132
|
let execOut = '';
|
|
@@ -1154,7 +1142,7 @@ describe("App's utilities functions", function () {
|
|
|
1154
1142
|
currentErr += chunk.toString();
|
|
1155
1143
|
return true;
|
|
1156
1144
|
};
|
|
1157
|
-
|
|
1145
|
+
await utils_1.utils.exec(`node`, [dummyJs], {
|
|
1158
1146
|
outputHandler: (stdoutOutput, stderrOutput) => {
|
|
1159
1147
|
execOut += stdoutOutput ? stdoutOutput : '';
|
|
1160
1148
|
execErr += stderrOutput ? stderrOutput : '';
|
|
@@ -1172,11 +1160,11 @@ describe("App's utilities functions", function () {
|
|
|
1172
1160
|
process.stdout.write = stdOutOriginal;
|
|
1173
1161
|
process.stderr.write = stdErrOriginal;
|
|
1174
1162
|
}
|
|
1175
|
-
})
|
|
1176
|
-
it('execPromisified deprecated but still working', () =>
|
|
1163
|
+
});
|
|
1164
|
+
it('execPromisified deprecated but still working', async () => {
|
|
1177
1165
|
let execOut = '';
|
|
1178
1166
|
let execErr = '';
|
|
1179
|
-
const exitCode =
|
|
1167
|
+
const exitCode = await utils_1.utils.execPromisified(`node`, [dummyJs], (stdoutOutput, stderrOutput) => {
|
|
1180
1168
|
execOut += stdoutOutput ? stdoutOutput : '';
|
|
1181
1169
|
execErr += stderrOutput ? stderrOutput : '';
|
|
1182
1170
|
});
|
|
@@ -1185,11 +1173,11 @@ describe("App's utilities functions", function () {
|
|
|
1185
1173
|
chai_1.assert.isFalse(execOut.includes(`in dummy - error`));
|
|
1186
1174
|
chai_1.assert.isFalse(execErr.includes(`in dummy - info`));
|
|
1187
1175
|
chai_1.assert.isTrue(execErr.includes(`in dummy - error`));
|
|
1188
|
-
})
|
|
1189
|
-
it('execPromisified deprecated but still working - error', () =>
|
|
1176
|
+
});
|
|
1177
|
+
it('execPromisified deprecated but still working - error', async () => {
|
|
1190
1178
|
let error;
|
|
1191
1179
|
try {
|
|
1192
|
-
|
|
1180
|
+
await utils_1.utils.execPromisified(`node`, [dummyJs, `error`]);
|
|
1193
1181
|
}
|
|
1194
1182
|
catch (err) {
|
|
1195
1183
|
error = err;
|
|
@@ -1197,7 +1185,7 @@ describe("App's utilities functions", function () {
|
|
|
1197
1185
|
if (!error) {
|
|
1198
1186
|
chai_1.assert.fail();
|
|
1199
1187
|
}
|
|
1200
|
-
})
|
|
1188
|
+
});
|
|
1201
1189
|
});
|
|
1202
1190
|
});
|
|
1203
1191
|
//# sourceMappingURL=utils.test.js.map
|