-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: detect a full page reload, show error and recover
We need to make this even better, by providing which test caused the page reload. Before that, the adapters need to report spec_start. Even after that, the information which test caused the page reload does not have to be correct. Multiple tests can run within a single event loop (and they do, until there is an async test), so the developer has to set `jasmine.UPDATE_INTERVAL = -1` to know what test caused the page reload. Closes #27
- Loading branch information
Showing
2 changed files
with
29 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,9 @@ var Karma = function(socket, context, navigator, location) { | |
this.VERSION = VERSION; | ||
|
||
this.setupContext = function(contextWindow) { | ||
if (hasError) { | ||
return; | ||
} | ||
|
||
var getConsole = function(currentWindow) { | ||
return currentWindow.console || { | ||
|
@@ -72,6 +75,13 @@ var Karma = function(socket, context, navigator, location) { | |
return contextWindow.__karma__.error.apply(contextWindow.__karma__, arguments); | ||
}; | ||
|
||
contextWindow.onbeforeunload = function(e, b) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
dignifiedquire
Member
|
||
if (context.src !== 'about:blank') { | ||
// TODO(vojta): show what test (with explanation about jasmine.UPDATE_INTERVAL) | ||
contextWindow.__karma__.error('Some of your tests did a full page reload!'); | ||
} | ||
}; | ||
|
||
// patch the console | ||
var localConsole = contextWindow.console = getConsole(contextWindow); | ||
var browserConsoleLog = localConsole.log; | ||
|
@@ -170,7 +180,7 @@ var Karma = function(socket, context, navigator, location) { | |
// we are not going to execute at all | ||
this.error = function(msg, url, line) { | ||
hasError = true; | ||
socket.emit('error', msg + '\nat ' + url + ':' + line); | ||
socket.emit('error', url ? msg + '\nat ' + url + (line ? ':' + line : '') : msg); | ||
this.complete(); | ||
return false; | ||
}; | ||
|
@@ -180,8 +190,12 @@ var Karma = function(socket, context, navigator, location) { | |
}; | ||
|
||
this.complete = function(result) { | ||
socket.emit('complete', result || {}); | ||
clearContext(); | ||
// give the browser some time to breath, there could be a page reload, but because a bunch of | ||
// tests could run in the same event loop, we wouldn't notice. | ||
setTimeout(function() { | ||
socket.emit('complete', result || {}); | ||
clearContext(); | ||
}, 0); | ||
}; | ||
|
||
this.info = function(info) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Is there a way to disable this? I want to test the onbeforeunload method. However, whenever I call
window.onbeforeunload()
I received the error message.