Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rfc(error): improve timeout error stack trace for waitFor timeouts #92

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion dist/amd/wait.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
]);
Expand Down
4 changes: 3 additions & 1 deletion dist/commonjs/wait.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
]);
Expand Down
4 changes: 3 additions & 1 deletion dist/es2015/wait.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
]);
Expand Down
4 changes: 3 additions & 1 deletion dist/es2017/wait.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
]);
Expand Down
4 changes: 3 additions & 1 deletion dist/native-modules/wait.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
]);
Expand Down
4 changes: 3 additions & 1 deletion dist/system/wait.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
]);
Expand Down
5 changes: 4 additions & 1 deletion src/wait.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ export function waitFor<T>(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()
Expand Down