Skip to content

Commit e9459e2

Browse files
committed
added custom arg support
1 parent f9ae74f commit e9459e2

File tree

3 files changed

+64
-36
lines changed

3 files changed

+64
-36
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var browserstack = require('browserstack-local');
1919
var bs_local = new browserstack.Local();
2020
2121
# replace <browserstack-accesskey> with your key. You can also set an environment variable - "BROWSERSTACK_ACCESS_KEY".
22-
var bs_local_args = { '-key': '<browserstack-accesskey>' };
22+
var bs_local_args = { 'key': '<browserstack-accesskey>' };
2323
2424
# starts the Local instance with the required arguments
2525
bs_local.start(bs_local_args, function() {
@@ -43,7 +43,7 @@ Apart from the key, all other BrowserStack Local modifiers are optional. For the
4343
#### Verbose Logging
4444
To enable verbose logging -
4545
```
46-
bs_local_args = { '-key': '<browserstack-accesskey>', 'v': 'true' }
46+
bs_local_args = { 'key': '<browserstack-accesskey>', 'v': 'true' }
4747
```
4848

4949
#### Folder Testing

lib/Local.js

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ function Local(){
1111
this.key = process.env.BROWSERSTACK_ACCESS_KEY;
1212
this.logfile = path.join(process.cwd(), 'local.log');
1313
this.exitCallback;
14+
this.userArgs = [];
1415

1516
this.errorRegex = /\*\*\* Error: [^\r\n]*/i;
1617
this.doneRegex = /Press Ctrl-C to exit/i;
@@ -81,88 +82,94 @@ function Local(){
8182
var value = options[key];
8283

8384
switch(key){
84-
case '-key':
85+
case 'key':
8586
this.key = value;
8687
break;
8788

88-
case '-v':
89+
case 'v':
8990
if(value)
9091
this.verboseFlag = '-vvv';
9192
break;
9293

93-
case '-force':
94+
case 'force':
9495
if(value)
9596
this.forceFlag = '-force';
9697
break;
9798

98-
case '-only':
99+
case 'only':
99100
if(value)
100101
this.onlyFlag = '-only';
101102
break;
102103

103-
case '-onlyAutomate':
104+
case 'onlyAutomate':
104105
if(value)
105106
this.onlyAutomateFlag = '-onlyAutomate';
106107
break;
107108

108-
case '-forcelocal':
109+
case 'forcelocal':
109110
if(value)
110111
this.forceLocalFlag = '-forcelocal';
111112
break;
112113

113-
case '-localIdentifier':
114+
case 'localIdentifier':
114115
if(value)
115116
this.localIdentifierFlag = '-localIdentifier ' + value;
116117
break;
117118

118-
case '-f':
119+
case 'f':
119120
if(value){
120121
this.folderFlag = '-f';
121122
this.folderPath = value;
122123
}
123124
break;
124125

125-
case '-proxyHost':
126+
case 'proxyHost':
126127
if(value)
127128
this.proxyHost = '-proxyHost ' + value;
128129
break;
129130

130-
case '-proxyPort':
131+
case 'proxyPort':
131132
if(value)
132133
this.proxyPort = '-proxyPort ' + value;
133134
break;
134135

135-
case '-proxyUser':
136+
case 'proxyUser':
136137
if(value)
137138
this.proxyUser = '-proxyUser ' + value;
138139
break;
139140

140-
case '-proxyPass':
141+
case 'proxyPass':
141142
if(value)
142143
this.proxyPass = '-proxyPass ' + value;
143144
break;
144145

145-
case '-forceproxy':
146+
case 'forceproxy':
146147
if(value)
147148
this.forceProxyFlag = '-forceproxy';
148149
break;
149150

150-
case '-hosts':
151+
case 'hosts':
151152
if(value)
152153
this.hosts = value;
153154
break;
154155

155-
case '-logfile':
156+
case 'logfile':
156157
if(value)
157158
this.logfile = value;
158159
break;
159160

160-
case '-binarypath':
161+
case 'binarypath':
161162
if(value)
162163
this.binaryPath = value;
163164
break;
164165

165166
default:
167+
if(value.toString().toLowerCase() == 'true'){
168+
this.userArgs.push('-' + key);
169+
} else {
170+
this.userArgs.push('-' + key);
171+
this.userArgs.push(value);
172+
}
166173
break;
167174
}
168175
}
@@ -208,6 +215,9 @@ function Local(){
208215
args.push(this.verboseFlag);
209216
if(this.hosts)
210217
args.push(this.hosts);
218+
for(var i in this.userArgs){
219+
args.push(this.userArgs[i]);
220+
}
211221
return args;
212222
};
213223
}

test/local.js

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('Local', function () {
1212

1313
it('should have pid when running', function (done) {
1414
this.timeout(600000);
15-
bsLocal.start({ '-key': process.env.BROWSERSTACK_ACCESS_KEY }, function(){
15+
bsLocal.start({ 'key': process.env.BROWSERSTACK_ACCESS_KEY }, function(){
1616
expect(bsLocal.tunnel.pid).to.not.equal(0);
1717
done();
1818
});
@@ -21,19 +21,19 @@ describe('Local', function () {
2121
it('should return is running properly', function (done) {
2222
this.timeout(60000);
2323
expect(bsLocal.isRunning()).to.not.equal(true);
24-
bsLocal.start({ '-key': process.env.BROWSERSTACK_ACCESS_KEY }, function(){
24+
bsLocal.start({ 'key': process.env.BROWSERSTACK_ACCESS_KEY }, function(){
2525
expect(bsLocal.isRunning()).to.equal(true);
2626
done();
2727
});
2828
});
2929

3030
it('should throw error on running multiple binary', function (done) {
3131
this.timeout(60000);
32-
bsLocal.start({ '-key': process.env.BROWSERSTACK_ACCESS_KEY }, function(){
32+
bsLocal.start({ 'key': process.env.BROWSERSTACK_ACCESS_KEY }, function(){
3333
bsLocal_2 = new browserstack.Local();
3434
var tempLogPath = path.join(process.cwd(), 'log2.log');
3535
try{
36-
bsLocal_2.start({ '-key': process.env.BROWSERSTACK_ACCESS_KEY, '-logfile': tempLogPath }, function(){});
36+
bsLocal_2.start({ 'key': process.env.BROWSERSTACK_ACCESS_KEY, 'logfile': tempLogPath }, function(){});
3737
}
3838
catch(err){
3939
expect(err.toString().trim()).to.equal('LocalError: *** Error: Either another browserstack local client is running on your machine or some server is listening on port 45691');
@@ -44,71 +44,89 @@ describe('Local', function () {
4444
});
4545

4646
it('should enable verbose', function (done) {
47-
bsLocal.start({ '-key': process.env.BROWSERSTACK_ACCESS_KEY, onlyCommand: true, '-v': true }, function(){
47+
bsLocal.start({ 'key': process.env.BROWSERSTACK_ACCESS_KEY, onlyCommand: true, 'v': true }, function(){
4848
expect(bsLocal.getBinaryArgs().indexOf('-vvv')).to.not.equal(-1);
4949
done();
5050
});
5151
});
5252

5353
it('should set folder testing', function (done) {
54-
bsLocal.start({ '-key': process.env.BROWSERSTACK_ACCESS_KEY, onlyCommand: true, '-f': '/var/html' }, function(){
54+
bsLocal.start({ 'key': process.env.BROWSERSTACK_ACCESS_KEY, onlyCommand: true, 'f': '/var/html' }, function(){
5555
expect(bsLocal.getBinaryArgs().indexOf('-f')).to.not.equal(-1);
5656
expect(bsLocal.getBinaryArgs().indexOf('/var/html')).to.not.equal(-1);
5757
done();
5858
});
5959
});
6060

6161
it('should enable force', function (done) {
62-
bsLocal.start({ '-key': process.env.BROWSERSTACK_ACCESS_KEY, onlyCommand: true, '-force': true }, function(){
62+
bsLocal.start({ 'key': process.env.BROWSERSTACK_ACCESS_KEY, onlyCommand: true, 'force': true }, function(){
6363
expect(bsLocal.getBinaryArgs().indexOf('-force')).to.not.equal(-1);
6464
done();
6565
});
6666
});
6767

6868
it('should enable only', function (done) {
69-
bsLocal.start({ '-key': process.env.BROWSERSTACK_ACCESS_KEY, onlyCommand: true, '-only': true }, function(){
69+
bsLocal.start({ 'key': process.env.BROWSERSTACK_ACCESS_KEY, onlyCommand: true, 'only': true }, function(){
7070
expect(bsLocal.getBinaryArgs().indexOf('-only')).to.not.equal(-1);
7171
done();
7272
});
7373
});
7474

7575
it('should enable onlyAutomate', function (done) {
76-
bsLocal.start({ '-key': process.env.BROWSERSTACK_ACCESS_KEY, onlyCommand: true, '-onlyAutomate': true }, function(){
76+
bsLocal.start({ 'key': process.env.BROWSERSTACK_ACCESS_KEY, onlyCommand: true, 'onlyAutomate': true }, function(){
7777
expect(bsLocal.getBinaryArgs().indexOf('-onlyAutomate')).to.not.equal(-1);
7878
done();
7979
});
8080
});
8181

8282
it('should enable forcelocal', function (done) {
83-
bsLocal.start({ '-key': process.env.BROWSERSTACK_ACCESS_KEY, onlyCommand: true, '-forcelocal': true }, function(){
83+
bsLocal.start({ 'key': process.env.BROWSERSTACK_ACCESS_KEY, onlyCommand: true, 'forcelocal': true }, function(){
8484
expect(bsLocal.getBinaryArgs().indexOf('-forcelocal')).to.not.equal(-1);
8585
done();
8686
});
8787
});
8888

89+
it('should enable custom boolean args', function (done) {
90+
bsLocal.start({ 'key': process.env.BROWSERSTACK_ACCESS_KEY, onlyCommand: true, 'boolArg1': true, 'boolArg2': true }, function(){
91+
expect(bsLocal.getBinaryArgs().indexOf('-boolArg1')).to.not.equal(-1);
92+
expect(bsLocal.getBinaryArgs().indexOf('-boolArg2')).to.not.equal(-1);
93+
done();
94+
});
95+
});
96+
97+
it('should enable custom keyval args', function (done) {
98+
bsLocal.start({ 'key': process.env.BROWSERSTACK_ACCESS_KEY, onlyCommand: true, 'customKey1': 'custom value1', 'customKey2': 'custom value2' }, function(){
99+
expect(bsLocal.getBinaryArgs().indexOf('-customKey1')).to.not.equal(-1);
100+
expect(bsLocal.getBinaryArgs().indexOf('custom value1')).to.not.equal(-1);
101+
expect(bsLocal.getBinaryArgs().indexOf('-customKey2')).to.not.equal(-1);
102+
expect(bsLocal.getBinaryArgs().indexOf('custom value2')).to.not.equal(-1);
103+
done();
104+
});
105+
});
106+
89107
it('should enable forceproxy', function (done) {
90-
bsLocal.start({ '-key': process.env.BROWSERSTACK_ACCESS_KEY, onlyCommand: true, '-forceproxy': true }, function(){
108+
bsLocal.start({ 'key': process.env.BROWSERSTACK_ACCESS_KEY, onlyCommand: true, 'forceproxy': true }, function(){
91109
expect(bsLocal.getBinaryArgs().indexOf('-forceproxy')).to.not.equal(-1);
92110
done();
93111
});
94112
});
95113

96114

97115
it('should set localIdentifier', function (done) {
98-
bsLocal.start({ '-key': process.env.BROWSERSTACK_ACCESS_KEY, onlyCommand: true, '-localIdentifier': 'abcdef' }, function(){
116+
bsLocal.start({ 'key': process.env.BROWSERSTACK_ACCESS_KEY, onlyCommand: true, 'localIdentifier': 'abcdef' }, function(){
99117
expect(bsLocal.getBinaryArgs().indexOf('-localIdentifier abcdef')).to.not.equal(-1);
100118
done();
101119
});
102120
});
103121

104122
it('should set proxy', function (done) {
105123
bsLocal.start({
106-
'-key': process.env.BROWSERSTACK_ACCESS_KEY,
124+
'key': process.env.BROWSERSTACK_ACCESS_KEY,
107125
onlyCommand: true,
108-
'-proxyHost': 'localhost',
109-
'-proxyPort': 8080,
110-
'-proxyUser': 'user',
111-
'-proxyPass': 'pass'
126+
'proxyHost': 'localhost',
127+
'proxyPort': 8080,
128+
'proxyUser': 'user',
129+
'proxyPass': 'pass'
112130
}, function(){
113131
expect(bsLocal.getBinaryArgs().indexOf('-proxyHost localhost')).to.not.equal(-1);
114132
expect(bsLocal.getBinaryArgs().indexOf('-proxyPort 8080')).to.not.equal(-1);
@@ -119,7 +137,7 @@ describe('Local', function () {
119137
});
120138

121139
it('should set hosts', function (done) {
122-
bsLocal.start({ '-key': process.env.BROWSERSTACK_ACCESS_KEY, onlyCommand: true, '-hosts': 'localhost,8000,0' }, function(){
140+
bsLocal.start({ 'key': process.env.BROWSERSTACK_ACCESS_KEY, onlyCommand: true, 'hosts': 'localhost,8000,0' }, function(){
123141
expect(bsLocal.getBinaryArgs().indexOf('localhost,8000,0')).to.not.equal(-1);
124142
done();
125143
});

0 commit comments

Comments
 (0)