Skip to content

Commit

Permalink
Merge branch 'socket-io-1.3' into canary
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed May 27, 2015
2 parents a2edf47 + d793b25 commit 79072ae
Show file tree
Hide file tree
Showing 23 changed files with 223 additions and 206 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ before_script:
- sh -e /etc/init.d/xvfb start
- npm install -g grunt-cli
- rm -rf node_modules/karma
- cd node_modules && ln -nsf ../ karma && cd ../
- export $(openssl aes-256-cbc -pass env:CREDENTIALS_PASS -d -in credentials)

script:
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
<a name"0.12.33"></a>
### 0.12.33 (2015-05-26)


#### Bug Fixes

* catch exceptions from SourceMapConsumer ([5d42e643](https://github.com/karma-runner/karma/commit/5d42e643))
* Safeguard IE against console.log ([0b5ff8f6](https://github.com/karma-runner/karma/commit/0b5ff8f6), closes [#1209](https://github.com/karma-runner/karma/issues/1209))
* **config:** Default remaining client options if any are set ([632dd5e3](https://github.com/karma-runner/karma/commit/632dd5e3), closes [#961](https://github.com/karma-runner/karma/issues/961))
* **init:** fix test-main.(js/coffee) generation ([d8521ef4](https://github.com/karma-runner/karma/commit/d8521ef4), closes [#1120](https://github.com/karma-runner/karma/issues/1120), [#896](https://github.com/karma-runner/karma/issues/896))


<a name="0.12.31"></a>
### 0.12.31 (2015-01-02)

Expand Down
19 changes: 8 additions & 11 deletions client/karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ 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;
this.config = {};

// Expose for testing purposes as there is no global socket.io
// registry anymore.
this.socket = socket;

var childWindow = null;
var navigateContextTo = function(url) {
if (self.config.useIframe === false) {
Expand Down Expand Up @@ -104,7 +107,6 @@ var Karma = function(socket, iframe, opener, navigator, location) {

this.stringify = stringify;


var clearContext = function() {
reloadingContext = true;
navigateContextTo('about:blank');
Expand All @@ -114,7 +116,7 @@ var Karma = function(socket, iframe, opener, navigator, location) {
// we are not going to execute at all
this.error = function(msg, url, line) {
hasError = true;
socket.emit('error', url ? msg + '\nat ' + url + (line ? ':' + line : '') : msg);
socket.emit('karma_error', url ? msg + '\nat ' + url + (line ? ':' + line : '') : msg);
this.complete();
return false;
};
Expand Down Expand Up @@ -218,14 +220,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' || currentTransport === 'flashsocket') {
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
4 changes: 2 additions & 2 deletions docs/config/01-configuration-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,10 @@ on whether all tests passed or any tests failed.
## transports
**Type:** Array

**Default:** `['websocket', 'flashsocket', 'xhr-polling', 'jsonp-polling']`
**Default:** `['polling', 'websocket']`

**Description:** An array of allowed transport methods between the browser and testing server. This configuration setting
is handed off to [socket.io](https://github.com/LearnBoost/Socket.IO/wiki/Configuring-Socket.IO) (which manages the communication
is handed off to [socket.io](http://socket.io/) (which manages the communication
between browsers and the testing server).

## client.useIframe
Expand Down
1 change: 0 additions & 1 deletion docs/intro/01-installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ On Linux, we recommend using [NVM](https://github.com/creationix/nvm).

Note: Karma works on the two latest stable versions of node. That is **0.10.x** and **0.12.x** at this point. Also works on iojs 2.x.x.


## Installing Karma and plugins

The recommended approach is to install Karma (and all the plugins your project needs) locally in
Expand Down
2 changes: 1 addition & 1 deletion lib/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ var Browser = function(id, fullName, /* capturedBrowsers */ collection, emitter,
return this.name;
};

this.onError = function(error) {
this.onKarmaError = function(error) {
if (this.isReady()) {
return;
}
Expand Down
10 changes: 8 additions & 2 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ var normalizeConfig = function(config, configFilePath) {
throw new Error('Invalid configuration: client.args must be an array of strings');
}

var defaultClient = config.defaultClient || {};
Object.keys(defaultClient).forEach(function(key) {
var option = config.client[key];
config.client[key] = helper.isDefined(option) ? option : defaultClient[key];
});

// normalize preprocessors
var preprocessors = config.preprocessors || {};
var normalizedPreprocessors = config.preprocessors = Object.create(null);
Expand Down Expand Up @@ -223,9 +229,9 @@ var Config = function() {
this.urlRoot = '/';
this.reportSlowerThan = 0;
this.loggers = [constant.CONSOLE_APPENDER];
this.transports = ['websocket', 'flashsocket', 'xhr-polling', 'jsonp-polling'];
this.transports = ['polling', 'websocket'];
this.plugins = ['karma-*'];
this.client = {
this.defaultClient = this.client = {
args: [],
useIframe: true,
captureConsole: true
Expand Down
4 changes: 2 additions & 2 deletions lib/launchers/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ var ProcessLauncher = function(spawn, tempDir, timer) {

var errorOutput = '';

self._process.on('close', function(code) {
self._process.on('exit', function(code) {
self._onProcessExit(code, errorOutput);
});

self._process.on('error', function(err) {
self._process.on('karma_error', function(err) {
if (err.code === 'ENOENT') {
self._retryLimit = -1;
errorOutput = 'Can not find the binary ' + cmd + '\n\t' +
Expand Down
23 changes: 4 additions & 19 deletions lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,6 @@ var log4js = require('log4js');
var helper = require('./helper');
var constant = require('./constants');

// Special Wrapper for Socket.io :(
var LogWrapper = function(name, level) {
this.logger = log4js.getLogger(name);
this.logger.setLevel(level);
};
['error', 'warn', 'info', 'debug'].forEach(function(level) {
LogWrapper.prototype[level] = function() {
this.logger[level].apply(this.logger, arguments);
};
});

// #### Public Functions

// Setup the logger by passing in the configuration options. It needs
Expand Down Expand Up @@ -61,15 +50,11 @@ var setup = function(level, colors, appenders) {
// to be used as a logger for socket.io.
// * `level`, which defaults to the global level.
var create = function(name, level) {
if (name === 'socket.io') {
return new LogWrapper('socket.io', level);
} else {
var logger = log4js.getLogger(name || 'karma');
if (helper.isDefined(level)) {
logger.setLevel(level);
}
return logger;
var logger = log4js.getLogger(name || 'karma');
if (helper.isDefined(level)) {
logger.setLevel(level);
}
return logger;
};


Expand Down
29 changes: 10 additions & 19 deletions lib/server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var io = require('socket.io');
var Server = require('socket.io');
var di = require('di');

var cfg = require('./config');
Expand Down Expand Up @@ -83,7 +83,7 @@ var start = function(injector, config, launcher, globalEmitter, preprocess, file
}
});

var EVENTS_TO_REPLY = ['start', 'info', 'error', 'result', 'complete'];
var EVENTS_TO_REPLY = ['start', 'info', 'karma_error', 'result', 'complete'];
socketServer.sockets.on('connection', function(socket) {
log.debug('A browser has connected on socket ' + socket.id);

Expand Down Expand Up @@ -196,11 +196,13 @@ 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();
// Disconnect asynchronously. Socket.io mutates the `sockets.sockets` array
// underneath us so this would skip every other browser/socket.
process.nextTick(socket.disconnect.bind(socket));
}
});

Expand All @@ -226,11 +228,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 All @@ -254,16 +251,10 @@ start.$inject = ['injector', 'config', 'launcher', 'emitter', 'preprocess', 'fil


var createSocketIoServer = function(webServer, executor, config) {
var server = io.listen(webServer, {
var server = new Server(webServer, {
// avoid destroying http upgrades from socket.io to get proxied websockets working
'destroy upgrade': false,
// socket.io has a timeout (15s by default) before destroying a store (a data structure where
// data associated with a socket are stored). Unfortunately this timeout is not cleared
// properly on socket.io shutdown and this timeout prevents karma from exiting cleanly.
// We change this timeout to 0 to make Karma exit just after all tests were executed.
'client store expiration': 0,
logger: logger.create('socket.io', constant.LOG_ERROR),
resource: config.urlRoot + 'socket.io',
destroyUpgrade: false,
path: config.urlRoot + 'socket.io/',
transports: config.transports
});

Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
],
"dependencies": {
"di": "~0.0.1",
"socket.io": "0.9.16",
"socket.io": "~1.3.5",
"chokidar": ">=0.8.2",
"glob": "~3.2.7",
"minimatch": "~0.2",
Expand Down Expand Up @@ -201,6 +201,8 @@
"grunt-jscs": "^1.8.0",
"grunt-mocha-test": "^0.12.7",
"grunt-npm": "0.0.2",
"grunt-simple-mocha": "*",
"karma-browserify": "^4.1.2",
"karma-browserstack-launcher": "*",
"karma-chrome-launcher": "*",
"karma-coffee-preprocessor": "*",
Expand All @@ -209,7 +211,7 @@
"karma-firefox-launcher": "*",
"karma-growl-reporter": "*",
"karma-html2js-preprocessor": "*",
"karma-jasmine": "^0.1.5",
"karma-jasmine": "~0.3.5",
"karma-junit-reporter": "*",
"karma-live-preprocessor": "*",
"karma-mocha": "*",
Expand Down
6 changes: 0 additions & 6 deletions scripts/presubmit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,6 @@ else
git push $REMOTE :$TRAVIS_BRANCH
fi


# Authenticate NPM.
npm config set email "karmarunnerbot@gmail.com"
npm config set _auth $NPM_TOKEN

if [ "$PUSH_TO_NPM" ]; then
if [ "$REMOTE_BRANCH" = "$STABLE_BRANCH" ]; then
npm publish --tag latest
Expand All @@ -172,5 +167,4 @@ else
fi

# Clean up the credentials.
npm config set _auth ""
rm .git/credentials
11 changes: 4 additions & 7 deletions test/client/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@ module.exports = function(config) {
// base path, that will be used to resolve files and exclude
basePath: '../..',

frameworks: ['jasmine', 'commonjs'],
frameworks: ['browserify', 'mocha'],

// list of files / patterns to load in the browser
files: [
'client/*.js',
'test/client/*.js'
],

// list of files to exclude
exclude: [
'client/main.js'
],

preprocessors: {
'client/*.js': ['commonjs'],
'test/client/*.js': ['commonjs']
'test/client/*.js': ['browserify']
},

// use dots reporter, as travis terminal does not support escaping sequences
Expand Down Expand Up @@ -72,11 +69,11 @@ module.exports = function(config) {
reportSlowerThan: 500,

plugins: [
'karma-jasmine',
'karma-mocha',
'karma-chrome-launcher',
'karma-firefox-launcher',
'karma-junit-reporter',
'karma-commonjs'
'karma-browserify'
]
});
};
Loading

0 comments on commit 79072ae

Please sign in to comment.