Skip to content

Commit

Permalink
Make unit tests less flaky on Travis CI (#1329)
Browse files Browse the repository at this point in the history
* Fix "Cannot read property 'setUp' of undefined"

* Deflake Animation keyframeEasing test
  • Loading branch information
islemaster authored and rwaldron committed Apr 21, 2017
1 parent 005b955 commit 6d8b4a3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
8 changes: 6 additions & 2 deletions test/animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,10 @@ exports["Animation -- Servo"] = {
},

keyframeEasing: function(test) {

// Don't allow time to advance in this test. Otherwise it's possible for
// the animation to progress between setup and the assertion, causing flaky
// failures.
this.sandbox.useFakeTimers();
this.animation = new Animation(this.a);
test.expect(1);

Expand All @@ -260,7 +263,8 @@ exports["Animation -- Servo"] = {
var indices = this.animation.findIndices(progress);
var val = this.animation.tweenedValue(indices, progress);

test.ok(Math.abs(val - 74.843 < 0.01));
test.ok(Math.abs(val - 74.843) < 0.01,
"Expected " + val + " to be within 0.01 of 74.843");
test.done();
},

Expand Down
9 changes: 8 additions & 1 deletion test/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,16 @@ exports["Repl"] = {
debug: false
});

// Extra-careful guard against calling test.done() twice here.
// This was causing "Cannot read property 'setUp' of undefined" errors
// See https://github.com/caolan/nodeunit/issues/234
var calledTestDone = false;
var reallyExit = this.sandbox.stub(process, "reallyExit", function() {
reallyExit.restore();
test.done();
if (!calledTestDone) {
calledTestDone = true;
test.done();
}
});

board.on("ready", function() {
Expand Down

0 comments on commit 6d8b4a3

Please sign in to comment.