Skip to content

Commit

Permalink
fix(server): launch browsers when file_list is ready
Browse files Browse the repository at this point in the history
If we have a lot of files and a fast starting browser (PhantomJS),
the browser might try to connect to the web server before the
server is ready to reply, causing the connect mechanism to time out.
Make sure to wait until fileList.refresh() is complete before starting
the browsers.
  • Loading branch information
jpommerening committed Jul 29, 2014
1 parent 1097002 commit ee537a0
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var start = function(injector, config, launcher, globalEmitter, preprocess, file
var filesPromise = fileList.refresh();

if (config.autoWatch) {
filesPromise.then(function() {
filesPromise = filesPromise.then(function() {
injector.invoke(watcher.watch);
}, function() {
injector.invoke(watcher.watch);
Expand All @@ -61,15 +61,21 @@ var start = function(injector, config, launcher, globalEmitter, preprocess, file
// Some browsers did not get captured.
var singleRunBrowserNotCaptured = false;

webServer.listen(config.port, function() {
log.info('Karma v%s server started at http://%s:%s%s', constant.VERSION, config.hostname,
config.port, config.urlRoot);

var launchSingleRunBrowsers = function() {
if (config.browsers && config.browsers.length) {
injector.invoke(launcher.launch, launcher).forEach(function(browserLauncher) {
singleRunDoneBrowsers[browserLauncher.id] = false;
});
}
};

webServer.listen(config.port, function() {
log.info('Karma v%s server started at http://%s:%s%s', constant.VERSION, config.hostname,
config.port, config.urlRoot);

// Wait until fileList.refresh() is done, or else we might
// not be ready to reply to the browser's capture request.
filesPromise.then(launchSingleRunBrowsers, launchSingleRunBrowsers);
});

globalEmitter.on('browsers_change', function() {
Expand Down

0 comments on commit ee537a0

Please sign in to comment.