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

Ready event seems to be unreliable #1563

Open
lpeabody opened this issue Apr 6, 2024 · 1 comment
Open

Ready event seems to be unreliable #1563

lpeabody opened this issue Apr 6, 2024 · 1 comment

Comments

@lpeabody
Copy link
Contributor

lpeabody commented Apr 6, 2024

What are some scenarios where the ready event always fires but some scenarios still log the following:

ReadyEvent not detected within readyTimeout limit. (30000 ms) ...

It's inconsistent, so it seems like maybe the ready event fires too quickly, perhaps?

@lpeabody
Copy link
Contributor Author

lpeabody commented Apr 6, 2024

I'm unsure just by reading the source, but, it appears that BackstopTools need to be installed before the ready event is logged to the console?

I'm finding this to be helpful:

// Let's promise to resolve that BackstopTools is installed before outputting the ready event to the console.
let backstopToolsInstalledResolve;
const backstopToolsInstalledPromise = new Promise(resolve => {
  backstopToolsInstalledResolve = resolve;
});
const backstopReadyWhenAllResolved = [
  backstopToolsInstalledPromise
];

...

// Give it up to 10 seconds to become ready.
let readyEventIntervalCounter = 0;
const readyEventInterval = setInterval(() => {
  if (window._readyEvent) {
    backstopToolsInstalledResolve();
    clearInterval(readyEventInterval);
  }
  if (readyEventIntervalCounter++ > 10) {
    clearInterval(readyEventInterval);
  }
}, 1000);

// When all required promises to be ready have been fulfilled, log the event.
// Also wait a few seconds for good measure.
Promise.all(backstopReadyWhenAllResolved)
  .then(() => {
    setTimeout(() => {
      console.log(window._readyEvent);
    }, 3000);
  });

I think it would be helpful to suggest this as a recipe in the documentation, otherwise using the ready event feature may seem like it's not working as intended and its not obvious at all as to why.

EDIT: If you think it would be useful I can setup a PR with the added documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant