Skip to content

Commit

Permalink
fix(context): do not error when karma is navigating
Browse files Browse the repository at this point in the history
Change the flag name to karmaNavigating and set it along all paths where
karma deliberately navigates. Other paths must be wrong.

Fixes #3560
  • Loading branch information
johnjbarton committed Oct 5, 2020
1 parent ead31cd commit dd0f5ac
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions client/karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -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-')
Expand Down Expand Up @@ -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) {
Expand All @@ -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()
Expand Down Expand Up @@ -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')
}

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit dd0f5ac

Please sign in to comment.