Skip to content

Commit 7e73b1f

Browse files
Add unit tests
1 parent 8062df0 commit 7e73b1f

File tree

2 files changed

+70
-14
lines changed

2 files changed

+70
-14
lines changed

lib/LocalBinary.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,26 @@ function LocalBinary(){
1111
this.hostOS = process.platform;
1212
this.is64bits = process.arch == 'x64';
1313

14-
if(this.hostOS.match(/darwin|mac os/i)){
15-
this.httpPath = 'https://s3.amazonaws.com/bstack-local-prod/BrowserStackLocal-darwin-x64';
16-
} else if(this.hostOS.match(/mswin|msys|mingw|cygwin|bccwin|wince|emc|win32/i)) {
17-
this.windows = true;
18-
this.httpPath = 'https://s3.amazonaws.com/bstack-local-prod/BrowserStackLocal.exe';
19-
} else {
20-
if(this.isAlpine()) {
21-
this.httpPath = 'https://s3.amazonaws.com/bstack-local-prod/BrowserStackLocal-alpine';
14+
this.getDownloadPath = function () {
15+
var that = this;
16+
if(that.hostOS.match(/darwin|mac os/i)){
17+
return 'https://s3.amazonaws.com/bstack-local-prod/BrowserStackLocal-darwin-x64';
18+
} else if(that.hostOS.match(/mswin|msys|mingw|cygwin|bccwin|wince|emc|win32/i)) {
19+
that.windows = true;
20+
return 'https://s3.amazonaws.com/bstack-local-prod/BrowserStackLocal.exe';
2221
} else {
23-
if(this.is64bits)
24-
this.httpPath = 'https://s3.amazonaws.com/bstack-local-prod/BrowserStackLocal-linux-x64';
25-
else
26-
this.httpPath = 'https://s3.amazonaws.com/bstack-local-prod/BrowserStackLocal-linux-ia32';
22+
if(that.isAlpine()) {
23+
return 'https://s3.amazonaws.com/bstack-local-prod/BrowserStackLocal-alpine';
24+
} else {
25+
if(that.is64bits)
26+
return 'https://s3.amazonaws.com/bstack-local-prod/BrowserStackLocal-linux-x64';
27+
else
28+
return 'https://s3.amazonaws.com/bstack-local-prod/BrowserStackLocal-linux-ia32';
29+
}
2730
}
28-
}
31+
};
32+
33+
this.httpPath = this.getDownloadPath();
2934

3035
this.isAlpine = function() {
3136
try {

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://s3.amazonaws.com/bstack-local-prod/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://s3.amazonaws.com/bstack-local-prod/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://s3.amazonaws.com/bstack-local-prod/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://s3.amazonaws.com/bstack-local-prod/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://s3.amazonaws.com/bstack-local-prod/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)