diff --git a/package.json b/package.json index a70c3f1..e778f23 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@barchart/common-js", - "version": "4.29.0", + "version": "4.29.1", "description": "Library of common JavaScript utilities", "author": { "name": "Bryan Ingle", diff --git a/test/SpecRunner.js b/test/SpecRunner.js index a20d93d..353f154 100644 --- a/test/SpecRunner.js +++ b/test/SpecRunner.js @@ -5606,11 +5606,26 @@ module.exports = (() => { if (!(milliseconds > 0)) { return Promise.reject('Unable to configure promise timeout, the "milliseconds" argument must be positive'); } - return Promise.race([promise, this.build((resolveCallback, rejectCallback) => { - setTimeout(() => { + let timeoutToken = null; + const timeoutPromise = this.build((resolveCallback, rejectCallback) => { + timeoutToken = setTimeout(() => { rejectCallback(description || `Promise timed out after ${milliseconds} milliseconds`); }, milliseconds); - })]); + }); + const userPromise = Promise.resolve().then(() => { + return promise; + }).then(result => { + if (timeoutToken !== null) { + clearTimeout(timeoutToken); + } + return result; + }).catch(e => { + if (timeoutToken !== null) { + clearTimeout(timeoutToken); + } + return Promise.reject(e); + }); + return Promise.race([userPromise, timeoutPromise]); }); }, /**