@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.
Files changed (2) hide show
  1. package/core/series.js +28 -10
  2. 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
- let kungFuDeathGripTimer = 0;
644
- let kungFuDeathGrip = new Promise(r => {
645
- kungFuDeathGripTimer = setTimeout(r, settings.timeout);
646
- }).then(() =>
647
- fail(
648
- `Test ${name} takes longer than ${settings.timeout}ms. It's either slow or never ends.`
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
- await Promise.race([func(), kungFuDeathGrip]);
653
- clearTimeout(kungFuDeathGripTimer);
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camperaid/watest",
3
- "version": "2.4.3",
3
+ "version": "2.4.4",
4
4
  "description": "Web Application Testsuite",
5
5
  "engines": {
6
6
  "node": ">=14.15.1"