Skip to content

Commit 1527a3e

Browse files
committed
Merge pull request #101 from Sanox/browserstack-local-windows-fix
Windows fixes
2 parents fce9725 + 28bca6c commit 1527a3e

File tree

5 files changed

+45
-38
lines changed

5 files changed

+45
-38
lines changed

bin/cli.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ function launchServer() {
120120
}
121121

122122
function launchBrowser(browser, path) {
123-
var url = 'http://localhost:' + serverPort.toString() + '/' + path;
123+
var url = 'http://localhost:' + serverPort.toString() + '/' + path.replace(/\\/g, '/');
124124
var browserString = utils.browserString(browser);
125125
logger.debug('[%s] Launching', getTestBrowserInfo(browserString, path));
126126

@@ -224,7 +224,7 @@ var statusPoller = {
224224
config.status = 1;
225225
}
226226

227-
process.kill(process.pid, 'SIGTERM');
227+
process.exit('SIGTERM');
228228
}
229229
}
230230
}, activityTimeout * 1000);
@@ -245,7 +245,7 @@ var statusPoller = {
245245
config.status = 1;
246246
}
247247

248-
process.kill(process.pid, 'SIGTERM');
248+
process.exit('SIGTERM');
249249
}
250250
}
251251
}, (activityTimeout * 1000));
@@ -308,11 +308,8 @@ try {
308308
runTests();
309309
var pid_file = process.cwd() + '/browserstack-run.pid';
310310
fs.writeFileSync(pid_file, process.pid, 'utf-8');
311-
process.on('SIGINT', function() {
312-
cleanUpAndExit('SIGINT', 1);
313-
});
314-
process.on('SIGTERM', function() {
315-
cleanUpAndExit('SIGTERM', config.status);
311+
process.on('exit', function(signal){
312+
cleanUpAndExit(signal, config.status);
316313
});
317314
} catch (e) {
318315
console.log(e);

lib/config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ if (commit_id) {
6161
});
6262

6363
var formatPath = function(path) {
64+
if (/^win/.test(process.platform)) {
65+
path = path.replace(/\//g, '\\');
66+
}
67+
6468
if (path.indexOf(pwd) === 0) {
6569
path = path.slice(pwd.length + 1);
6670
}

lib/local.js

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,32 @@
11
var Log = require('./logger'),
22
logger = new Log(global.logLevel),
3-
exec = require('child_process').exec,
3+
exec = require('child_process').execFile,
44
fs = require('fs'),
55
http = require('http'),
66
windows = ((process.platform.match(/win32/) || process.platform.match(/win64/)) !== null),
7-
localBinary = process.cwd() + (windows ? '/BrowserStackTunnel.jar' : '/BrowserStackLocal'),
7+
localBinary = process.cwd() + '/BrowserStackLocal' + (windows ? '.exe' : ''),
88
utils = require('./utils'),
99
config = require('./config');
1010

1111
var Tunnel = function Tunnel(key, port, uniqueIdentifier, callback) {
1212
var that = {};
1313

1414
function tunnelLauncher() {
15-
var tunnelCommand = (windows ? 'java -jar ' : '') + localBinary + ' ';
16-
if (config.debug) {
17-
tunnelCommand += ' -v ';
18-
}
19-
tunnelCommand += key + ' ';
20-
tunnelCommand += 'localhost' + ',';
21-
tunnelCommand += port.toString() + ',';
22-
tunnelCommand += '0';
23-
tunnelCommand += (typeof uniqueIdentifier === 'undefined') ? ' -force -onlyAutomate' : ' -tunnelIdentifier ' + uniqueIdentifier;
24-
tunnelCommand += checkAndAddProxy();
15+
var tunnelOptions = getTunnelOptions(key, uniqueIdentifier);
2516

2617
if (typeof callback !== 'function') {
2718
callback = function(){};
2819
}
2920

3021
logger.debug('[%s] Launching tunnel', new Date());
31-
var subProcess = exec(tunnelCommand, function(error, stdout, stderr) {
22+
23+
var subProcess = exec(localBinary, tunnelOptions, function(error, stdout, stderr) {
3224
logger.debug(stderr);
3325
logger.debug(error);
3426
if (stdout.indexOf('Error') >= 0 || error) {
3527
logger.debug('[%s] Tunnel launching failed', new Date());
3628
logger.debug(stdout);
37-
process.kill(process.pid, 'SIGINT');
29+
process.exit('SIGINT');
3830
}
3931
});
4032

@@ -67,30 +59,44 @@ var Tunnel = function Tunnel(key, port, uniqueIdentifier, callback) {
6759
that.process = subProcess;
6860
}
6961

70-
function checkAndAddProxy() {
71-
var proxy = config.proxy;
72-
if (typeof proxy === 'undefined') {
73-
return '';
62+
function getTunnelOptions(key, uniqueIdentifier) {
63+
var options = [key];
64+
65+
if (config.debug) {
66+
options.push('-v');
67+
}
68+
69+
if (!uniqueIdentifier) {
70+
options.push('-force');
71+
options.push('-onlyAutomate');
72+
} else {
73+
options.push('-localIdentifier ' + uniqueIdentifier);
7474
}
75-
var proxyCommand = '';
76-
proxyCommand += ' -proxyHost ' + proxy.host;
77-
proxyCommand += ' -proxyPort ' + proxy.port;
78-
if(typeof proxy.username !== 'undefined'){
79-
proxyCommand += ' -proxyUser ' + proxy.username;
80-
proxyCommand += ' -proxyPass ' + proxy.password;
75+
76+
var proxy = config.proxy;
77+
78+
if (proxy) {
79+
options.push('-proxyHost ' + proxy.host);
80+
options.push('-proxyPort ' + proxy.port);
81+
82+
if (proxy.username && proxy.password) {
83+
options.push('-proxyUser ' + proxy.username);
84+
options.push('-proxyPass ' + proxy.password);
85+
}
8186
}
82-
return proxyCommand;
87+
88+
return options;
8389
}
8490

8591
fs.exists(localBinary, function(exists) {
8692
if (exists) {
8793
tunnelLauncher();
8894
return;
8995
}
90-
logger.debug('Downloading BrowserStack Local to `%s`', localBinary);
96+
logger.debug('Downloading BrowserStack Local to "%s"', localBinary);
9197

9298
var file = fs.createWriteStream(localBinary);
93-
http.get(windows ? 'http://www.browserstack.com/BrowserStackTunnel.jar' : ('http://s3.amazonaws.com/browserStack/browserstack-local/BrowserStackLocal-' + process.platform + '-' + process.arch),
99+
http.get((windows ? 'http://s3.amazonaws.com/browserStack/browserstack-local/BrowserStackLocal.exe' : ('http://s3.amazonaws.com/browserStack/browserstack-local/BrowserStackLocal-' + process.platform + '-' + process.arch)),
94100
function(response) {
95101
response.pipe(file);
96102

@@ -101,7 +107,7 @@ var Tunnel = function Tunnel(key, port, uniqueIdentifier, callback) {
101107
}, 100);
102108
}).on('error', function(e) {
103109
logger.info('Got error while downloading binary: ' + e.message);
104-
process.kill(process.pid, 'SIGINT');
110+
process.exit('SIGINT');
105111
});
106112
});
107113
});

lib/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ exports.Server = function Server(bsClient, workers) {
255255
config.status = 1;
256256
}
257257

258-
process.kill(process.pid, 'SIGTERM');
258+
process.exit('SIGTERM');
259259
}
260260
});
261261
});

lib/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ var alertBrowserStack = function alertBrowserStack(subject, content, params, fn)
5757
if (typeof params === 'function') {
5858
} else {
5959
fn = function() {
60-
process.kill(process.pid, 'SIGINT');
60+
process.exit('SIGINT');
6161
};
6262
}
6363
}

0 commit comments

Comments
 (0)