Skip to content

Commit

Permalink
fix(client): redirect to redirect_url after all messages are sent
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtajina committed Dec 3, 2013
1 parent d06b717 commit 4d05602
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
17 changes: 11 additions & 6 deletions client/karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var Karma = function(socket, context, navigator, location) {
var queryParams = util.parseQueryParams(location.search);
var browserId = queryParams.id || util.generateId('manual-');
var returnUrl = queryParams.return_url || null;
var currentTransport;

var resultsBufferLimit = 1;
var resultsBuffer = [];
Expand Down Expand Up @@ -129,11 +130,15 @@ var Karma = function(socket, context, navigator, location) {
// tests could run in the same event loop, we wouldn't notice.
setTimeout(function() {
socket.emit('complete', result || {});
clearContext();

// Redirect to the return_url, however we need to give the browser some time,
// so that all the messages are sent.
// TODO(vojta): can we rather get notification from socket.io?
if (returnUrl) {
socket.disconnect();
location.href = returnUrl;
} else {
clearContext();
setTimeout(function() {
location.href = returnUrl;
}, (currentTransport === 'websocket' || currentTransport === 'flashsocket') ? 0 : 3000);
}
}, 0);
};
Expand Down Expand Up @@ -197,10 +202,10 @@ var Karma = function(socket, context, navigator, location) {

// report browser name, id
socket.on('connect', function() {
var transport = socket.socket.transport.name;
currentTransport = socket.socket.transport.name;

// TODO(vojta): make resultsBufferLimit configurable
if (transport === 'websocket' || transport === 'flashsocket') {
if (currentTransport === 'websocket' || currentTransport === 'flashsocket') {
resultsBufferLimit = 1;
} else {
resultsBufferLimit = 50;
Expand Down
3 changes: 1 addition & 2 deletions test/client/karma.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,14 @@ describe('Karma', function() {
});


it('should disconnect navigate the client to return_url if specified', function() {
it('should navigate the client to return_url if specified', function() {
windowLocation.search = '?id=567&return_url=http:https://return.com';
socket = new MockSocket();
k = new Karma(socket, {}, windowNavigator, windowLocation);

spyOn(socket, 'disconnect');

k.complete();
expect(socket.disconnect).toHaveBeenCalled();
expect(windowLocation.href).toBe('http:https://return.com');
});
});
Expand Down

0 comments on commit 4d05602

Please sign in to comment.