Skip to content
This repository has been archived by the owner on Oct 10, 2021. It is now read-only.

Commit

Permalink
Merge pull request #323 from vweevers/custom-loopback-hostname
Browse files Browse the repository at this point in the history
Support custom loopback hostname
  • Loading branch information
vvo committed May 31, 2018
2 parents 060d991 + 4c5d666 commit 79693fa
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 8 deletions.
2 changes: 2 additions & 0 deletions bin/zuul
Expand Up @@ -27,6 +27,7 @@ program
.option('--electron', 'run tests in electron. electron must be installed separately.')
.option('--tunnel-host <host url>', 'specify a localtunnel server to use for forwarding')
.option('--sauce-connect [tunnel-identifier]', 'use saucelabs with sauce connect instead of localtunnel. Optionally specify the tunnel-identifier')
.option('--loopback <host name>', 'hostname to use instead of localhost, to accomodate Safari and Edge with Sauce Connect. Must resolve to 127.0.0.1')
.option('--server <the server script>', 'specify a server script to be run')
.option('--list-available-browsers', 'list available browsers and versions')
.option('--browser-name <browser name>', 'specficy the browser name to test an individual browser')
Expand All @@ -52,6 +53,7 @@ var config = {
prj_dir: process.cwd(),
tunnel_host: program.tunnelHost,
sauce_connect: program.sauceConnect,
loopback: program.loopback,
server: program.server,
concurrency: program.concurrency,
coverage: program.coverage,
Expand Down
2 changes: 1 addition & 1 deletion lib/SauceBrowser.js
Expand Up @@ -52,7 +52,7 @@ SauceBrowser.prototype.start = function() {
return self.shutdown(err);
}

self.emit('init', conf);
self.emit('init', conf, url);

var init_conf = xtend({
build: conf.build,
Expand Down
27 changes: 20 additions & 7 deletions lib/setup.js
Expand Up @@ -12,18 +12,22 @@ function setup_test_instance(opt, cb) {
var support_server = undefined;
var bouncer = undefined;
var Tunnel;
var tunnel;

if (typeof opt.tunnel === 'string') {
Tunnel = require('zuul-' + opt.tunnel);
debug('using zuul-%s to tunnel', opt.tunnel);
} else if (typeof opt.tunnel === 'object' && opt.tunnel.type) {
Tunnel = require('zuul-' + opt.tunnel.type);
debug('using zuul-%s to tunnel', opt.tunnel.type);
} else {
} else if (opt.tunnel !== false) {
Tunnel = require('zuul-localtunnel');
debug('using zuul-localhost to tunnel');
}

var tunnel = new Tunnel(opt);
if (Tunnel) {
tunnel = new Tunnel(opt);
}

if (opt.server) {
user_server(opt.server, setup);
Expand All @@ -35,6 +39,7 @@ function setup_test_instance(opt, cb) {
function setup(_support_server) {
support_server = _support_server;
var config = opt;
var loopback = config.loopback || 'localhost';
var control_port = opt.control_port;

var support_port = undefined;
Expand All @@ -61,16 +66,21 @@ function setup_test_instance(opt, cb) {
bouncer.on('request', on_request(proxy.web));
bouncer.on('upgrade', on_request(proxy.ws));

function local_url (port, path) {
var base = 'http://' + loopback + ':' + port;
return path ? base + path : base;
}

function on_request(bounce) {
return function(req, res) {
var args = [].slice.call(arguments);
if (is_control_req(req)) {
args.push({ target: 'http://localhost:' + control_port });
args.push({ target: local_url(control_port) });
bounce.apply(proxy, args);
return;
}

args.push({ target: 'http://localhost:' + support_port }, on_support_server_proxy_done);
args.push({ target: local_url(support_port) }, on_support_server_proxy_done);
bounce.apply(proxy, args);
};
}
Expand Down Expand Up @@ -99,8 +109,8 @@ function setup_test_instance(opt, cb) {
var app_port = bouncer.address().port;
debug('bouncer active on port %d', app_port);

if (!config.tunnel) {
return cb(null, 'http://localhost:' + app_port + '/__zuul');
if (!tunnel) {
return cb(null, local_url(app_port, '/__zuul'));
}

tunnel.connect(app_port, cb);
Expand All @@ -109,7 +119,10 @@ function setup_test_instance(opt, cb) {

function shutdown() {
bouncer.close();
tunnel.close();

if (tunnel) {
tunnel.close();
}

if (support_server) {
support_server.process.kill('SIGKILL');
Expand Down
74 changes: 74 additions & 0 deletions test/integration/sauce-connect-loopback.js
@@ -0,0 +1,74 @@
var Zuul = require('../../');

var auth = require('../auth');
var assert = require('assert');
var URL = require('url');

test('sauce connect without loopback option', function(done) {
var config = {
ui: 'mocha-bdd',
sauce_connect: true,
username: auth.username,
key: auth.key
};

var zuul = Zuul(config);

zuul.browser({
name: 'internet explorer',
version: '11'
});

var browser = zuul._browsers[0];

browser.on('init', function(browserConfig, url) {
assert.equal(zuul._config.sauce_connect, true)
assert.equal(zuul._config.tunnel, false)
assert.equal(URL.parse(url).hostname, 'localhost')

browser.shutdown();
});

browser.on('done', function(/*stats*/) {
done();
});

browser.on('error', done);

browser.start();
});

test('sauce connect with loopback option', function(done) {
var config = {
ui: 'mocha-bdd',
sauce_connect: true,
loopback: 'test.local',
username: auth.username,
key: auth.key
};

var zuul = Zuul(config);

zuul.browser({
name: 'internet explorer',
version: '11'
});

var browser = zuul._browsers[0];

browser.on('init', function(browserConfig, url) {
assert.equal(zuul._config.sauce_connect, true)
assert.equal(zuul._config.tunnel, false)
assert.equal(URL.parse(url).hostname, 'test.local')

browser.shutdown();
});

browser.on('done', function(/*stats*/) {
done();
});

browser.on('error', done);

browser.start();
});

0 comments on commit 79693fa

Please sign in to comment.