Skip to content

Commit 6c1b658

Browse files
committed
Tests added for CLI
1 parent 843c2cf commit 6c1b658

File tree

2 files changed

+50
-6
lines changed

2 files changed

+50
-6
lines changed

bin/runner.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ try {
6969
}
7070

7171
// extract a path to file to store tunnel pid
72-
if(yargs['pid']) {
73-
if(yargs['pid'].length > 0) {
74-
config.tunnel_pid_file = yargs['pid'];
72+
if(yargs.hasOwnProperty('pid')) {
73+
if(yargs['pid'].trim().length > 0) {
74+
config.tunnel_pid_file = yargs['pid'].trim();
7575
} else {
76-
console.error('Error while parsing flag --pid. Usage: --pid=/path/to/file');
76+
throw new Error('Empty pid file path');
7777
}
7878
}
7979

@@ -84,7 +84,13 @@ if(yargs['browsers']) {
8484
return yargs['browsers'].indexOf(browser['cli_key']) !== -1;
8585
});
8686
} else {
87-
console.error('No browser keys specified. Usage --browsers <key1> <key2> ...');
87+
throw new Error('No browser keys specified. Usage --browsers <key1> <key2> ...');
88+
}
89+
if(config.browsers.length === 0) {
90+
throw new Error('Invalid browser keys');
91+
}
92+
if(config.browsers.length < yargs['browsers'].length) {
93+
console.warn('Some browser keys not present in config file.');
8894
}
8995
}
9096

tests/behaviour/runner.js

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ var assert = require('assert'),
77
path = require('path'),
88
http = require('http'),
99
browserstackRunner = require('../../bin/cli.js'),
10-
Tunnel = require('../../lib/local.js').Tunnel;
10+
Tunnel = require('../../lib/local.js').Tunnel,
11+
exec = require('child_process').exec,
12+
execSync = require('child_process').execSync;
1113

1214
var getBaseConfig = function() {
1315
return {
@@ -219,3 +221,39 @@ describe('Pass/Fail reporting', function() {
219221
});
220222
});
221223
});
224+
225+
describe('Command Line Interface Tests', function() {
226+
this.timeout(0);
227+
it('Should run with valid CLI arguments', function(done) {
228+
execSync('bin/runner.js init');
229+
exec('bin/runner.js --browsers 1 --path tests/behaviour/resources/qunit_sample.html', null, function(error, stdout, stderr) {
230+
assert.equal(error, null);
231+
done();
232+
});
233+
});
234+
it('Should raise errors if all invalid browser keys.', function(done) {
235+
exec('bin/runner.js --browsers 10 --path tests/behaviour/resources/qunit_sample.html', null, function(error, stdout, stderr) {
236+
assert.notEqual(error.message.match('Invalid'), null);
237+
done();
238+
});
239+
});
240+
it('Should raise error if invalid test path', function(done) {
241+
exec('bin/runner.js --browsers 1 --path invalid/path', function(error, stdout, stderr) {
242+
assert.notEqual(error, null);
243+
assert.notEqual(error.message.match('Invalid'), null);
244+
done();
245+
});
246+
});
247+
it('Should run tests on browsers present if some keys not present', function(done) {
248+
exec('bin/runner.js --browsers 1 10 --path tests/behaviour/resources/qunit_sample.html', null, function(error, stdout, stderr) {
249+
assert.equal(error, null);
250+
done();
251+
});
252+
});
253+
it('Should raise error if empty pid path with pid parameter', function(done) {
254+
exec('bin/runner.js --browsers 1 --path tests/behaviour/resources/qunit_sample.html --pid', null, function(error, stdout, stderr) {
255+
assert.notEqual(error, null);
256+
done();
257+
});
258+
});
259+
});

0 commit comments

Comments
 (0)