| 
									
										
										
										
											2016-10-04 20:39:20 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							| 
									
										
										
										
											2020-05-19 12:08:49 -07:00
										 |  |  |  * Copyright Google LLC All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2016-10-04 20:39:20 -07:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Use of this source code is governed by an MIT-style license that can be | 
					
						
							|  |  |  |  * found in the LICENSE file at https://angular.io/license
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-27 16:09:09 +01:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var fs = require('fs'); | 
					
						
							|  |  |  | var http = require('http'); | 
					
						
							|  |  |  | var BrowserStackTunnel = require('browserstacktunnel-wrapper'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var HOSTNAME = 'localhost'; | 
					
						
							|  |  |  | var PORTS = [9876, 9877]; | 
					
						
							|  |  |  | var ACCESS_KEY = process.env.BROWSER_STACK_ACCESS_KEY; | 
					
						
							|  |  |  | var READY_FILE = process.env.BROWSER_PROVIDER_READY_FILE; | 
					
						
							|  |  |  | var TUNNEL_IDENTIFIER = process.env.TRAVIS_JOB_NUMBER; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // We need to start fake servers, otherwise the tunnel does not start.
 | 
					
						
							|  |  |  | var fakeServers = []; | 
					
						
							|  |  |  | var hosts = []; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PORTS.forEach(function(port) { | 
					
						
							|  |  |  |   fakeServers.push(http.createServer(function() {}).listen(port)); | 
					
						
							| 
									
										
										
										
											2020-05-05 13:12:39 -07:00
										 |  |  |   hosts.push({name: HOSTNAME, port: port, sslFlag: 0}); | 
					
						
							| 
									
										
										
										
											2015-10-27 16:09:09 +01:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-05 13:12:39 -07:00
										 |  |  | var tunnel = | 
					
						
							|  |  |  |     new BrowserStackTunnel({key: ACCESS_KEY, localIdentifier: TUNNEL_IDENTIFIER, hosts: hosts}); | 
					
						
							| 
									
										
										
										
											2015-10-27 16:09:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-02 18:35:30 +01:00
										 |  |  | console.info('Starting tunnel on ports', PORTS.join(', ')); | 
					
						
							| 
									
										
										
										
											2015-10-27 16:09:09 +01:00
										 |  |  | tunnel.start(function(error) { | 
					
						
							|  |  |  |   if (error) { | 
					
						
							|  |  |  |     console.error('Can not establish the tunnel', error); | 
					
						
							|  |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2020-03-02 18:35:30 +01:00
										 |  |  |     console.info('Tunnel established.'); | 
					
						
							| 
									
										
										
										
											2015-10-27 16:09:09 +01:00
										 |  |  |     fakeServers.forEach(function(server) { | 
					
						
							|  |  |  |       server.close(); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (READY_FILE) { | 
					
						
							|  |  |  |       fs.writeFile(READY_FILE, ''); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | tunnel.on('error', function(error) { | 
					
						
							|  |  |  |   console.error(error); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2017-03-02 00:22:24 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // TODO(i): we should properly stop the tunnel when tests are done.
 | 
					
						
							|  |  |  | // tunnel.stop(function(error) {
 | 
					
						
							|  |  |  | //   if (error) {
 | 
					
						
							|  |  |  | //     console.log(error);
 | 
					
						
							|  |  |  | //   } else {
 | 
					
						
							|  |  |  | //     console.log('browserStack tunnel has stopped');
 | 
					
						
							|  |  |  | //   }
 | 
					
						
							|  |  |  | //});
 |