browserstacktunnel-wrapper
Advanced tools
Comparing version 1.1.1 to 1.1.2
{ | ||
"name": "browserstacktunnel-wrapper", | ||
"description": "A Node.js wrapper for the BrowserStack java tunnel client ", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"homepage": "https://github.com/pghalliday/node-BrowserStackTunnel.git", | ||
@@ -38,3 +38,4 @@ "author": { | ||
"mocks": "0.0.15", | ||
"grunt-cli": "~0.1.9" | ||
"grunt-cli": "~0.1.9", | ||
"sinon": "~1.7.3" | ||
}, | ||
@@ -41,0 +42,0 @@ "keywords": [ |
[ | ||
{"vagrant-omnibus": "1.1.1"}, | ||
{"vagrant-berkshelf": "1.3.3"} | ||
{"vagrant-omnibus": "1.2.1"}, | ||
{"vagrant-berkshelf": "1.3.7"} | ||
] |
@@ -11,12 +11,2 @@ node-BrowserStackTunnel | ||
## Features | ||
- should start the tunnel using the default jar file included in the package | ||
- should error if an invalid jar file is specified | ||
- should error if stopped before started | ||
- should error if no server listening on the specified host and port | ||
- should error if started when already running | ||
- should error if user provided an invalid key | ||
- should download new jar if promted that a new version exists, hence auto download doesnt work | ||
## Installation | ||
@@ -39,3 +29,6 @@ | ||
sslFlag: 0 | ||
}] | ||
}], | ||
jarFile: 'your_jar_file', // optionally override the included BrowserStackTunnel.jar file | ||
tunnelIdentifier: 'my_tunnel', // optionally set the -tunnelIdentifier option | ||
skipCheck: true // optionally set the -skipCheck option | ||
}); | ||
@@ -42,0 +35,0 @@ |
@@ -9,3 +9,3 @@ var util = require('util'), | ||
'use strict'; | ||
var params = '', | ||
var params = [], | ||
currentDir = __dirname ? __dirname + '/..' : '.', | ||
@@ -18,9 +18,20 @@ defaultJarPath = util.format('%s/bin/BrowserStackTunnel.jar', currentDir); | ||
options.jarFile = options.jarFile || defaultJarPath; | ||
var hosts = ''; | ||
options.hosts.forEach(function (host) { | ||
if (params.length > 0) { | ||
params += ','; | ||
if (hosts.length > 0) { | ||
hosts += ','; | ||
} | ||
params += host.name + ',' + host.port + ',' + host.sslFlag; | ||
hosts += host.name + ',' + host.port + ',' + host.sslFlag; | ||
}); | ||
params.push(hosts); | ||
if (options.tunnelIdentifier) { | ||
params.push('-tunnelIdentifier', options.tunnelIdentifier); | ||
} | ||
if (options.skipCheck) { | ||
params.push('-skipCheck'); | ||
} | ||
this.state = 'stop'; | ||
@@ -110,3 +121,3 @@ this.stateMatchers = { | ||
this.cleanUp(); | ||
this.tunnel = spawn('java', ['-jar', options.jarFile, options.key, params]); | ||
this.tunnel = spawn('java', ['-jar', options.jarFile, options.key].concat(params)); | ||
this.tunnel.stdout.on('data', this.updateState.bind(this)); | ||
@@ -113,0 +124,0 @@ this.tunnel.stderr.on('data', this.updateState.bind(this)); |
@@ -5,40 +5,45 @@ var util = require('util'), | ||
var childProcess = {}; | ||
childProcess.spawn = function (cmd, args) { | ||
function std() {} | ||
var childProcess = { | ||
cleanUp: function() { | ||
process.removeAllListeners('mock:child_process:stdout:data'); | ||
process.removeAllListeners('mock:child_process:stderr:data'); | ||
process.removeAllListeners('mock:child_process:error'); | ||
process.removeAllListeners('mock:child_process:exit'); | ||
}, | ||
function mockProcess(cmd, args) { | ||
var self = this; | ||
spawn: function (cmd, args) { | ||
function std() {} | ||
this.stdout = new std(); | ||
this.stderr = new std(); | ||
this.kill = function () { | ||
self.emit('exit'); | ||
}; | ||
function mockProcess(cmd, args) { | ||
var self = this; | ||
process.removeAllListeners('mock:child_process:stdout:data'); | ||
process.removeAllListeners('mock:child_process:stderr:data'); | ||
process.removeAllListeners('mock:child_process:error'); | ||
process.removeAllListeners('mock:child_process:exit'); | ||
this.stdout = new std(); | ||
this.stderr = new std(); | ||
this.kill = function () { | ||
self.emit('exit'); | ||
}; | ||
process.on('mock:child_process:stdout:data', function(data) { | ||
self.stdout.emit('data', data); | ||
}); | ||
childProcess.cleanUp(); | ||
process.on('mock:child_process:stderr:data', function(data) { | ||
self.stderr.emit('data', data); | ||
}); | ||
process.on('mock:child_process:stdout:data', function(data) { | ||
self.stdout.emit('data', data); | ||
}); | ||
process.on('mock:child_process:error', function(data) { | ||
self.emit('error', data); | ||
}); | ||
process.on('mock:child_process:stderr:data', function(data) { | ||
self.stderr.emit('data', data); | ||
}); | ||
process.on('mock:child_process:exit', function(data) { | ||
self.emit('exit', data); | ||
}); | ||
} | ||
process.on('mock:child_process:error', function(data) { | ||
self.emit('error', data); | ||
}); | ||
util.inherits(std, EventEmitter); | ||
util.inherits(mockProcess, EventEmitter); | ||
return new mockProcess(cmd, args); | ||
process.on('mock:child_process:exit', function(data) { | ||
self.emit('exit', data); | ||
}); | ||
} | ||
util.inherits(std, EventEmitter); | ||
util.inherits(mockProcess, EventEmitter); | ||
return new mockProcess(cmd, args); | ||
} | ||
}; | ||
@@ -45,0 +50,0 @@ |
@@ -6,3 +6,8 @@ var expect = require('expect.js'), | ||
fsMock = require('../lib/mocks').fsMock, | ||
bs = mocks.loadFile('./src/BrowserStackTunnel.js', { | ||
sinon = require('sinon'); | ||
var spawnSpy = sinon.spy(childProcessMock.spawn); | ||
childProcessMock.spawn = spawnSpy; | ||
var bs = mocks.loadFile('./src/BrowserStackTunnel.js', { | ||
child_process: childProcessMock, | ||
@@ -23,27 +28,10 @@ http: httpMock, | ||
SSL_FLAG = 0, | ||
KEY = 'This is a fake key'; | ||
KEY = 'This is a fake key', | ||
HOST_NAME2 = 'localhost2', | ||
PORT2 = 8081, | ||
SSL_FLAG2 = 1, | ||
DEFAULT_JAR_FILE = 'src/../bin/BrowserStackTunnel.jar'; | ||
describe('BrowserStackTunnel', function () { | ||
'use strict'; | ||
it('should start the tunnel using the default jar file included in the package', function (done) { | ||
var browserStackTunnel = new bs.BrowserStackTunnel({ | ||
key: KEY, | ||
hosts: [{ | ||
name: HOST_NAME, | ||
port: PORT, | ||
sslFlag: SSL_FLAG | ||
}], | ||
jarFile: VALID_JAR_FILE | ||
}); | ||
browserStackTunnel.start(function (error) { | ||
if (error) { | ||
expect().fail(function () { return error; }); | ||
} else if (browserStackTunnel.state === 'started') { | ||
done(); | ||
} | ||
}); | ||
process.emit('mock:child_process:stdout:data', 'monkey----- Press Ctrl-C to exit ----monkey'); | ||
}); | ||
@@ -167,8 +155,171 @@ it('should error if an invalid jar file is specified', function (done) { | ||
it('should support a single host with the default jar file', function (done) { | ||
spawnSpy.reset(); | ||
var browserStackTunnel = new bs.BrowserStackTunnel({ | ||
key: KEY, | ||
hosts: [{ | ||
name: HOST_NAME, | ||
port: PORT, | ||
sslFlag: SSL_FLAG | ||
}], | ||
}); | ||
browserStackTunnel.start(function (error) { | ||
if (error) { | ||
expect().fail(function () { return error; }); | ||
} else if (browserStackTunnel.state === 'started') { | ||
sinon.assert.calledOnce(spawnSpy); | ||
sinon.assert.calledWithExactly( | ||
spawnSpy, | ||
'java', [ | ||
'-jar', | ||
DEFAULT_JAR_FILE, | ||
KEY, | ||
HOST_NAME + ',' + PORT + ',' + SSL_FLAG | ||
] | ||
); | ||
done(); | ||
} | ||
}); | ||
process.emit('mock:child_process:stdout:data', 'monkey----- Press Ctrl-C to exit ----monkey'); | ||
}); | ||
it('should support multiple hosts', function (done) { | ||
spawnSpy.reset(); | ||
var browserStackTunnel = new bs.BrowserStackTunnel({ | ||
key: KEY, | ||
hosts: [{ | ||
name: HOST_NAME, | ||
port: PORT, | ||
sslFlag: SSL_FLAG | ||
}, { | ||
name: HOST_NAME2, | ||
port: PORT2, | ||
sslFlag: SSL_FLAG2 | ||
}] | ||
}); | ||
browserStackTunnel.start(function (error) { | ||
if (error) { | ||
expect().fail(function () { return error; }); | ||
} else if (browserStackTunnel.state === 'started') { | ||
sinon.assert.calledOnce(spawnSpy); | ||
sinon.assert.calledWithExactly( | ||
spawnSpy, | ||
'java', [ | ||
'-jar', | ||
DEFAULT_JAR_FILE, | ||
KEY, | ||
HOST_NAME + ',' + PORT + ',' + SSL_FLAG + ',' + HOST_NAME2 + ',' + PORT2 + ',' + SSL_FLAG2 | ||
] | ||
); | ||
done(); | ||
} | ||
}); | ||
process.emit('mock:child_process:stdout:data', 'monkey----- Press Ctrl-C to exit ----monkey'); | ||
}); | ||
it('should use the specified jar file', function (done) { | ||
spawnSpy.reset(); | ||
var browserStackTunnel = new bs.BrowserStackTunnel({ | ||
key: KEY, | ||
hosts: [{ | ||
name: HOST_NAME, | ||
port: PORT, | ||
sslFlag: SSL_FLAG, | ||
tunnelIdentifier: 'my_tunnel' | ||
}], | ||
jarFile: VALID_JAR_FILE | ||
}); | ||
browserStackTunnel.start(function (error) { | ||
if (error) { | ||
expect().fail(function () { return error; }); | ||
} else if (browserStackTunnel.state === 'started') { | ||
sinon.assert.calledOnce(spawnSpy); | ||
sinon.assert.calledWithExactly( | ||
spawnSpy, | ||
'java', [ | ||
'-jar', | ||
VALID_JAR_FILE, | ||
KEY, | ||
HOST_NAME + ',' + PORT + ',' + SSL_FLAG | ||
] | ||
); | ||
done(); | ||
} | ||
}); | ||
process.emit('mock:child_process:stdout:data', 'monkey----- Press Ctrl-C to exit ----monkey'); | ||
}); | ||
it('should support the tunnelIdentifier option', function (done) { | ||
spawnSpy.reset(); | ||
var browserStackTunnel = new bs.BrowserStackTunnel({ | ||
key: KEY, | ||
hosts: [{ | ||
name: HOST_NAME, | ||
port: PORT, | ||
sslFlag: SSL_FLAG | ||
}], | ||
tunnelIdentifier: 'my_tunnel' | ||
}); | ||
browserStackTunnel.start(function (error) { | ||
if (error) { | ||
expect().fail(function () { return error; }); | ||
} else if (browserStackTunnel.state === 'started') { | ||
sinon.assert.calledOnce(spawnSpy); | ||
sinon.assert.calledWithExactly( | ||
spawnSpy, | ||
'java', [ | ||
'-jar', | ||
DEFAULT_JAR_FILE, | ||
KEY, | ||
HOST_NAME + ',' + PORT + ',' + SSL_FLAG, | ||
'-tunnelIdentifier', | ||
'my_tunnel' | ||
] | ||
); | ||
done(); | ||
} | ||
}); | ||
process.emit('mock:child_process:stdout:data', 'monkey----- Press Ctrl-C to exit ----monkey'); | ||
}); | ||
it('should support the skipCheck option', function (done) { | ||
spawnSpy.reset(); | ||
var browserStackTunnel = new bs.BrowserStackTunnel({ | ||
key: KEY, | ||
hosts: [{ | ||
name: HOST_NAME, | ||
port: PORT, | ||
sslFlag: SSL_FLAG | ||
}], | ||
skipCheck: true | ||
}); | ||
browserStackTunnel.start(function (error) { | ||
if (error) { | ||
expect().fail(function () { return error; }); | ||
} else if (browserStackTunnel.state === 'started') { | ||
sinon.assert.calledOnce(spawnSpy); | ||
sinon.assert.calledWithExactly( | ||
spawnSpy, | ||
'java', [ | ||
'-jar', | ||
DEFAULT_JAR_FILE, | ||
KEY, | ||
HOST_NAME + ',' + PORT + ',' + SSL_FLAG, | ||
'-skipCheck' | ||
] | ||
); | ||
done(); | ||
} | ||
}); | ||
process.emit('mock:child_process:stdout:data', 'monkey----- Press Ctrl-C to exit ----monkey'); | ||
}); | ||
after(function () { | ||
process.removeAllListeners('mock:child_process:stdout:data'); | ||
process.removeAllListeners('mock:child_process:stderr:data'); | ||
process.removeAllListeners('mock:child_process:error'); | ||
process.removeAllListeners('mock:child_process:exit'); | ||
childProcessMock.cleanUp(); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
299593
542
8
61