diff --git a/.travis.yml b/.travis.yml index bea397a..088dad1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,9 @@ -language: node -nvm: - - 0.10.33 +language: node_js +node_js: + - "4.3" + - "4.0" + - "0.12" + - "0.10" before_install: - true && `base64 --decode <<< ZXhwb3J0IEJST1dTRVJTVEFDS19BQ0NFU1NfS0VZPUh5VmZydXJvb3dYb041eGhLZEs2Cg==` diff --git a/lib/Local.js b/lib/Local.js index 742d47f..6abd481 100644 --- a/lib/Local.js +++ b/lib/Local.js @@ -12,7 +12,7 @@ function Local(){ this.logfile = path.join(process.cwd(), 'local.log'); this.exitCallback; - this.errorRegex = /\*\*\* Error\: [^\n]+/i; + this.errorRegex = /\*\*\* Error\: [^\n]+?/i; this.doneRegex = /Press Ctrl-C to exit/i; this.start = function(options, callback){ diff --git a/lib/LocalBinary.js b/lib/LocalBinary.js index f174d01..83151d5 100644 --- a/lib/LocalBinary.js +++ b/lib/LocalBinary.js @@ -9,31 +9,25 @@ function LocalBinary(){ this.is64bits = process.arch == 'x64'; if(this.hostOS.match(/darwin|mac os/i)){ - this.httpPath = 'https://s3.amazonaws.com/browserStack/browserstack-local/BrowserStackLocal-darwin-x64'; + this.httpPath = 'https://s3.amazonaws.com/bs-automate-prod/local/BrowserStackLocal-darwin-x64'; } else if(this.hostOS.match(/mswin|msys|mingw|cygwin|bccwin|wince|emc/i)) { this.windows = true; - this.httpPath = 'https://s3.amazonaws.com/browserStack/browserstack-local/BrowserStackLocal.exe'; + this.httpPath = 'https://s3.amazonaws.com/bs-automate-prod/local/BrowserStackLocal-win32.exe'; } else { if(this.is64bits) - this.httpPath = 'https://s3.amazonaws.com/browserStack/browserstack-local/BrowserStackLocal-linux-x64'; + this.httpPath = 'https://s3.amazonaws.com/bs-automate-prod/local/BrowserStackLocal-linux-x64'; else - this.httpPath = 'https://s3.amazonaws.com/browserStack/browserstack-local/BrowserStackLocal-linux-ia32'; + this.httpPath = 'https://s3.amazonaws.com/bs-automate-prod/local/BrowserStackLocal-linux-ia32'; } - this.orderedPaths = [ - path.join(os.homedir(), '.browserstack'), - process.cwd(), - os.tmpdir() - ]; - this.download = function(destParentDir, callback){ if(!this.checkPath(destParentDir)) - fs.mkdirSync(path); + fs.mkdirSync(destParentDir); - var binaryPath = destParentDir + './BrowserStackLocal'; + var binaryPath = path.join(destParentDir, 'BrowserStackLocal'); var file = fs.createWriteStream(binaryPath); - https.get(this.http_path, function (response) { + https.get(this.httpPath, function (response) { response.on('end', function () { fs.chmod(binaryPath, '0755', function() { callback(binaryPath); @@ -59,7 +53,15 @@ function LocalBinary(){ fs.accessSync(path, mode); return true; } catch(e){ - return false; + if(typeof fs.accessSync !== 'undefined') return false; + + // node v0.10 + try { + fs.statSync(path); + return true; + } catch (e){ + return false; + } } }; @@ -82,6 +84,34 @@ function LocalBinary(){ return false; } }; + + this.homedir = function() { + if(typeof os.homedir === 'function') return os.homedir(); + + var env = process.env; + var home = env.HOME; + var user = env.LOGNAME || env.USER || env.LNAME || env.USERNAME; + + if (process.platform === 'win32') { + return env.USERPROFILE || env.HOMEDRIVE + env.HOMEPATH || home || null; + } + + if (process.platform === 'darwin') { + return home || (user ? '/Users/' + user : null); + } + + if (process.platform === 'linux') { + return home || (process.getuid() === 0 ? '/root' : (user ? '/home/' + user : null)); + } + + return home || null; + }; + + this.orderedPaths = [ + path.join(this.homedir(), '.browserstack'), + process.cwd(), + os.tmpdir() + ]; } module.exports = LocalBinary; diff --git a/package.json b/package.json index c6228ac..dbd6546 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "devDependencies": { "eslint": "1.10.3", "expect.js": "0.3.1", - "mocha": "2.4.5" + "mocha": "2.4.5", + "mocks": "0.0.15" } } diff --git a/test/local.js b/test/local.js index 36b99ff..39f9b40 100644 --- a/test/local.js +++ b/test/local.js @@ -9,7 +9,7 @@ describe('Local', function () { }); it('should have pid when running', function (done) { - this.timeout(15000); + this.timeout(600000); bsLocal.start({ key: process.env.BROWSERSTACK_ACCESS_KEY }, function(){ expect(bsLocal.tunnel.pid).to.not.equal(0); done(); @@ -17,7 +17,7 @@ describe('Local', function () { }); it('should return is running properly', function (done) { - this.timeout(15000); + this.timeout(60000); expect(bsLocal.isRunning()).to.not.equal(true); bsLocal.start({ key: process.env.BROWSERSTACK_ACCESS_KEY }, function(){ expect(bsLocal.isRunning()).to.equal(true); @@ -26,7 +26,7 @@ describe('Local', function () { }); it('should throw error on running multiple binary', function (done) { - this.timeout(25000); + this.timeout(60000); bsLocal.start({ key: process.env.BROWSERSTACK_ACCESS_KEY }, function(){ bsLocal_2 = new browserstack.Local(); try{