@camperaid/watest 2.4.3 → 2.4.4
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/core/series.js +28 -10
- package/package.json +1 -1
package/core/series.js
CHANGED
|
@@ -30,6 +30,9 @@ const {
|
|
|
30
30
|
const root_folder = 'tests';
|
|
31
31
|
const root_dir = path.resolve('.');
|
|
32
32
|
|
|
33
|
+
const kKungFuDeathGripTimeout = {};
|
|
34
|
+
const kKungFuDeathGripCancelled = {};
|
|
35
|
+
|
|
33
36
|
process.on('unhandledRejection', error => {
|
|
34
37
|
log_error(error);
|
|
35
38
|
fail(`Unhandled Promise rejection`);
|
|
@@ -635,26 +638,41 @@ class Series {
|
|
|
635
638
|
// Invoke a test.
|
|
636
639
|
log(`\n!Running: ${name}, path: ${path}\n`);
|
|
637
640
|
let start_time = new Date();
|
|
641
|
+
let kungFuDeathGrip = null;
|
|
642
|
+
let kungFuDeathGripResolve = null;
|
|
643
|
+
let kungFuDeathGripTimer = 0;
|
|
638
644
|
try {
|
|
639
645
|
this.core.setExpectedFailures(failures_info);
|
|
640
646
|
|
|
641
647
|
// If timeout is given then race it against the test.
|
|
642
648
|
if (settings.timeout) {
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
649
|
+
kungFuDeathGrip = new Promise(
|
|
650
|
+
resolve => (kungFuDeathGripResolve = resolve)
|
|
651
|
+
).then(value => {
|
|
652
|
+
if (value != kKungFuDeathGripCancelled) {
|
|
653
|
+
fail(
|
|
654
|
+
`Test ${name} takes longer than ${settings.timeout}ms. It's either slow or never ends.`
|
|
655
|
+
);
|
|
656
|
+
return kKungFuDeathGripTimeout;
|
|
657
|
+
}
|
|
658
|
+
});
|
|
659
|
+
kungFuDeathGripTimer = setTimeout(
|
|
660
|
+
kungFuDeathGripResolve,
|
|
661
|
+
settings.timeout
|
|
650
662
|
);
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
663
|
+
let retval = await Promise.race([func(), kungFuDeathGrip]);
|
|
664
|
+
if (retval != kKungFuDeathGripTimeout) {
|
|
665
|
+
clearTimeout(kungFuDeathGripTimer);
|
|
666
|
+
kungFuDeathGripResolve(kKungFuDeathGripCancelled);
|
|
667
|
+
}
|
|
654
668
|
} else {
|
|
655
669
|
await func(); // execute the test
|
|
656
670
|
}
|
|
657
671
|
} catch (e) {
|
|
672
|
+
if (kungFuDeathGripTimer) {
|
|
673
|
+
clearTimeout(kungFuDeathGripTimer);
|
|
674
|
+
kungFuDeathGripResolve(kKungFuDeathGripCancelled);
|
|
675
|
+
}
|
|
658
676
|
let failmsg = e;
|
|
659
677
|
if (e instanceof Error) {
|
|
660
678
|
log_error(e);
|