Skip to content

Commit

Permalink
customize proxy protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
maychen committed Dec 25, 2017
1 parent 1518f32 commit e279efa
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
9 changes: 5 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ async function getValidPort (port) {
}

// API
async function createTestCafe (hostname, port1, port2) {
[hostname, port1, port2] = await Promise.all([
async function createTestCafe (hostname, port1, port2, protocol) {
[hostname, port1, port2, protocol] = await Promise.all([
getValidHostname(hostname),
getValidPort(port1),
getValidPort(port2)
getValidPort(port2),
protocol
]);

var testcafe = new TestCafe(hostname, port1, port2);
var testcafe = new TestCafe(hostname, port1, port2, protocol);

setupExitHook(cb => testcafe.close().then(cb));

Expand Down
4 changes: 2 additions & 2 deletions src/testcafe.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ const FAVICON = read('./client/ui/favicon.ico', true);


export default class TestCafe {
constructor (hostname, port1, port2) {
constructor (hostname, port1, port2, protocol) {
this.closed = false;
this.proxy = new Proxy(hostname, port1, port2);
this.proxy = new Proxy(hostname, port1, port2, protocol);
this.browserConnectionGateway = new BrowserConnectionGateway(this.proxy);
this.runners = [];

Expand Down
19 changes: 17 additions & 2 deletions test/server/create-testcafe-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ describe('TestCafe factory function', function () {
var testCafe = null;
var server = null;

function getTestCafe (hostname, port1, port2) {
return createTestCafe(hostname, port1, port2)
function getTestCafe (hostname, port1, port2, protocol) {
return createTestCafe(hostname, port1, port2, protocol)
.then(function (tc) {
testCafe = tc;
});
Expand Down Expand Up @@ -58,6 +58,21 @@ describe('TestCafe factory function', function () {
});
});

it('Should accept custom ports, hostname and protocol', function () {
return getTestCafe('localhost', 1338, 1339, 'https')
.then(function () {
return testCafe.createBrowserConnection();
})
.then(function (bc) {
var bcUrl = url.parse(bc.url);
var port = parseInt(bcUrl.port, 10);

expect(bcUrl.hostname).eql('localhost');
expect(bcUrl.protocol).eql('https:');
expect(port).eql(1338);
});
});

it('Should raise error if specified port is not free', function () {
var serverListen = new Promise(function (resolve) {
server = net.createServer();
Expand Down

0 comments on commit e279efa

Please sign in to comment.