Skip to content

Commit 9495f60

Browse files
Adding --pid to README.md
* Renaming config.tunnel_pid to config.tunnel_pid_file * Regex match for --pid instead of -pid * Error message on invalid flag
1 parent 3088545 commit 9495f60

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ To run browser tests on BrowserStack infrastructure, you need to create a `brows
174174
* `build`: A string to identify your test run in Browserstack. In `TRAVIS` setup `TRAVIS_COMMIT` will be the default identifier.
175175
* `proxy`: Specify a proxy to use for the local tunnel. Object with `host`, `port`, `username` and `password` properties.
176176
* `exit_with_fail`: If set to true the cli process will exit with fail if any of the tests failed. Useful for automatic build systems.
177-
* `tunnel_pid`: Specify a path to file to save the tunnel process id into.
177+
* `tunnel_pid_file`: Specify a path to file to save the tunnel process id into. Can also by specified using the `--pid` flag while launching browserstack-runner from the command line.
178178

179179
A sample configuration file:
180180

bin/runner.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,15 @@ try {
3737
}
3838

3939
// extract a path to file to store tunnel pid
40-
var matches, pid = process.argv.find(function (param) { return param.indexOf('--pid') !== -1; });
41-
if (pid && (matches = /-pid=([\w\/\.-]+)/g.exec(pid))) {
42-
config.tunnel_pid = matches[1];
40+
var pid = process.argv.find(function (param) { return param.indexOf('--pid') !== -1; });
41+
42+
if (pid) {
43+
var extracted_path = /--pid=([\w\/\.-]+)/g.exec(pid);
44+
if (extracted_path) {
45+
config.tunnel_pid_file = extracted_path[1];
46+
} else {
47+
console.error('Error while parsing flag --pid. Usage: --pid=/path/to/file');
48+
}
4349
}
4450

4551
var runner = require('./cli.js');

lib/local.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ var Tunnel = function Tunnel(key, port, uniqueIdentifier, config, callback) {
5757
}
5858
});
5959

60-
if (config.tunnel_pid) {
61-
utils.mkdirp(path.dirname(config.tunnel_pid));
62-
fs.writeFile(config.tunnel_pid, subProcess.pid);
60+
if (config.tunnel_pid_file) {
61+
utils.mkdirp(path.dirname(config.tunnel_pid_file));
62+
fs.writeFile(config.tunnel_pid_file, subProcess.pid);
6363
}
6464

6565
that.process = subProcess;
@@ -107,8 +107,8 @@ var Tunnel = function Tunnel(key, port, uniqueIdentifier, config, callback) {
107107
} catch (e) {
108108
logger.debug('[%s] failed to kill process:', new Date(), e);
109109
} finally {
110-
if (config.tunnel_pid) {
111-
fs.unlink(config.tunnel_pid, function () {});
110+
if (config.tunnel_pid_file) {
111+
fs.unlink(config.tunnel_pid_file, function () {});
112112
}
113113
}
114114
}

0 commit comments

Comments
 (0)