Skip to content

Commit f4144b0

Browse files
committed
fix(server): complete acknowledgment
1 parent 6ef74f2 commit f4144b0

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

client/karma.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,18 +146,14 @@ var Karma = function(socket, iframe, opener, navigator, location) {
146146
// give the browser some time to breath, there could be a page reload, but because a bunch of
147147
// tests could run in the same event loop, we wouldn't notice.
148148
setTimeout(function() {
149-
socket.emit('complete', result || {});
150149
clearContext();
150+
}, 0);
151151

152-
// Redirect to the return_url, however we need to give the browser some time,
153-
// so that all the messages are sent.
154-
// TODO(vojta): can we rather get notification from socket.io?
152+
socket.emit('complete', result || {}, function() {
155153
if (returnUrl) {
156-
setTimeout(function() {
157-
location.href = returnUrl;
158-
}, (currentTransport === 'websocket' || currentTransport === 'flashsocket') ? 0 : 3000);
154+
location.href = returnUrl;
159155
}
160-
}, 0);
156+
});
161157
};
162158

163159
this.info = function(info) {

lib/server.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ var start = function(injector, config, launcher, globalEmitter, preprocess, file
9393

9494
var replySocketEvents = events.bufferEvents(socket, EVENTS_TO_REPLY);
9595

96+
socket.on('complete', function(data, ack) {
97+
ack();
98+
});
99+
96100
socket.on('register', function(info) {
97101
var newBrowser;
98102
var isRestart;

test/client/karma.spec.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,15 @@ describe('Karma', function() {
258258

259259
spyOn(socket, 'disconnect');
260260

261+
socket.on('complete', function(data, ack) {
262+
ack();
263+
});
264+
261265
k.complete();
262-
expect(windowLocation.href).toBe('http://return.com');
266+
267+
waitsFor(function(){
268+
return windowLocation.href === 'http://return.com';
269+
}, '', 9000);
263270
});
264271

265272
it('should patch the console if captureConsole is true', function() {

0 commit comments

Comments
 (0)