tests: Give `helper.waitFor()` timeout errors a useful stack trace
parent
71c1899164
commit
8dca4cb16f
|
@ -198,6 +198,10 @@ const helper = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
helper.waitFor = (conditionFunc, timeoutTime = 1900, intervalTime = 10) => {
|
helper.waitFor = (conditionFunc, timeoutTime = 1900, intervalTime = 10) => {
|
||||||
|
// Create an Error object to use if the condition is never satisfied. This is created here so
|
||||||
|
// that the Error has a useful stack trace associated with it.
|
||||||
|
const timeoutError =
|
||||||
|
new Error(`waitFor condition never became true ${conditionFunc.toString()}`);
|
||||||
const deferred = new $.Deferred();
|
const deferred = new $.Deferred();
|
||||||
|
|
||||||
const _fail = deferred.fail.bind(deferred);
|
const _fail = deferred.fail.bind(deferred);
|
||||||
|
@ -222,11 +226,10 @@ const helper = {};
|
||||||
|
|
||||||
const timeout = setTimeout(() => {
|
const timeout = setTimeout(() => {
|
||||||
clearInterval(intervalCheck);
|
clearInterval(intervalCheck);
|
||||||
const error = new Error(`wait for condition never became true ${conditionFunc.toString()}`);
|
deferred.reject(timeoutError);
|
||||||
deferred.reject(error);
|
|
||||||
|
|
||||||
if (!listenForFail) {
|
if (!listenForFail) {
|
||||||
throw error;
|
throw timeoutError;
|
||||||
}
|
}
|
||||||
}, timeoutTime);
|
}, timeoutTime);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue