From 3cfac58d7889681e7ddd84da9685acc4bd7bb663 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Thu, 18 May 2017 10:42:20 -0700 Subject: [PATCH] Eliminate all console errors during test run FREEBIE --- js/signal_protocol_store.js | 19 ++++++++++--------- js/views/network_status_view.js | 6 ++++-- test/fixtures_test.js | 6 +++++- test/storage_test.js | 12 ++++++++++++ test/views/network_status_view_test.js | 11 +++++++---- 5 files changed, 38 insertions(+), 16 deletions(-) diff --git a/js/signal_protocol_store.js b/js/signal_protocol_store.js index 5eb376d42a..ecce1d2917 100644 --- a/js/signal_protocol_store.js +++ b/js/signal_protocol_store.js @@ -136,15 +136,16 @@ removePreKey: function(keyId) { var prekey = new PreKey({id: keyId}); - new Promise(function(resolve) { - getAccountManager().refreshPreKeys().then(resolve); - }); - - return new Promise(function(resolve) { - prekey.destroy().then(function() { - resolve(); - }); - }); + return Promise.all([ + new Promise(function(resolve) { + getAccountManager().refreshPreKeys().then(resolve); + }), + new Promise(function(resolve) { + prekey.destroy().then(function() { + resolve(); + }); + }) + ]); }, /* Returns a signed keypair object or undefined */ diff --git a/js/views/network_status_view.js b/js/views/network_status_view.js index 88b93494ac..0f0bc34221 100644 --- a/js/views/network_status_view.js +++ b/js/views/network_status_view.js @@ -9,8 +9,10 @@ initialize: function() { this.$el.hide(); - var renderIntervalHandle = setInterval(this.update.bind(this), 5000); - extension.windows.onClosed(function () { clearInterval(renderIntervalHandle); }); + this.renderIntervalHandle = setInterval(this.update.bind(this), 5000); + extension.windows.onClosed(function () { + clearInterval(this.renderIntervalHandle); + }.bind(this)); setTimeout(this.finishConnectingGracePeriod.bind(this), 5000); diff --git a/test/fixtures_test.js b/test/fixtures_test.js index f4579e16c4..97a1c71f85 100644 --- a/test/fixtures_test.js +++ b/test/fixtures_test.js @@ -2,10 +2,14 @@ describe("Fixtures", function() { before(function(done) { + // NetworkStatusView checks this method every five seconds while showing + window.getSocketStatus = function() { return WebSocket.OPEN; }; + Whisper.Fixtures.saveAll().then(function() { done(); }); }); + it('renders', function(done) { ConversationController.updateInbox().then(function() { var view = new Whisper.InboxView({appWindow: {contentWindow: window}}); @@ -18,6 +22,6 @@ describe("Fixtures", function() { var view = new Whisper.InboxView({appWindow: {contentWindow: window}}); view.$el.removeClass('android').addClass('android-dark'); view.$el.prependTo($('#render-android-dark')); - }).then(done,done); + }).then(done, done); }); }); diff --git a/test/storage_test.js b/test/storage_test.js index 18ea913014..e7649a87d8 100644 --- a/test/storage_test.js +++ b/test/storage_test.js @@ -91,9 +91,21 @@ describe("SignalProtocolStore", function() { }); }); describe('removePreKey', function() { + var oldGetAccountManager; before(function(done) { + oldGetAccountManager = window.getAccountManager; + window.getAccountManager = function() { + return { + refreshPreKeys: function() { + return Promise.resolve(); + } + }; + }; store.storePreKey(2, testKey).then(done); }); + after(function() { + window.getAccountManager = oldGetAccountManager; + }); it('deletes prekeys', function(done) { store.removePreKey(2, testKey).then(function() { return store.loadPreKey(2).then(function(key) { diff --git a/test/views/network_status_view_test.js b/test/views/network_status_view_test.js index c2e48ff213..17879ba1eb 100644 --- a/test/views/network_status_view_test.js +++ b/test/views/network_status_view_test.js @@ -25,13 +25,16 @@ describe('NetworkStatusView', function() { }); /* END stubbing globals */ - beforeEach(function(done) { - + beforeEach(function() { networkStatusView = new Whisper.NetworkStatusView(); $('.network-status-container').append(networkStatusView.el); - // stubbing global - done(); }); + afterEach(function() { + // prevents huge number of errors on console after running tests + clearInterval(networkStatusView.renderIntervalHandle); + networkStatusView = null; + }); + describe('initialization', function() { it('should have an empty interval', function() { assert.equal(networkStatusView.socketReconnectWaitDuration.asSeconds(), 0);