Skip to content

Commit 2c4df2b

Browse files
07souravkundafrancisf
authored andcommitted
add unit tests
1 parent dfd3ab5 commit 2c4df2b

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

lib/Local.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ function Local(){
4343
}
4444
try{
4545
const obj = childProcess.spawnSync(that.binaryPath, that.getBinaryArgs());
46+
this.tunnel = {pid: obj.pid};
4647
var data = {};
4748
if(obj.stdout.length > 0)
4849
data = JSON.parse(obj.stdout);

test/local.js

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,43 @@ describe('Local', function () {
225225
this.timeout(60000);
226226
bsLocal.stop(done);
227227
});
228-
229228
});
230229

230+
describe('Start sync', () => {
231+
var bsLocal;
232+
beforeEach(function () {
233+
bsLocal = new browserstack.Local();
234+
});
235+
236+
it('should have pid when running', function () {
237+
this.timeout(60000);
238+
bsLocal.startSync({ 'key': process.env.BROWSERSTACK_ACCESS_KEY});
239+
expect(bsLocal.tunnel.pid).to.not.equal(0);
240+
});
241+
242+
it('should return is running properly', function () {
243+
this.timeout(60000);
244+
expect(bsLocal.isRunning()).to.not.equal(true);
245+
bsLocal.startSync({ 'key': process.env.BROWSERSTACK_ACCESS_KEY});
246+
expect(bsLocal.isRunning()).to.equal(true);
247+
});
248+
249+
it('should throw error on running multiple binary', function () {
250+
this.timeout(60000);
251+
bsLocal.startSync({ 'key': process.env.BROWSERSTACK_ACCESS_KEY });
252+
bsLocal_2 = new browserstack.Local();
253+
var tempLogPath = path.join(process.cwd(), 'log2.log');
254+
const error = bsLocal_2.startSync({ 'key': process.env.BROWSERSTACK_ACCESS_KEY, 'logfile': tempLogPath });
255+
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');
256+
fs.unlinkSync(tempLogPath);
257+
});
258+
259+
afterEach(function (done) {
260+
this.timeout(60000);
261+
bsLocal.stop(done);
262+
});
263+
})
264+
231265
describe('LocalBinary', function () {
232266
describe('Retries', function() {
233267
var unlinkTmp,
@@ -414,5 +448,12 @@ describe('LocalBinary', function () {
414448
done();
415449
});
416450
});
451+
452+
it('should download binaries in sync', function () {
453+
this.timeout(MAX_TIMEOUT);
454+
var conf = {};
455+
const result = binary.downloadSync(conf, tempDownloadPath);
456+
expect(fs.existsSync(result)).to.equal(true);
457+
});
417458
});
418459
});

0 commit comments

Comments
 (0)