Skip to content

Commit

Permalink
Make it work
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed May 15, 2015
1 parent 39f2869 commit 5af14dd
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 29 deletions.
13 changes: 3 additions & 10 deletions client/karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ var Karma = function(socket, iframe, opener, 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 resultsBufferLimit = 50;
var resultsBuffer = [];

this.VERSION = constant.VERSION;
Expand Down Expand Up @@ -104,7 +103,6 @@ var Karma = function(socket, iframe, opener, navigator, location) {

this.stringify = stringify;


var clearContext = function() {
reloadingContext = true;
navigateContextTo('about:blank');
Expand Down Expand Up @@ -218,14 +216,9 @@ var Karma = function(socket, iframe, opener, navigator, location) {

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

// TODO(vojta): make resultsBufferLimit configurable
if (currentTransport === 'websocket') {
socket.io.engine.on('upgrade', function() {
resultsBufferLimit = 1;
} else {
resultsBufferLimit = 50;
}
})

socket.emit('register', {
name: navigator.userAgent,
Expand Down
15 changes: 7 additions & 8 deletions client/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ var util = require('./util');
var KARMA_URL_ROOT = require('./constants').KARMA_URL_ROOT;


// connect socket.io
// https://github.com/LearnBoost/Socket.IO/wiki/Configuring-Socket.IO
var socket = io.connect('http://' + location.host, {
'reconnection delay': 500,
'reconnection limit': 2000,
'resource': KARMA_URL_ROOT.substr(1) + 'socket.io',
'sync disconnect on unload': true,
'max reconnection attempts': Infinity
// Connect to the server using socket.io http://socket.io
var socket = io('http://' + location.host, {
reconnectionDelay: 500,
reconnectionDelayMax: Infinity,
timeout: 2000,
path: '/' + KARMA_URL_ROOT.substr(1) + 'socket.io',
'sync disconnect on unload': true
});

// instantiate the updater of the view
Expand Down
2 changes: 1 addition & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ var Config = function() {
this.urlRoot = '/';
this.reportSlowerThan = 0;
this.loggers = [constant.CONSOLE_APPENDER];
this.transports = ['websocket', 'polling'];
this.transports = ['polling', 'websocket'];
this.plugins = ['karma-*'];
this.client = {
args: [],
Expand Down
9 changes: 2 additions & 7 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ var start = function(injector, config, launcher, globalEmitter, preprocess, file
// to suppress "browser disconnect" warnings
// TODO(vojta): change the client to not send the event (if disconnected by purpose)
var sockets = socketServer.sockets.sockets;
Object.getOwnPropertyNames(sockets).forEach(function(key) {
var socket = sockets[key];

sockets.forEach(function(socket) {
socket.removeAllListeners('disconnect');
if (!socket.disconnected) {
socket.disconnect();
Expand Down Expand Up @@ -230,11 +230,6 @@ var start = function(injector, config, launcher, globalEmitter, preprocess, file
clearTimeout(closeTimeout);
removeAllListeners();
});

// shutdown socket.io flash transport, if defined
if (socketServer.flashPolicyServer) {
socketServer.flashPolicyServer.close();
}
});
};

Expand Down
4 changes: 4 additions & 0 deletions test/client/karma.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ describe('Karma', function() {
log.push('start');
});

setTransportTo('websocket');

// adapter didn't call info({total: x})
k.result();
expect(log).toEqual(['start', 'result']);
Expand All @@ -178,6 +180,8 @@ describe('Karma', function() {

socket.on('start', spyStart);

setTransportTo('websocket');

k.info({total: 321});
k.result();
expect(log).toEqual(['start', 'result']);
Expand Down
17 changes: 14 additions & 3 deletions test/client/mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,26 @@ var Emitter = function() {
var MockSocket = function() {
Emitter.call(this);

this.socket = {transport: {name: 'websocket'}};
var transportName = 'websocket';

this.io = {
engine: {
on: function(event, cb) {
if (event === 'upgrade' && transportName === 'websocket') {
//setTimeout(cb, 0);
cb();
}
}
}
};

this.disconnect = function() {
this.emit('disconnect');
};

// MOCK API
this._setTransportNameTo = function(transportName) {
this.socket.transport.name = transportName;
this._setTransportNameTo = function(name) {
transportName = name;
};
};

Expand Down

0 comments on commit 5af14dd

Please sign in to comment.