Skip to content

Commit

Permalink
test: use & verify dynamic ports for proxy testing
Browse files Browse the repository at this point in the history
  • Loading branch information
dbushong committed Oct 25, 2016
1 parent f345b0d commit 7957cd8
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions test/processes/proxy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,25 @@ describe('Proxy', () => {
it('can generate spawn options', async () => {
const config = new Config({ app: { port: 3041 } });
const options = await Proxy.getOptions(config);
assert.hasType('Finds an open port', Number, options.port);
assert.equal('Uses default port', 4445, options.port);
assert.equal('Passes in the app port as the 2nd param to the child',
'3041', options.commandArgs[1]);
assert.equal(`http://127.0.0.1:${options.port}`, config.get('proxy.targetUrl'));
});

it('can generate remote-selenium spawn options', async () => {
const config = new Config(
{ app: { port: '3041' }, selenium: { serverUrl: 'http://example.com' } }
);
const config = new Config({
app: { port: '3041' },
selenium: { serverUrl: 'http://example.com' },
proxy: { port: '0' },
});
const [options, hostname] = await Bluebird.all([
Proxy.getOptions(config),
cp.execFileAsync('hostname', ['-f'], { encoding: 'utf8' }).call('trim'),
]);
assert.hasType('Finds an open port', Number, options.port);
assert.expect('Port is no longer 0', options.port > 0);
assert.notEqual('Port is not default', 4445, options.port);
assert.equal(`http://${hostname}:${options.port}`,
config.get('proxy.targetUrl'));
});
Expand All @@ -40,6 +45,7 @@ describe('Proxy', () => {
const config = new Config({
root: HELLO_WORLD,
app: { port: '3041' },
proxy: { port: '0' },
});
const { proxy, application } = await spawnServer(config, [Proxy, App]);
proxy.rawProcess.kill();
Expand All @@ -51,7 +57,7 @@ describe('Proxy', () => {
root: HELLO_WORLD,
app: { port: '3041' },
driver: 'wd',
proxy: { tunnel: { host: 'tun-host', port: '4242' } },
proxy: { port: '0', tunnel: { host: 'tun-host', port: '4242' } },
});
const { proxy, application } = await spawnServer(config, [Proxy, App]);
assert.equal('http://tun-host:4242', proxy.launchArguments[3]);
Expand Down

0 comments on commit 7957cd8

Please sign in to comment.