From ffcc06abdfeda1601418a001c1e8b1ef12ca7377 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 15 Sep 2021 15:40:57 +0200 Subject: [PATCH] handle missing error field --- src/fake-timers-src.js | 10 +++++++--- test/fake-timers-test.js | 13 +------------ 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/fake-timers-src.js b/src/fake-timers-src.js index aaf0642b..746b4dae 100644 --- a/src/fake-timers-src.js +++ b/src/fake-timers-src.js @@ -207,7 +207,7 @@ function withGlobal(_global) { } /** - * @param clock + * @param {Clock} clock * @param i */ function checkIsNearInfiniteLimit(clock, i) { @@ -217,7 +217,7 @@ function withGlobal(_global) { } /** - * @param clock + * @param {Clock} clock */ function resetIsNearInfiniteLimit(clock) { clock.isNearInfiniteLimit = false; @@ -308,7 +308,7 @@ function withGlobal(_global) { } /** - * @param clock + * @param {Clock} clock * @param job */ function getInfiniteLoopError(clock, job) { @@ -316,6 +316,10 @@ function withGlobal(_global) { `Aborting after running ${clock.loopLimit} timers, assuming an infinite loop!` ); + if (!job.error) { + return infiniteLoopError + } + // pattern never matched in Node const computedTargetPattern = /target\.*[<|(|[].*?[>|\]|)]\s*/; let clockMethodPattern = new RegExp( diff --git a/test/fake-timers-test.js b/test/fake-timers-test.js index 200d3d19..efe33956 100644 --- a/test/fake-timers-test.js +++ b/test/fake-timers-test.js @@ -4944,6 +4944,7 @@ describe("loop limit stack trace", function () { }); }); + // This doesn't really work since we're unable to add an error to all running intervals describe("setInterval", function () { beforeEach(function () { function recursiveCreateTimer() { @@ -4964,12 +4965,6 @@ describe("loop limit stack trace", function () { assert(catchSpy.calledOnce); const err = catchSpy.firstCall.args[0]; assert.equals(err.message, expectedMessage); - assert.equals( - new RegExp( - `Error: ${expectedMessage}\\s+Interval - recursiveCreateTimerTimeout\\s+(at )*recursiveCreateTimer` - ).test(err.stack), - true - ); }); }); @@ -4981,12 +4976,6 @@ describe("loop limit stack trace", function () { } catch (err) { caughtError = true; assert.equals(err.message, expectedMessage); - assert.equals( - new RegExp( - `Error: ${expectedMessage}\\s+Interval - recursiveCreateTimerTimeout\\s+(at )*recursiveCreateTimer` - ).test(err.stack), - true - ); } assert.equals(caughtError, true); });