Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #228 from remix/config-async-timeout
Browse files Browse the repository at this point in the history
Allow the async timeout duration to be configured per-example
  • Loading branch information
trotzig committed May 7, 2019
2 parents f575256 + a2cd4b1 commit 78716f7
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/happo-target-firefox/src/HappoRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ function handleError(currentExample, error) {
* that is called when it is done.
* @return {Promise}
*/
function tryAsync(func) {
function tryAsync(func, timeoutDuration = 3000) {
return new Promise((resolve, reject) => {
// Safety valve: if the function does not finish after 3s, then something
// went haywire and we need to move on.
// Safety valve: if the function does not finish after the timeoutDuration,
// then something probably went haywire and we need to move on.
const timeout = setTimeout(() => {
reject(new Error('Async callback was not invoked within timeout.'));
}, 3000);
}, timeoutDuration);

// This function is called by the example when it is done executing.
const doneCallback = () => {
Expand Down Expand Up @@ -111,12 +111,12 @@ window.happo = {
document.body.removeChild(document.body.firstChild);
}

const { func } = currentExample;
const { func, options } = currentExample;
if (func.length) {
// The function takes an argument, which is a callback that is called
// once it is done executing. This can be used to write functions that
// have asynchronous code in them.
tryAsync(func).then(() => {
tryAsync(func, options.timeout).then(() => {
this.processExample(currentExample).then(doneFunc).catch(doneFunc);
}).catch((error) => {
doneFunc(handleError(currentExample, error));
Expand Down

0 comments on commit 78716f7

Please sign in to comment.