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

Travis unit tests failing with 'window is not defined' #33

Open
wimrijnders opened this issue Sep 5, 2017 · 0 comments
Open

Travis unit tests failing with 'window is not defined' #33

wimrijnders opened this issue Sep 5, 2017 · 0 comments

Comments

@wimrijnders
Copy link

Hi there,

In our unit tests we use the following construct to initialize jsdom-global:

before(function() {
    this.jsdom_global = jsdom_global(
      "<div id='mynetwork'></div>",
      { skipWindowCheck: true}
    );
    this.container = document.getElementById('mynetwork');
  });

  after(function() {
    this.jsdom_global();
  });

The unit tests work perfectly when run locally, but it happens regularly that they fail on Travis:

1) Network "after all" hook:
     Uncaught ReferenceError: window is not defined
      at CanvasRenderer._requestNextFrame (dist/vis.js:50457:22)
      at CanvasRenderer._requestRedraw (dist/vis.js:50540:14)
      at Network.Emitter.emit (dist/vis.js:6493:20)
      at View.animateView (dist/vis.js:51596:29)
      at View.moveTo (dist/vis.js:51536:12)
      at View.fit (dist/vis.js:51462:12)
      at Network.Emitter.emit (dist/vis.js:6493:20)
      at PhysicsEngine._finalizeStabilization (dist/vis.js:47781:27)
      at PhysicsEngine._stabilizationBatch (dist/vis.js:47767:14)

After this happens, other unrelated unit tests tend to fail as well as a consequence.
I don't fully understand the mechanics of execution on Travis, but by the looks of it, the global window is cleared while (apparently) overlapping unit tests are running.

Is there any way to avoid this error?

As a stopgap measure, I'm considering just catching the ReferenceError for this particular case; I see in the code that window is the very last item in the list of keys, so everything else would have been cleaned up on the call to jsdom_global() in the after-hook. Would this be acceptable? If you know of any other solutions, I would love to know.


This is my current working hypothesis on this error:

In our code, window.requestAnimationFrame is used to trigger the drawing of a next frame on a Canvas element. The final frame redraw can be delayed, and it's possible that this overlaps with the subsequent unit test (on Travis). Because of this, the global window could be reset while another test is running, causing the given error.

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