diff --git a/lib/Local.js b/lib/Local.js index 054fe50..6381fb7 100644 --- a/lib/Local.js +++ b/lib/Local.js @@ -259,13 +259,17 @@ function Local(){ var killChecker = setInterval(() => { if(childPids.length === 0) { clearInterval(killChecker); - process.kill(this.pid); - - // This gives time to local binary to send kill signal to railsApp. - setTimeout(() => { + try { + process.kill(this.pid); + // This gives time to local binary to send kill signal to railsApp. + setTimeout(() => { + this.isProcessRunning = false; + callback(); + }, 2000); + } catch(err) { this.isProcessRunning = false; callback(); - }, 2000); + } } for(var i in childPids) { try { @@ -274,7 +278,7 @@ function Local(){ childPids.splice(i, 1); } } - },100); + },500); }); }; } diff --git a/test/local.js b/test/local.js index b4e20d9..79af54a 100644 --- a/test/local.js +++ b/test/local.js @@ -210,6 +210,17 @@ describe('Local', function () { }); }); + it('should stop local', function (done) { + this.timeout(MAX_TIMEOUT); + bsLocal.start({ 'key': process.env.BROWSERSTACK_ACCESS_KEY}, function(){ + expect(bsLocal.isRunning()).to.equal(true); + bsLocal.stop(function(){ + expect(bsLocal.isRunning()).to.equal(false); + done(); + }); + }); + }); + afterEach(function (done) { this.timeout(60000); bsLocal.stop(done);