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

Fix e2e readiness flag on slow or overloaded computers #2524

Closed
dcylabs opened this issue Jun 22, 2020 · 1 comment
Closed

Fix e2e readiness flag on slow or overloaded computers #2524

dcylabs opened this issue Jun 22, 2020 · 1 comment
Labels

Comments

@dcylabs
Copy link
Contributor

dcylabs commented Jun 22, 2020

Stencil version:

 @stencil/core@1.14.0

I'm submitting a:

[x] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://stencil-worldwide.herokuapp.com/ or https://forum.ionicframework.com/

Current behavior:

When running e2e tests on slow, or overloaded computers, the stencilReady flag may not be triggered and got this error :

  ● my-component › should display icon

    App did not load in allowed time. Please ensure the content loads a stencil application.

Expected behavior:
window.stencilAppLoaded should be initialized even on slow or overloaded computers.

Steps to reproduce:

  • Use a standard computer as a GitLab Runner.
  • Launch 1 test pipeline => Success
  • Launch 3 or 4 tests pipelines simultaneously => The error occurs randomly

Related code:

Code that triggers the stencil readiness :

// puppeteer-events.ts
// ... 
  const stencilReady = () => {
    return allReady()
      .then(() => waitFrame())
      .then(() => allReady())
      .then(() => {
        ((window as unknown) as pd.BrowserWindow).stencilAppLoaded = true;
      });
  };
// ... 
  if (window.document.readyState === 'complete') {
    stencilReady();
  } else {
    window.addEventListener('load', stencilReady);
  }
}

What leads me to this conclusion is that when analysing the readyState flow :

loading > interactive > loaded 

It seems that on overloadded computers, you can fall into a hole that you are not in the complete readyState, but the load event is fired before the else block is executed and the listener attached.

As recommended by mozilla it would be better to use this syntax.

  if (window.document.readyState === 'complete') {
    stencilReady();
  } else {
    document.addEventListener('readystatechange', function (e) {
      if ((e.target as Document).readyState == "complete") {
        stencilReady();
      }
    }, false);
  }

Other information:

I'm preparing a PR to use the mozilla recommendations

@manucorporat
Copy link
Contributor

Fixed by #2525

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

No branches or pull requests

2 participants