From 584c806869faef5000e44952165ec04fe06c6105 Mon Sep 17 00:00:00 2001 From: Tom Newby Date: Thu, 19 Sep 2019 12:02:48 +1000 Subject: [PATCH 1/2] rfc(error): improve timeout error stack trace for waitFor --- src/wait.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/wait.ts b/src/wait.ts index b2ba116..233ab3c 100644 --- a/src/wait.ts +++ b/src/wait.ts @@ -34,11 +34,14 @@ export function waitFor(getter: () => T, options: { return new Promise(rs => setTimeout(rs, options.interval)).then(wait); } + // We generate the error here to capture the stack trace, but we will only throw it if it times out + const timeoutError = new Error(options.present ? 'Element not found' : 'Element not removed'); + return Promise.race([ new Promise( (_, rj) => setTimeout(() => { timedOut = true; - rj(new Error(options.present ? 'Element not found' : 'Element not removed')); + rj(timeoutError); }, options.timeout) ), wait() From ff2fb3df89e6c72751b54487926cbf7d1abf291d Mon Sep 17 00:00:00 2001 From: Tom Newby Date: Fri, 1 May 2020 11:50:21 +1000 Subject: [PATCH 2/2] Build --- dist/amd/wait.js | 4 +++- dist/commonjs/wait.js | 4 +++- dist/es2015/wait.js | 4 +++- dist/es2017/wait.js | 4 +++- dist/native-modules/wait.js | 4 +++- dist/system/wait.js | 4 +++- 6 files changed, 18 insertions(+), 6 deletions(-) diff --git a/dist/amd/wait.js b/dist/amd/wait.js index 1c8f1d2..4c661b9 100644 --- a/dist/amd/wait.js +++ b/dist/amd/wait.js @@ -32,10 +32,12 @@ define(["require", "exports"], function (require, exports) { } return new Promise(function (rs) { return setTimeout(rs, options.interval); }).then(wait); } + // We generate the error here to capture the stack trace, but we will only throw it if it times out + var timeoutError = new Error(options.present ? 'Element not found' : 'Element not removed'); return Promise.race([ new Promise(function (_, rj) { return setTimeout(function () { timedOut = true; - rj(new Error(options.present ? 'Element not found' : 'Element not removed')); + rj(timeoutError); }, options.timeout); }), wait() ]); diff --git a/dist/commonjs/wait.js b/dist/commonjs/wait.js index 68616d8..1b6b957 100644 --- a/dist/commonjs/wait.js +++ b/dist/commonjs/wait.js @@ -31,10 +31,12 @@ function waitFor(getter, options) { } return new Promise(function (rs) { return setTimeout(rs, options.interval); }).then(wait); } + // We generate the error here to capture the stack trace, but we will only throw it if it times out + var timeoutError = new Error(options.present ? 'Element not found' : 'Element not removed'); return Promise.race([ new Promise(function (_, rj) { return setTimeout(function () { timedOut = true; - rj(new Error(options.present ? 'Element not found' : 'Element not removed')); + rj(timeoutError); }, options.timeout); }), wait() ]); diff --git a/dist/es2015/wait.js b/dist/es2015/wait.js index 8f807f1..fdad4e7 100644 --- a/dist/es2015/wait.js +++ b/dist/es2015/wait.js @@ -20,10 +20,12 @@ export function waitFor(getter, options = { present: true, interval: 50, timeout } return new Promise(rs => setTimeout(rs, options.interval)).then(wait); } + // We generate the error here to capture the stack trace, but we will only throw it if it times out + const timeoutError = new Error(options.present ? 'Element not found' : 'Element not removed'); return Promise.race([ new Promise((_, rj) => setTimeout(() => { timedOut = true; - rj(new Error(options.present ? 'Element not found' : 'Element not removed')); + rj(timeoutError); }, options.timeout)), wait() ]); diff --git a/dist/es2017/wait.js b/dist/es2017/wait.js index 8f807f1..fdad4e7 100644 --- a/dist/es2017/wait.js +++ b/dist/es2017/wait.js @@ -20,10 +20,12 @@ export function waitFor(getter, options = { present: true, interval: 50, timeout } return new Promise(rs => setTimeout(rs, options.interval)).then(wait); } + // We generate the error here to capture the stack trace, but we will only throw it if it times out + const timeoutError = new Error(options.present ? 'Element not found' : 'Element not removed'); return Promise.race([ new Promise((_, rj) => setTimeout(() => { timedOut = true; - rj(new Error(options.present ? 'Element not found' : 'Element not removed')); + rj(timeoutError); }, options.timeout)), wait() ]); diff --git a/dist/native-modules/wait.js b/dist/native-modules/wait.js index 5d81447..daa747a 100644 --- a/dist/native-modules/wait.js +++ b/dist/native-modules/wait.js @@ -29,10 +29,12 @@ export function waitFor(getter, options) { } return new Promise(function (rs) { return setTimeout(rs, options.interval); }).then(wait); } + // We generate the error here to capture the stack trace, but we will only throw it if it times out + var timeoutError = new Error(options.present ? 'Element not found' : 'Element not removed'); return Promise.race([ new Promise(function (_, rj) { return setTimeout(function () { timedOut = true; - rj(new Error(options.present ? 'Element not found' : 'Element not removed')); + rj(timeoutError); }, options.timeout); }), wait() ]); diff --git a/dist/system/wait.js b/dist/system/wait.js index 85fa35c..fd5a15b 100644 --- a/dist/system/wait.js +++ b/dist/system/wait.js @@ -32,10 +32,12 @@ System.register([], function (exports_1, context_1) { } return new Promise(function (rs) { return setTimeout(rs, options.interval); }).then(wait); } + // We generate the error here to capture the stack trace, but we will only throw it if it times out + var timeoutError = new Error(options.present ? 'Element not found' : 'Element not removed'); return Promise.race([ new Promise(function (_, rj) { return setTimeout(function () { timedOut = true; - rj(new Error(options.present ? 'Element not found' : 'Element not removed')); + rj(timeoutError); }, options.timeout); }), wait() ]);