1 | #!/usr/bin/env node
|
2 |
|
3 | /**********************************
|
4 | * Provides a simple tool to open a tunnel to BrowserStack when running browser-srv manually and wanting to do manual testing
|
5 | *
|
6 | * Usage:
|
7 | * manual-tunnel [http ports,split,by,commas] [https ports,split,by,commas]
|
8 | *
|
9 | **********************************/
|
10 |
|
11 | var fs = require('fs'),
|
12 | childProcess = require('child_process'),
|
13 | path = require('path'),
|
14 | config;
|
15 |
|
16 | try {
|
17 | config = JSON.parse(fs.readFileSync(path.normalize(__dirname + '/browser-stack.json')));
|
18 | } catch (e) {
|
19 | console.error('Could not load browser-stack.json configuration. Please ensure the file exists and follows the format in browser-stack.json.example');
|
20 | console.error('Error: ' + e.message);
|
21 | process.exit(1);
|
22 | }
|
23 |
|
24 | var httpTunnelPorts, httpsTunnelPorts;
|
25 |
|
26 | if (!(process.argv[2] || process.argv[3])) {
|
27 | console.warn('You did not specify any ports, we will default to ports commonly used with a simple farm: 8092,8080 over HTTP and 8081 over HTTPS');
|
28 | httpTunnelPorts = ['8092','8080'];
|
29 | httpsTunnelPorts = ['8081'];
|
30 | } else {
|
31 | httpTunnelPorts = (process.argv[2] || '').split(',').filter(function(elem) { return elem != ''; });
|
32 | httpsTunnelPorts = (process.argv[3] || '').split(',').filter(function(elem) { return elem != ''; });
|
33 | }
|
34 |
|
35 | var tunnelHosts = httpTunnelPorts.map(function (e) { return 'localhost.ably.io,' + e + ',0'; }).concat(httpsTunnelPorts.map(function (e) { return 'localhost.ably.io,' + e + ',1'; }))
|
36 | tunnelArgs = ['-jar', path.normalize(__dirname + '/bin/BrowserStackTunnel.jar'), config['credentials']['manual_testing_tunnel_key'],tunnelHosts.join(',')];
|
37 |
|
38 | tunnelProcess = childProcess.spawn('java', tunnelArgs);
|
39 | tunnelProcess.stdout.pipe(process.stdout);
|
40 | tunnelProcess.stderr.pipe(process.stderr);
|
41 | tunnelProcess.on('exit', function(code, signal) {
|
42 | console.error('Tunnel has closed: ' + code + ', ' + signal);
|
43 | process.exit();
|
44 | });
|
45 |
|
46 | console.log('Tunnel opened to BrowserStack for host localhost.ably.io on HTTP ports ' + httpTunnelPorts.join(', ') + ' and HTTPS ports ' + httpsTunnelPorts.join(', '));
|
47 |
|
48 | if (httpTunnelPorts.indexOf('8092') == -1) console.warn('\n! The test server runs on port 8092; did you mean to leave that port out?\n');
|
49 |
|
50 | setInterval(function() {}, 1000); |
\ | No newline at end of file |