Skip to content

Commit b5a8559

Browse files
authored
Merge pull request #111 from AdityaHirapara/LOC-1636_Alpine_binary
LOC-1636 Detect Alpine linux and download specific binary
2 parents d238484 + ffc38fb commit b5a8559

File tree

4 files changed

+83
-14
lines changed

4 files changed

+83
-14
lines changed

lib/Local.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var childProcess = require('child_process'),
55
running = require('is-running'),
66
LocalBinary = require('./LocalBinary'),
77
LocalError = require('./LocalError'),
8+
version = require('../package.json').version,
89
psTree = require('ps-tree');
910

1011
function Local(){
@@ -205,7 +206,7 @@ function Local(){
205206
};
206207

207208
this.getBinaryArgs = function(){
208-
var args = ['--daemon', this.opcode, '--log-file', this.logfile];
209+
var args = ['--daemon', this.opcode, '--log-file', this.logfile, '--source', `nodejs-${version}`];
209210
if(this.key) {
210211
args.push('--key');
211212
args.push(this.key);

lib/LocalBinary.js

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,41 @@ var https = require('https'),
33
fs = require('fs'),
44
path = require('path'),
55
os = require('os'),
6+
childProcess = require('child_process'),
67
HttpsProxyAgent = require('https-proxy-agent'),
78
LocalError = require('./LocalError');
89

910
function LocalBinary(){
1011
this.hostOS = process.platform;
1112
this.is64bits = process.arch == 'x64';
1213

13-
if(this.hostOS.match(/darwin|mac os/i)){
14-
this.httpPath = 'https://s3.amazonaws.com/bstack-local-prod/BrowserStackLocal-darwin-x64';
15-
} else if(this.hostOS.match(/mswin|msys|mingw|cygwin|bccwin|wince|emc|win32/i)) {
16-
this.windows = true;
17-
this.httpPath = 'https://s3.amazonaws.com/bstack-local-prod/BrowserStackLocal.exe';
18-
} else {
19-
if(this.is64bits)
20-
this.httpPath = 'https://s3.amazonaws.com/bstack-local-prod/BrowserStackLocal-linux-x64';
21-
else
22-
this.httpPath = 'https://s3.amazonaws.com/bstack-local-prod/BrowserStackLocal-linux-ia32';
23-
}
14+
this.getDownloadPath = function () {
15+
if(this.hostOS.match(/darwin|mac os/i)){
16+
return 'https://bstack-local-prod.s3.amazonaws.com/BrowserStackLocal-darwin-x64';
17+
} else if(this.hostOS.match(/mswin|msys|mingw|cygwin|bccwin|wince|emc|win32/i)) {
18+
this.windows = true;
19+
return 'https://bstack-local-prod.s3.amazonaws.com/BrowserStackLocal.exe';
20+
} else {
21+
if(this.isAlpine()) {
22+
return 'https://bstack-local-prod.s3.amazonaws.com/BrowserStackLocal-alpine';
23+
} else {
24+
if(this.is64bits)
25+
return 'https://bstack-local-prod.s3.amazonaws.com/BrowserStackLocal-linux-x64';
26+
else
27+
return 'https://bstack-local-prod.s3.amazonaws.com/BrowserStackLocal-linux-ia32';
28+
}
29+
}
30+
};
31+
32+
this.httpPath = this.getDownloadPath();
33+
34+
this.isAlpine = function() {
35+
try {
36+
return childProcess.execSync('grep -w "NAME" /etc/os-release').includes('Alpine');
37+
} catch(e) {
38+
return false;
39+
}
40+
};
2441

2542
this.retryBinaryDownload = function(conf, destParentDir, callback, retries, binaryPath) {
2643
var that = this;

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/local.js

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe('Local', function () {
4242
var tempLogPath = path.join(process.cwd(), 'log2.log');
4343

4444
bsLocal_2.start({ 'key': process.env.BROWSERSTACK_ACCESS_KEY, 'logfile': tempLogPath }, function(error){
45-
expect(error.toString().trim()).to.equal('LocalError: Either another browserstack local client is running on your machine or some server is listening on port 45691');
45+
expect(error.toString().trim()).to.equal('LocalError: Either another browserstack local client is running on your machine or some server is listening on port 45690');
4646
fs.unlinkSync(tempLogPath);
4747
done();
4848
});
@@ -312,6 +312,57 @@ describe('LocalBinary', function () {
312312
});
313313
});
314314

315+
describe('Download Path', function() {
316+
var sandBox;
317+
var localBinary;
318+
319+
beforeEach(function() {
320+
sandBox = sinon.sandbox.create();
321+
localBinary = new LocalBinary();
322+
});
323+
324+
it('should return download path of darwin binary', function() {
325+
var osNames = ['darwin', 'mac os'];
326+
osNames.forEach(function(os) {
327+
sandBox.stub(localBinary, 'hostOS', os);
328+
expect(localBinary.getDownloadPath()).to.equal('https://bstack-local-prod.s3.amazonaws.com/BrowserStackLocal-darwin-x64');
329+
});
330+
});
331+
332+
it('should return download path of exe binary', function() {
333+
var osNames = ['mswin', 'msys', 'mingw', 'cygwin', 'bccwin', 'wince', 'emc', 'win32'];
334+
osNames.forEach(function(os) {
335+
sandBox.stub(localBinary, 'hostOS', os);
336+
expect(localBinary.getDownloadPath()).to.equal('https://bstack-local-prod.s3.amazonaws.com/BrowserStackLocal.exe');
337+
});
338+
});
339+
340+
it('should return download path of linux 64 arch binary', function() {
341+
sandBox.stub(localBinary, 'hostOS', 'linux');
342+
sandBox.stub(localBinary, 'is64bits', true);
343+
localBinary.isAlpine = sandBox.stub(localBinary, 'isAlpine').returns(false);
344+
expect(localBinary.getDownloadPath()).to.equal('https://bstack-local-prod.s3.amazonaws.com/BrowserStackLocal-linux-x64');
345+
});
346+
347+
it('should return download path of linux 32 arch binary', function() {
348+
sandBox.stub(localBinary, 'hostOS', 'linux');
349+
sandBox.stub(localBinary, 'is64bits', false);
350+
localBinary.isAlpine = sandBox.stub(localBinary, 'isAlpine').returns(false);
351+
expect(localBinary.getDownloadPath()).to.equal('https://bstack-local-prod.s3.amazonaws.com/BrowserStackLocal-linux-ia32');
352+
});
353+
354+
it('should return download path of alpine linux binary', function() {
355+
sandBox.stub(localBinary, 'hostOS', 'linux');
356+
localBinary.isAlpine = sandBox.stub(localBinary, 'isAlpine').returns(true);
357+
expect(localBinary.getDownloadPath()).to.equal('https://bstack-local-prod.s3.amazonaws.com/BrowserStackLocal-alpine');
358+
});
359+
360+
afterEach(function(done) {
361+
sandBox.restore();
362+
done();
363+
});
364+
});
365+
315366
describe('Download', function() {
316367
var proxy;
317368
var proxyPort;

0 commit comments

Comments
 (0)