diff --git a/client/karma.js b/client/karma.js index 37e9552e6..8bbb4858b 100644 --- a/client/karma.js +++ b/client/karma.js @@ -4,9 +4,10 @@ var util = require('./util'); /* jshint unused: false */ -var Karma = function(socket, context, navigator, location) { +var Karma = function(socket, iframe, opener, navigator, location) { var hasError = false; var startEmitted = false; + var reloadingContext = false; var store = {}; var self = this; var queryParams = util.parseQueryParams(location.search); @@ -20,6 +21,19 @@ var Karma = function(socket, context, navigator, location) { this.VERSION = constant.VERSION; this.config = {}; + var childWindow = null; + var navigateContextTo = function(url) { + if (self.config.useIframe === false) { + if (childWindow === null || childWindow.closed === true) { + // If this is the first time we are opening the window, or the window is closed + childWindow = opener('about:blank'); + } + childWindow.location = url; + } else { + iframe.src = url; + } + }; + this.setupContext = function(contextWindow) { if (hasError) { return; @@ -43,7 +57,7 @@ var Karma = function(socket, context, navigator, location) { }; contextWindow.onbeforeunload = function(e, b) { - if (context.src !== 'about:blank') { + if (!reloadingContext) { // TODO(vojta): show what test (with explanation about jasmine.UPDATE_INTERVAL) contextWindow.__karma__.error('Some of your tests did a full page reload!'); } @@ -90,7 +104,8 @@ var Karma = function(socket, context, navigator, location) { var clearContext = function() { - context.src = 'about:blank'; + reloadingContext = true; + navigateContextTo('about:blank'); }; // error during js file loading (most likely syntax error) @@ -190,8 +205,9 @@ var Karma = function(socket, context, navigator, location) { // reset hasError and reload the iframe hasError = false; startEmitted = false; + reloadingContext = false; self.config = cfg; - context.src = constant.CONTEXT_URL; + navigateContextTo(constant.CONTEXT_URL); // clear the console before run // works only on FF (Safari, Chrome do not allow to clear console from js source) diff --git a/client/main.js b/client/main.js index 4ac55548c..031ef7f67 100644 --- a/client/main.js +++ b/client/main.js @@ -17,5 +17,5 @@ var socket = io.connect('http://' + location.host, { // instantiate the updater of the view new StatusUpdater(socket, util.elm('title'), util.elm('banner'), util.elm('browsers')); - -window.karma = new Karma(socket, util.elm('context'), window.navigator, window.location); +window.karma = new Karma(socket, util.elm('context'), window.open, + window.navigator, window.location); \ No newline at end of file diff --git a/docs/config/01-configuration-file.md b/docs/config/01-configuration-file.md index 72de01beb..a95d7d716 100644 --- a/docs/config/01-configuration-file.md +++ b/docs/config/01-configuration-file.md @@ -343,6 +343,15 @@ on whether all tests passed or any tests failed. is handed off to [socket.io](https://github.com/LearnBoost/Socket.IO/wiki/Configuring-Socket.IO) (which manages the communication between browsers and the testing server). +## client.useIframe +**Type:** Boolean + +**Default:** `true` + +**Description:** Run the tests inside an iframe or a new window + +If true, Karma runs the tests inside an iframe. If false, Karma runs the tests in a new window. Some tests may not run in an iFrame and may need a new window to run. + ## urlRoot **Type:** String diff --git a/lib/config.js b/lib/config.js index 2e6feefcb..8a4509b6f 100644 --- a/lib/config.js +++ b/lib/config.js @@ -210,7 +210,8 @@ var Config = function() { this.transports = ['websocket', 'flashsocket', 'xhr-polling', 'jsonp-polling']; this.plugins = ['karma-*']; this.client = { - args: [] + args: [], + useIframe: true }; this.browserDisconnectTimeout = 2000; this.browserDisconnectTolerance = 0; diff --git a/static/context.html b/static/context.html index a1d6cb9e6..807448646 100644 --- a/static/context.html +++ b/static/context.html @@ -16,7 +16,12 @@ manner. -->