Skip to content

Commit

Permalink
run testcafe with https protocol (DevExpress#1985)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Kalinin authored and intermike committed May 5, 2018
1 parent 3b13bc0 commit 51ccc0b
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 5 deletions.
18 changes: 18 additions & 0 deletions src/cli/argument-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { assertType, is } from '../errors/runtime/type-assertions';
import getViewPortWidth from '../utils/get-viewport-width';
import { wordWrap, splitQuotedText } from '../utils/string';
import { stat, ensureDir } from '../utils/promisified-functions';
import fs from 'fs';


const REMOTE_ALIAS_RE = /^remote(?::(\d*))?$/;
Expand Down Expand Up @@ -106,6 +107,8 @@ export default class CLIArgumentParser {
.option('--speed <factor>', 'set the speed of test execution (0.01 ... 1)')
.option('--ports <port1,port2>', 'specify custom port numbers')
.option('--hostname <name>', 'specify the hostname')
.option('--ssl', 'enable HTTPS for the proxy server')
.option('--certificate <key,crt>', 'specify SSL certificate files')
.option('--proxy <host>', 'specify the host of the proxy server')
.option('--proxy-bypass <rules>', 'specify a comma-separated list of rules that define URLs accessed bypassing the proxy server')
.option('--qr-code', 'outputs QR-code that repeats URLs used to connect the remote browsers')
Expand Down Expand Up @@ -202,6 +205,20 @@ export default class CLIArgumentParser {
}
}

_parseCertificate () {
if (this.opts.certificate) {
const parts = this.opts.certificate.split(',');

if (parts.length < 2)
throw new GeneralError(MESSAGE.certificateOptionRequiresTwoPaths);

this.opts.certificate = {
key: fs.readFileSync(resolve(this.cwd, parts[0])),
cert: fs.readFileSync(resolve(this.cwd, parts[1]))
};
}
}

_parseBrowserList () {
var browsersArg = this.program.args[0] || '';

Expand Down Expand Up @@ -317,6 +334,7 @@ export default class CLIArgumentParser {
this._parseAppInitDelay();
this._parseSpeed();
this._parsePorts();
this._parseCertificate();
this._parseBrowserList();
this._parseConcurrency();

Expand Down
8 changes: 7 additions & 1 deletion src/cli/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,15 @@ async function runTests (argParser) {
var externalProxyHost = opts.proxy;
var proxyBypass = opts.proxyBypass;

var options = {
ssl: Boolean(opts.ssl),
key: String(opts.certificate && opts.certificate.key),
cert: String(opts.certificate && opts.certificate.cert),
};

log.showSpinner();

var testCafe = await createTestCafe(opts.hostname, port1, port2);
var testCafe = await createTestCafe(opts.hostname, port1, port2, options);
var concurrency = argParser.concurrency || 1;
var remoteBrowsers = await remotesWizard(testCafe, argParser.remoteCount, opts.qrCode);
var browsers = argParser.browsers.concat(remoteBrowsers);
Expand Down
1 change: 1 addition & 0 deletions src/errors/runtime/message.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ async function getValidPort (port) {
}

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

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

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, options) {
this.closed = false;
this.proxy = new Proxy(hostname, port1, port2);
this.proxy = new Proxy(hostname, port1, port2, options);
this.browserConnectionGateway = new BrowserConnectionGateway(this.proxy);
this.runners = [];

Expand Down
2 changes: 2 additions & 0 deletions test/server/cli-argument-parser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ describe('CLI argument parser', function () {
{ long: '--hostname' },
{ long: '--proxy' },
{ long: '--proxy-bypass' },
{ long: '--ssl' },
{ long: '--certificate' },
{ long: '--qr-code' },
{ long: '--color' },
{ long: '--no-color' }
Expand Down

0 comments on commit 51ccc0b

Please sign in to comment.