From a8ac6d2d86cad3898d21f019b6fc0a5a2b99cd00 Mon Sep 17 00:00:00 2001 From: Vojta Jina Date: Sun, 25 Aug 2013 17:07:01 -0700 Subject: [PATCH] fix: support reconnecting for manually captured browsers Add "launchdId" (id) to manually captured browsers. This also changes the browser id to be a string rather than a number. --- lib/launcher.js | 2 +- static/karma.src.js | 4 +++- test/client/karma.spec.js | 7 +++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/launcher.js b/lib/launcher.js index d08684266..ca9ab7f65 100644 --- a/lib/launcher.js +++ b/lib/launcher.js @@ -103,7 +103,7 @@ var Launcher = function(emitter, injector) { Launcher.$inject = ['emitter', 'injector']; Launcher.generateId = function() { - return Math.floor(Math.random() * 100000000); + return '' + Math.floor(Math.random() * 100000000); }; diff --git a/static/karma.src.js b/static/karma.src.js index 8dd131b28..247fe295f 100644 --- a/static/karma.src.js +++ b/static/karma.src.js @@ -50,6 +50,8 @@ var Karma = function(socket, context, navigator, location) { var hasError = false; var store = {}; var self = this; + var browserId = (location.search.match(/\?id=(.*)/) || [])[1] || + 'manual-' + Math.floor(Math.random() * 10000); var resultsBufferLimit = 1; var resultsBuffer = []; @@ -281,7 +283,7 @@ var Karma = function(socket, context, navigator, location) { socket.emit('register', { name: navigator.userAgent, - id: parseInt((location.search.match(/\?id=(.*)/) || [])[1], 10) || null + id: browserId }); }); }; diff --git a/test/client/karma.spec.js b/test/client/karma.spec.js index f4c56a248..3b1a726bf 100644 --- a/test/client/karma.spec.js +++ b/test/client/karma.spec.js @@ -78,11 +78,14 @@ describe('karma', function() { it('should report browser id', function() { + windowLocation.search = '?id=567'; + socket = new MockSocket(); + k = new Karma(socket, {}, windowNavigator, windowLocation); + var spyInfo = jasmine.createSpy('onInfo').andCallFake(function(info) { - expect(info.id).toBe(567); + expect(info.id).toBe('567'); }); - windowLocation.search = '?id=567'; socket.on('register', spyInfo); socket.emit('connect');