Browse Source

The next fix on Travis unit test failure (#3431)

This is the next escalation on the war against the Travis unit tests failing (which came into being by yours truly).
By accident, I could recreate the unit test failure on my development machine. This led to a more directed effort to
squash the bug.

The insight here is that test `(window === undefined)` fails, but `(typeof window === 'undefined`)` succeeds. This undoubtedly has to do with the special status `window` has as a global object.

Changes:

- Added check on presence of `window` in `Canvas._requestNextFrame()`, fixed local source errors.
- Added catch clause in `CanvasRendered._determinePixelRatio()`
- small fix: raised timeout for the network `worldCup2014` unit test
revert-3409-performance
wimrijnders 6 years ago
committed by Yotam Berkowitz
parent
commit
9957798822
3 changed files with 23 additions and 10 deletions
  1. +9
    -1
      lib/network/modules/Canvas.js
  2. +10
    -7
      lib/network/modules/CanvasRenderer.js
  3. +4
    -2
      test/Network.test.js

+ 9
- 1
lib/network/modules/Canvas.js View File

@ -373,11 +373,19 @@ class Canvas {
throw new Error("Could not get canvax context");
}
return (window.devicePixelRatio || 1) / (ctx.webkitBackingStorePixelRatio ||
var numerator = 1;
if(typeof window !== 'undefined') { // (window !== undefined) doesn't work here!
// Protection during unit tests, where 'window' can be missing
numerator = (window.devicePixelRatio || 1);
}
var denominator = (ctx.webkitBackingStorePixelRatio ||
ctx.mozBackingStorePixelRatio ||
ctx.msBackingStorePixelRatio ||
ctx.oBackingStorePixelRatio ||
ctx.backingStorePixelRatio || 1);
return numerator / denominator;
}
/**

+ 10
- 7
lib/network/modules/CanvasRenderer.js View File

@ -149,13 +149,15 @@ class CanvasRenderer {
// This is not something that will happen in normal operation, but we still need
// to take it into account.
//
let timer;
let timer;
try {
var myWindow = window; // Grab a reference to reduce the possibility that 'window' is reset
// while running this method.
if (myWindow === undefined) return;
if(typeof window === 'undefined') { // (window === undefined) doesn't work here!
return;
}
var myWindow = window; // Grab a reference to reduce the possibility that 'window' is reset
// while running this method.
if (this.requiresTimeout === true) {
// wait given number of milliseconds and perform the animation step function
@ -166,9 +168,10 @@ class CanvasRenderer {
}
}
} catch(e) {
console.warning("Got exception with message: '" + e.message() + "'");
if (e.message() === 'window is undefined') {
console.warning("'" + e.message() + "' happened again");
var msg = e.message;
//console.warn("Got exception with message: '" + msg + "'");
if (msg === 'window is not defined') {
console.warn("CanvasRenderer._requestNextFrame: error '" + msg + "' happened again");
} else {
throw e;
}

+ 4
- 2
test/Network.test.js View File

@ -250,6 +250,7 @@ describe('Network', function () {
describe('Node', function () {
/**
* NOTE: choosify tests of Node and Edge are parallel
* TODO: consolidate this is necessary
@ -1150,15 +1151,16 @@ describe('runs example ', function () {
});
it('WorlCup2014', function () {
it('WorlCup2014', function (done) {
// This is a huge example (which is why it's tested here!), so it takes a long time to load.
this.timeout(10000);
this.timeout(15000);
var network = loadExample('./examples/network/datasources/WorldCup2014.js', true);
// Count in following also contains the helper nodes for dynamic edges
assert.equal(Object.keys(network.body.nodes).length, 9964);
assert.equal(Object.keys(network.body.edges).length, 9228);
done();
});

Loading…
Cancel
Save