From f6611f1efcd25f3530a466ee59bf57fcdba20c16 Mon Sep 17 00:00:00 2001 From: johnjbarton Date: Thu, 1 Oct 2020 16:47:40 -0700 Subject: [PATCH 1/2] fix(context): do not error when karma is navigating Change the flag name to karmaNavigating and set it along all paths where karma deliberately navigates. Other paths must be wrong. Fixes #3560 --- client/karma.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/client/karma.js b/client/karma.js index 2bd4f2cf3..823da44e8 100644 --- a/client/karma.js +++ b/client/karma.js @@ -4,7 +4,7 @@ var util = require('../common/util') function Karma (socket, iframe, opener, navigator, location, document) { var startEmitted = false - var reloadingContext = false + var karmaNavigating = false var self = this var queryParams = util.parseQueryParams(location.search) var browserId = queryParams.id || util.generateId('manual-') @@ -80,6 +80,8 @@ function Karma (socket, iframe, opener, navigator, location, document) { var childWindow = null function navigateContextTo (url) { + karmaNavigating = true + console.log('karmaNavigating', karmaNavigating) if (self.config.useIframe === false) { // run in new window if (self.config.runInParent === false) { @@ -89,9 +91,12 @@ function Karma (socket, iframe, opener, navigator, location, document) { childWindow.close() } childWindow = opener(url) + karmaNavigating = false + console.log('karmaNavigating', karmaNavigating) // run context on parent element (client_with_context) // using window.__karma__.scriptUrls to get the html element strings and load them dynamically } else if (url !== 'about:blank') { + karmaNavigating = false var loadScript = function (idx) { if (idx < window.__karma__.scriptUrls.length) { var parser = new DOMParser() @@ -123,20 +128,20 @@ function Karma (socket, iframe, opener, navigator, location, document) { // run in iframe } else { iframe.src = policy.createURL(url) + karmaNavigating = false + console.log('karmaNavigating', karmaNavigating) } } this.onbeforeunload = function () { - if (!reloadingContext) { + if (!karmaNavigating) { // TODO(vojta): show what test (with explanation about jasmine.UPDATE_INTERVAL) self.error('Some of your tests did a full page reload!') } - reloadingContext = false + karmaNavigating = false } function clearContext () { - reloadingContext = true - navigateContextTo('about:blank') } @@ -259,9 +264,11 @@ function Karma (socket, iframe, opener, navigator, location, document) { } socket.on('execute', function (cfg) { + console.log('-----------------------execute') // Delay our navigation to the next event in case the clearContext has not completed. setTimeout(function allowClearContextToComplete () { // reset startEmitted and reload the iframe + console.log('allowClearContextToComplete') startEmitted = false self.config = cfg From 56172b62927c83470256dd19ef89611b01a29c04 Mon Sep 17 00:00:00 2001 From: johnjbarton Date: Mon, 5 Oct 2020 12:13:08 -0700 Subject: [PATCH 2/2] fix(debug): debug appveyor error --- client/karma.js | 2 ++ static/karma.js | 19 ++++++++++++++----- test/client/karma.spec.js | 3 ++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/client/karma.js b/client/karma.js index 823da44e8..017e5f2f6 100644 --- a/client/karma.js +++ b/client/karma.js @@ -134,6 +134,7 @@ function Karma (socket, iframe, opener, navigator, location, document) { } this.onbeforeunload = function () { + console.log('onbeforeunload with karmaNavigating ', karmaNavigating) if (!karmaNavigating) { // TODO(vojta): show what test (with explanation about jasmine.UPDATE_INTERVAL) self.error('Some of your tests did a full page reload!') @@ -142,6 +143,7 @@ function Karma (socket, iframe, opener, navigator, location, document) { } function clearContext () { + console.log('send to about blank to clear context') navigateContextTo('about:blank') } diff --git a/static/karma.js b/static/karma.js index bb3630d98..31197617a 100644 --- a/static/karma.js +++ b/static/karma.js @@ -14,7 +14,7 @@ var util = require('../common/util') function Karma (socket, iframe, opener, navigator, location, document) { var startEmitted = false - var reloadingContext = false + var karmaNavigating = false var self = this var queryParams = util.parseQueryParams(location.search) var browserId = queryParams.id || util.generateId('manual-') @@ -90,6 +90,8 @@ function Karma (socket, iframe, opener, navigator, location, document) { var childWindow = null function navigateContextTo (url) { + karmaNavigating = true + console.log('karmaNavigating', karmaNavigating) if (self.config.useIframe === false) { // run in new window if (self.config.runInParent === false) { @@ -99,9 +101,12 @@ function Karma (socket, iframe, opener, navigator, location, document) { childWindow.close() } childWindow = opener(url) + karmaNavigating = false + console.log('karmaNavigating', karmaNavigating) // run context on parent element (client_with_context) // using window.__karma__.scriptUrls to get the html element strings and load them dynamically } else if (url !== 'about:blank') { + karmaNavigating = false var loadScript = function (idx) { if (idx < window.__karma__.scriptUrls.length) { var parser = new DOMParser() @@ -133,20 +138,22 @@ function Karma (socket, iframe, opener, navigator, location, document) { // run in iframe } else { iframe.src = policy.createURL(url) + karmaNavigating = false + console.log('karmaNavigating', karmaNavigating) } } this.onbeforeunload = function () { - if (!reloadingContext) { + console.log('onbeforeunload with karmaNavigating ', karmaNavigating) + if (!karmaNavigating) { // TODO(vojta): show what test (with explanation about jasmine.UPDATE_INTERVAL) self.error('Some of your tests did a full page reload!') } - reloadingContext = false + karmaNavigating = false } function clearContext () { - reloadingContext = true - + console.log('send to about blank to clear context') navigateContextTo('about:blank') } @@ -269,9 +276,11 @@ function Karma (socket, iframe, opener, navigator, location, document) { } socket.on('execute', function (cfg) { + console.log('-----------------------execute') // Delay our navigation to the next event in case the clearContext has not completed. setTimeout(function allowClearContextToComplete () { // reset startEmitted and reload the iframe + console.log('allowClearContextToComplete') startEmitted = false self.config = cfg diff --git a/test/client/karma.spec.js b/test/client/karma.spec.js index bc3ad81f2..4c9eee453 100644 --- a/test/client/karma.spec.js +++ b/test/client/karma.spec.js @@ -144,7 +144,7 @@ describe('Karma', function () { }) }) - it('should error out if a script attempted to reload the browser after setup', function (done) { + it.only('should error out if a script attempted to reload the browser after setup', function (done) { // Perform setup var config = ck.config = { clearContext: true @@ -158,6 +158,7 @@ describe('Karma', function () { // Spy on our error handler sinon.spy(k, 'error') + console.log('emulate unload') // Emulate an unload event mockWindow.onbeforeunload()