chore: replace occurrences of 'localhost' with '127.0.01'; use random ports; closes
`base-driver` gets a new `helpers` module with a `getTestPort` function; this is now used throughout the tests
`fake-driver` can't use random ports because it depends on `appium-base-driver`'s test suite, and that is _not_ the current appium-2.0-compatible `@appium/base-driver`
MODIFY
packages/appium/test/helpers.js
packages/appium/test/helpers.js
@@ -2,7 +2,7 @@ import path from 'path';
import {insertAppiumPrefixes} from '../lib/utils';
import getPort from 'get-port';
-const TEST_HOST = 'localhost';
+const TEST_HOST = '127.0.0.1';
const fakeDriverPath = path.dirname(require.resolve('@appium/fake-driver/package.json'));
const PROJECT_ROOT = path.join(fakeDriverPath, '..', '..');

MODIFY
packages/base-driver/test/basedriver/driver-e2e-tests.js
packages/base-driver/test/basedriver/driver-e2e-tests.js
@@ -5,7 +5,7 @@ import {
} from '../../lib/constants';
import axios from 'axios';
import B from 'bluebird';
-import getPort from 'get-port';
+import {TEST_HOST, getTestPort} from '../helpers';
import { PREFIXED_APPIUM_OPTS_CAP } from '../../lib/basedriver/capabilities';
function baseDriverE2ETests (DriverClass, defaultCaps = {}) {
@@ -15,15 +15,18 @@ function baseDriverE2ETests (DriverClass, defaultCaps = {}) {
describe(`BaseDriver E2E (as ${className})`, function () {
let baseServer, d;
+
before(async function () {
- port = port ?? await getPort();
+ port = port ?? await getTestPort();
defaultCaps = {...defaultCaps, 'appium:port': port};
d = new DriverClass({port, address});
baseServer = await server({
routeConfiguringFunction: routeConfiguringFunction(d),
- port
+ port,
+ hostname: TEST_HOST
});
});
+
after(async function () {
await baseServer.close();
});

MODIFY
packages/base-driver/test/basedriver/helpers-e2e-specs.js
packages/base-driver/test/basedriver/helpers-e2e-specs.js
@@ -7,7 +7,7 @@ import finalhandler from 'finalhandler';
import serveStatic from 'serve-static';
import contentDisposition from 'content-disposition';
import B from 'bluebird';
-
+import {TEST_HOST, getTestPort} from '../helpers';
function getFixture (file) {
@@ -54,8 +54,13 @@ describe('app download and configuration', function () {
.should.be.rejectedWith(/did not have extension/);
});
describe('should download an app from the web', function () {
- const port = 8000;
- const serverUrl = `http://localhost:${port}`;
+ let port;
+ let serverUrl;
+
+ before(async function () {
+ port = await getTestPort(true);
+ serverUrl = `http://${TEST_HOST}:${port}`;
+ });
describe('server not available', function () {
it('should handle server not available', async function () {
@@ -142,7 +147,7 @@ describe('app download and configuration', function () {
it('should handle invalid protocol', async function () {
await configureApp('file://C:/missing/FakeIOSApp.app.zip', '.app')
.should.eventually.be.rejectedWith(/is not supported/);
- await configureApp('ftp://localhost:8000/missing/FakeIOSApp.app.zip', '.app')
+ await configureApp(`ftp://${TEST_HOST}:${port}/missing/FakeIOSApp.app.zip`, '.app')
.should.eventually.be.rejectedWith(/is not supported/);
});
it('should handle missing file in Windows path format', async function () {

MODIFY
packages/base-driver/test/basedriver/websockets-e2e-specs.js
packages/base-driver/test/basedriver/websockets-e2e-specs.js
@@ -4,23 +4,23 @@ import { server, routeConfiguringFunction,
import { FakeDriver } from '../protocol/fake-driver';
import WebSocket from 'ws';
import B from 'bluebird';
-import getPort from 'get-port';
+import {TEST_HOST, getTestPort} from '../helpers';
describe('Websockets (e2e)', function () {
let baseServer;
let driver;
+ let port;
const SESSION_ID = 'foo';
const WS_DATA = 'Hello';
- let PORT;
before(async function () {
driver = new FakeDriver();
driver.sessionId = SESSION_ID;
- PORT = await getPort();
+ port = await getTestPort();
baseServer = await server({
routeConfiguringFunction: routeConfiguringFunction(driver),
- port: PORT,
+ port,
});
});
after(async function () {
@@ -44,7 +44,7 @@ describe('Websockets (e2e)', function () {
baseServer.listenerCount('upgrade').should.be.above(previousListenerCount);
_.keys(await baseServer.getWebSocketHandlers()).length.should.eql(1);
await new B((resolve, reject) => {
- const client = new WebSocket(`ws://localhost:${PORT}${endpoint}`);
+ const client = new WebSocket(`ws://${TEST_HOST}:${port}${endpoint}`);
client.on('connection', (ws, req) => {
ws.should.not.be.empty;
req.connection.remoteAddress.should.not.be.empty;
@@ -61,7 +61,7 @@ describe('Websockets (e2e)', function () {
(await baseServer.removeWebSocketHandler(endpoint)).should.be.true;
_.keys(await baseServer.getWebSocketHandlers()).length.should.eql(0);
await new B((resolve, reject) => {
- const client = new WebSocket(`ws://localhost:${PORT}${endpoint}`);
+ const client = new WebSocket(`ws://${TEST_HOST}:${port}${endpoint}`);
client.on('message', (data) =>
reject(new Error(`No websocket messages are expected after the handler ` +
`has been removed. '${data}' is received instead. `))

MODIFY
packages/base-driver/test/express/server-e2e-specs.js
packages/base-driver/test/express/server-e2e-specs.js
@@ -5,7 +5,7 @@ import axios from 'axios';
import sinon from 'sinon';
import B from 'bluebird';
import _ from 'lodash';
-import getPort from 'get-port';
+import {TEST_HOST, getTestPort} from '../helpers';
describe('server', function () {
@@ -13,7 +13,7 @@ describe('server', function () {
let errorStub;
let port;
before(async function () {
- port = await getPort();
+ port = await getTestPort(true);
errorStub = sinon.stub(console, 'error');
function configureRoutes (app) {
app.get('/', (req, res) => {
@@ -43,12 +43,12 @@ describe('server', function () {
});
it('should start up with our middleware', async function () {
- const {data} = await axios.get(`http://localhost:${port}/`);
+ const {data} = await axios.get(`http://${TEST_HOST}:${port}/`);
data.should.eql('Hello World!');
});
it('should fix broken context type', async function () {
const {data} = await axios({
- url: `http://localhost:${port}/python`,
+ url: `http://${TEST_HOST}:${port}/python`,
headers: {
'user-agent': 'Python',
'content-type': 'application/x-www-form-urlencoded'
@@ -57,7 +57,7 @@ describe('server', function () {
data.should.eql('application/json; charset=utf-8');
});
it('should catch errors in the catchall', async function () {
- await axios.get(`http://localhost:${port}/error`).should.be.rejected;
+ await axios.get(`http://${TEST_HOST}:${port}/error`).should.be.rejected;
});
it('should error if we try to start again on a port that is used', async function () {
await server({
@@ -66,7 +66,7 @@ describe('server', function () {
}).should.be.rejectedWith(/EADDRINUSE/);
});
it('should not wait for the server close connections before finishing closing', async function () {
- let bodyPromise = axios.get(`http://localhost:${port}/pause`).catch(() => {});
+ let bodyPromise = axios.get(`http://${TEST_HOST}:${port}/pause`).catch(() => {});
// relinquish control so that we don't close before the request is received
await B.delay(100);
@@ -98,7 +98,7 @@ describe('server plugins', function () {
let port;
before(async function () {
- port = await getPort();
+ port = await getTestPort(true);
});
afterEach(async function () {
@@ -126,9 +126,9 @@ describe('server plugins', function () {
updaterWithGetRoute('plugin2', 'res from plugin2 route'),
]
});
- let {data} = await axios.get(`http://localhost:${port}/plugin1`);
+ let {data} = await axios.get(`http://${TEST_HOST}:${port}/plugin1`);
data.should.eql('res from plugin1 route');
- ({data} = await axios.get(`http://localhost:${port}/plugin2`));
+ ({data} = await axios.get(`http://${TEST_HOST}:${port}/plugin2`));
data.should.eql('res from plugin2 route');
hwServer._updated_plugin1.should.be.true;
hwServer._updated_plugin2.should.be.true;

MODIFY
packages/base-driver/test/express/server-specs.js
packages/base-driver/test/express/server-specs.js
import { server, routeConfiguringFunction } from '../../index.js';
import { configureServer, normalizeBasePath } from '../../lib/express/server';
import sinon from 'sinon';
-import getPort from 'get-port';
+import {getTestPort} from '../helpers';
function fakeApp () {
const app = {
@@ -37,6 +37,12 @@ function fakeDriver () {
}
describe('server configuration', function () {
+ let port;
+
+ before(async function () {
+ port = await getTestPort(true);
+ });
+
it('should actually use the middleware', function () {
const app = fakeApp();
const configureRoutes = () => {};
@@ -67,7 +73,6 @@ describe('server configuration', function () {
it('should allow plugins to update the server', async function () {
const driver = fakeDriver();
- const port = await getPort();
const _server = await server({
routeConfiguringFunction: routeConfiguringFunction(driver),
port,
@@ -85,7 +90,6 @@ describe('server configuration', function () {
const configureRoutes = () => {
throw new Error('I am Mr. MeeSeeks look at me!');
};
- const port = await getPort();
await server({
routeConfiguringFunction: configureRoutes,
port,

ADD
packages/base-driver/test/helpers.js
+import getPort from 'get-port';
+
+const TEST_HOST = '127.0.0.1';
+
+let TEST_PORT;
+/**
+ * Returns a free port; one per process
+ * @param {boolean} [force] - If true, do not reuse the port (if it already exists)
+ * @returns {Promise<number>} a free port
+ */
+async function getTestPort (force = false) {
+ return await (force || !TEST_PORT ? getPort() : TEST_PORT);
+}
+
+export { TEST_HOST, getTestPort };

MODIFY
packages/base-driver/test/jsonwp-proxy/proxy-specs.js
packages/base-driver/test/jsonwp-proxy/proxy-specs.js
import { JWProxy } from '../..';
import request from './mock-request';
import { isErrorType, errors } from '../../lib/protocol/errors';
-
+import { getTestPort, TEST_HOST } from '../helpers';
function buildReqRes (url, method, body) {
let req = {originalUrl: url, method, body};
@@ -23,7 +23,12 @@ function buildReqRes (url, method, body) {
return [req, res];
}
+describe('proxy', function () {
+ let port;
+
function mockProxy (opts = {}) {
+ // sets default server/port
+ opts = {server: TEST_HOST, port, ...opts};
let proxy = new JWProxy(opts);
proxy.request = async function (...args) {
return await request(...args);
@@ -31,11 +36,14 @@ function mockProxy (opts = {}) {
return proxy;
}
-describe('proxy', function () {
+ before(async function () {
+ port = await getTestPort();
+ });
+
it('should override default params', function () {
- let j = mockProxy({server: '127.0.0.2'});
+ let j = mockProxy({server: '127.0.0.2', port});
j.server.should.equal('127.0.0.2');
- j.port.should.equal(4444);
+ j.port.should.equal(port);
});
it('should save session id on session creation', async function () {
let j = mockProxy();
@@ -48,29 +56,29 @@ describe('proxy', function () {
it('should modify session id, host, and port', function () {
let j = mockProxy({sessionId: '123'});
j.getUrlForProxy('http://host.com:1234/session/456/element/200/value')
- .should.eql('http://localhost:4444/session/123/element/200/value');
+ .should.eql(`http://${TEST_HOST}:${port}/session/123/element/200/value`);
});
it('should prepend scheme, host and port if not provided', function () {
let j = mockProxy({sessionId: '123'});
j.getUrlForProxy('/session/456/element/200/value')
- .should.eql('http://localhost:4444/session/123/element/200/value');
+ .should.eql(`http://${TEST_HOST}:${port}/session/123/element/200/value`);
});
it('should respect nonstandard incoming request base path', function () {
let j = mockProxy({sessionId: '123', reqBasePath: ''});
j.getUrlForProxy('/session/456/element/200/value')
- .should.eql('http://localhost:4444/session/123/element/200/value');
+ .should.eql(`http://${TEST_HOST}:${port}/session/123/element/200/value`);
j = mockProxy({sessionId: '123', reqBasePath: '/my/base/path'});
j.getUrlForProxy('/my/base/path/session/456/element/200/value')
- .should.eql('http://localhost:4444/session/123/element/200/value');
+ .should.eql(`http://${TEST_HOST}:${port}/session/123/element/200/value`);
});
it('should work with urls which do not have session ids', function () {
let j = mockProxy({sessionId: '123'});
j.getUrlForProxy('http://host.com:1234/session')
- .should.eql('http://localhost:4444/session');
+ .should.eql(`http://${TEST_HOST}:${port}/session`);
let newUrl = j.getUrlForProxy('/session');
- newUrl.should.eql('http://localhost:4444/session');
+ newUrl.should.eql(`http://${TEST_HOST}:${port}/session`);
});
it('should throw an error if url requires a sessionId but its null', function () {
let j = mockProxy();

MODIFY
packages/base-driver/test/jsonwp-proxy/url-specs.js
packages/base-driver/test/jsonwp-proxy/url-specs.js
// transpile:mocha
import { JWProxy } from '../..';
+import {getTestPort, TEST_HOST} from '../helpers';
+describe('JWProxy', function () {
+ let port;
+ function createJWProxy (opts = {}) {
+ return new JWProxy({server: TEST_HOST, port, ...opts});
+ }
+
+ before(async function () {
+ port = await getTestPort();
+ });
describe('proxying full urls', function () {
it('should translate host and port', function () {
let incomingUrl = 'http://127.0.0.2:4723/status';
- let j = new JWProxy();
+ let j = createJWProxy();
let proxyUrl = j.getUrlForProxy(incomingUrl);
- proxyUrl.should.equal('http://localhost:4444/status');
+ proxyUrl.should.equal(`http://${TEST_HOST}:${port}/status`);
});
it('should translate the scheme', function () {
let incomingUrl = 'http://127.0.0.2:4723/status';
- let j = new JWProxy({scheme: 'HTTPS'});
+ let j = createJWProxy({scheme: 'HTTPS'});
let proxyUrl = j.getUrlForProxy(incomingUrl);
- proxyUrl.should.equal('https://localhost:4444/status');
+ proxyUrl.should.equal(`https://${TEST_HOST}:${port}/status`);
});
it('should translate the base', function () {
let incomingUrl = 'http://127.0.0.2:4723/status';
- let j = new JWProxy({base: ''});
+ let j = createJWProxy({base: ''});
let proxyUrl = j.getUrlForProxy(incomingUrl);
- proxyUrl.should.equal('http://localhost:4444/status');
+ proxyUrl.should.equal(`http://${TEST_HOST}:${port}/status`);
});
it('should translate the session id', function () {
let incomingUrl = 'http://127.0.0.2:4723/session/foobar/element';
- let j = new JWProxy({sessionId: 'barbaz'});
+ let j = createJWProxy({sessionId: 'barbaz'});
let proxyUrl = j.getUrlForProxy(incomingUrl);
- proxyUrl.should.equal('http://localhost:4444/session/barbaz/element');
+ proxyUrl.should.equal(`http://${TEST_HOST}:${port}/session/barbaz/element`);
});
it('should error when translating session commands without session id', function () {
let incomingUrl = 'http://127.0.0.2:4723/session/foobar/element';
- let j = new JWProxy();
+ let j = createJWProxy();
(() => { j.getUrlForProxy(incomingUrl); }).should.throw('session id');
});
});
@@ -39,68 +49,70 @@ describe('proxying full urls', function () {
describe('proxying partial urls', function () {
it('should proxy /status', function () {
let incomingUrl = '/status';
- let j = new JWProxy();
+ let j = createJWProxy();
let proxyUrl = j.getUrlForProxy(incomingUrl);
- proxyUrl.should.equal('http://localhost:4444/status');
+ proxyUrl.should.equal(`http://${TEST_HOST}:${port}/status`);
});
it('should proxy /session', function () {
let incomingUrl = '/session';
- let j = new JWProxy();
+ let j = createJWProxy();
let proxyUrl = j.getUrlForProxy(incomingUrl);
- proxyUrl.should.equal('http://localhost:4444/session');
+ proxyUrl.should.equal(`http://${TEST_HOST}:${port}/session`);
});
it('should proxy /sessions', function () {
let incomingUrl = '/sessions';
- let j = new JWProxy();
+ let j = createJWProxy();
let proxyUrl = j.getUrlForProxy(incomingUrl);
- proxyUrl.should.equal('http://localhost:4444/sessions');
+ proxyUrl.should.equal(`http://${TEST_HOST}:${port}/sessions`);
});
it('should proxy session commands based off /session', function () {
let incomingUrl = '/session/foobar/element';
- let j = new JWProxy({sessionId: 'barbaz'});
+ let j = createJWProxy({sessionId: 'barbaz'});
let proxyUrl = j.getUrlForProxy(incomingUrl);
- proxyUrl.should.equal('http://localhost:4444/session/barbaz/element');
+ proxyUrl.should.equal(`http://${TEST_HOST}:${port}/session/barbaz/element`);
});
it('should error session commands based off /session without session id', function () {
let incomingUrl = '/session/foobar/element';
- let j = new JWProxy();
+ let j = createJWProxy();
(() => { j.getUrlForProxy(incomingUrl); }).should.throw('session id');
});
it('should proxy session commands based off ', function () {
let incomingUrl = '/session/3d001db2-7987-42a7-975d-8d5d5304083f/timeouts/implicit_wait';
- let j = new JWProxy({sessionId: '123'});
+ let j = createJWProxy({sessionId: '123'});
let proxyUrl = j.getUrlForProxy(incomingUrl);
- proxyUrl.should.equal('http://localhost:4444/session/123/timeouts/implicit_wait');
+ proxyUrl.should.equal(`http://${TEST_HOST}:${port}/session/123/timeouts/implicit_wait`);
});
it('should proxy session commands based off /session as ""', function () {
let incomingUrl = '';
- let j = new JWProxy();
+ let j = createJWProxy();
(() => { j.getUrlForProxy(incomingUrl); }).should.throw('session id');
- j = new JWProxy({sessionId: '123'});
+ j = createJWProxy({sessionId: '123'});
let proxyUrl = j.getUrlForProxy(incomingUrl);
- proxyUrl.should.equal('http://localhost:4444/session/123');
+ proxyUrl.should.equal(`http://${TEST_HOST}:${port}/session/123`);
});
it('should proxy session commands without /session', function () {
let incomingUrl = '/element';
- let j = new JWProxy({sessionId: 'barbaz'});
+ let j = createJWProxy({sessionId: 'barbaz'});
let proxyUrl = j.getUrlForProxy(incomingUrl);
- proxyUrl.should.equal('http://localhost:4444/session/barbaz/element');
+ proxyUrl.should.equal(`http://${TEST_HOST}:${port}/session/barbaz/element`);
});
it(`should proxy session commands when '/session' is in the url`, function () {
let incomingUrl = '/session/82a9b7da-faaf-4a1d-8ef3-5e4fb5812200/cookie/session-something-or-other';
- let j = new JWProxy({sessionId: 'barbaz'});
+ let j = createJWProxy({sessionId: 'barbaz'});
let proxyUrl = j.getUrlForProxy(incomingUrl);
- proxyUrl.should.equal('http://localhost:4444/session/barbaz/cookie/session-something-or-other');
+ proxyUrl.should.equal(`http://${TEST_HOST}:${port}/session/barbaz/cookie/session-something-or-other`);
});
it(`should proxy session commands when '/session' is in the url and not base on the original url`, function () {
let incomingUrl = '/session/82a9b7da-faaf-4a1d-8ef3-5e4fb5812200/cookie/session-something-or-other';
- let j = new JWProxy({sessionId: 'barbaz'});
+ let j = createJWProxy({sessionId: 'barbaz'});
let proxyUrl = j.getUrlForProxy(incomingUrl);
- proxyUrl.should.equal('http://localhost:4444/session/barbaz/cookie/session-something-or-other');
+ proxyUrl.should.equal(`http://${TEST_HOST}:${port}/session/barbaz/cookie/session-something-or-other`);
});
it('should error session commands without /session without session id', function () {
let incomingUrl = '/element';
- let j = new JWProxy();
+ let j = createJWProxy();
(() => { j.getUrlForProxy(incomingUrl); }).should.throw('session id');
});
});
+
+});

MODIFY
packages/base-driver/test/protocol/protocol-e2e-specs.js
packages/base-driver/test/protocol/protocol-e2e-specs.js
@@ -12,7 +12,7 @@ import {
MJSONWP_ELEMENT_KEY, W3C_ELEMENT_KEY
} from '../../lib/constants';
import qs from 'querystring';
-import getPort from 'get-port';
+import {TEST_HOST, getTestPort} from '../helpers';
let port;
let baseUrl;
@@ -20,8 +20,8 @@ let baseUrl;
describe('Protocol', function () {
before(async function () {
- port = await getPort();
- baseUrl = `http://localhost:${port}`;
+ port = await getTestPort();
+ baseUrl = `http://${TEST_HOST}:${port}`;
});
//TODO: more tests!:
@@ -571,14 +571,14 @@ describe('Protocol', function () {
let server, jwproxy, app;
before(async function () {
- port = await getPort();
+ port = await getTestPort(true);
});
beforeEach(function () {
const res = createProxyServer(sessionId, port);
server = res.server;
app = res.app;
- jwproxy = new JWProxy({host: 'localhost', port});
+ jwproxy = new JWProxy({host: TEST_HOST, port});
jwproxy.sessionId = sessionId;
driver.performActions = async (actions) => await jwproxy.command('/perform-actions', 'POST', actions);
});

MODIFY
packages/support/test/mjpeg-e2e-specs.js
packages/support/test/mjpeg-e2e-specs.js
@@ -3,14 +3,13 @@ import { mjpeg } from '..';
import B from 'bluebird';
import http from 'http';
import mJpegServer from 'mjpeg-server';
+import getPort from 'get-port';
const {MJpegStream} = mjpeg;
const TEST_IMG_JPG = '/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAAAeAAD/4QOBaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLwA8P3hwYWNrZXQgYmVnaW49Iu+7vyIgaWQ9Ilc1TTBNcENlaGlIenJlU3pOVGN6a2M5ZCI/PiA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4OnhtcHRrPSJBZG9iZSBYTVAgQ29yZSA1LjYtYzE0MCA3OS4xNjA0NTEsIDIwMTcvMDUvMDYtMDE6MDg6MjEgICAgICAgICI+IDxyZGY6UkRGIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyI+IDxyZGY6RGVzY3JpcHRpb24gcmRmOmFib3V0PSIiIHhtbG5zOnhtcE1NPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvbW0vIiB4bWxuczpzdFJlZj0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL3NUeXBlL1Jlc291cmNlUmVmIyIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bXBNTTpPcmlnaW5hbERvY3VtZW50SUQ9InhtcC5kaWQ6NGY5ODc1OTctZGE2My00Y2M0LTkzNDMtNGYyNjgzMGUwNjk3IiB4bXBNTTpEb2N1bWVudElEPSJ4bXAuZGlkOjlDMzI3QkY0N0Q3NTExRThCMTlDOTVDMDc2RDE5MDY5IiB4bXBNTTpJbnN0YW5jZUlEPSJ4bXAuaWlkOjlDMzI3QkYzN0Q3NTExRThCMTlDOTVDMDc2RDE5MDY5IiB4bXA6Q3JlYXRvclRvb2w9IkFkb2JlIFBob3Rvc2hvcCBDQyAyMDE4IChNYWNpbnRvc2gpIj4gPHhtcE1NOkRlcml2ZWRGcm9tIHN0UmVmOmluc3RhbmNlSUQ9InhtcC5paWQ6NGY5ODc1OTctZGE2My00Y2M0LTkzNDMtNGYyNjgzMGUwNjk3IiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOjRmOTg3NTk3LWRhNjMtNGNjNC05MzQzLTRmMjY4MzBlMDY5NyIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/Pv/uAA5BZG9iZQBkwAAAAAH/2wCEABALCwsMCxAMDBAXDw0PFxsUEBAUGx8XFxcXFx8eFxoaGhoXHh4jJSclIx4vLzMzLy9AQEBAQEBAQEBAQEBAQEABEQ8PERMRFRISFRQRFBEUGhQWFhQaJhoaHBoaJjAjHh4eHiMwKy4nJycuKzU1MDA1NUBAP0BAQEBAQEBAQEBAQP/AABEIACAAIAMBIgACEQEDEQH/xABgAAEAAwEAAAAAAAAAAAAAAAAABAUHCAEBAAAAAAAAAAAAAAAAAAAAABAAAQMCAgsAAAAAAAAAAAAAAAECBBEDEgYhMRODo7PTVAUWNhEBAAAAAAAAAAAAAAAAAAAAAP/aAAwDAQACEQMRAD8Az8AAdAAAAAAI8+fE8dEuTZtzZR7VMb6OdTE5GJoYirrUp/e8qd9wb3TGe/lJ2551sx8D/9k=';
-const MJPEG_SERVER_PORT = 8589;
-const MJPEG_SERVER_URL = `http://localhost:${MJPEG_SERVER_PORT}`;
-
+const MJPEG_HOST = '127.0.0.1';
/**
* Start an mjpeg server for the purpose of testing, which just sends the same
@@ -40,6 +39,7 @@ function initMJpegServer (port, intMs = 300, times = 20) {
describe('MJpeg Stream (e2e)', function () {
let mJpegServer, stream;
+ let serverUrl, port;
before(async function () {
// TODO: remove when buffertools can handle v12
@@ -47,7 +47,9 @@ describe('MJpeg Stream (e2e)', function () {
return this.skip();
}
- mJpegServer = await initMJpegServer(MJPEG_SERVER_PORT);
+ port = await getPort();
+ serverUrl = `http://${MJPEG_HOST}:${port}`;
+ mJpegServer = await initMJpegServer(port);
});
after(function () {
@@ -60,7 +62,7 @@ describe('MJpeg Stream (e2e)', function () {
});
it('should update mjpeg stream based on new data from mjpeg server', async function () {
- stream = new MJpegStream(MJPEG_SERVER_URL, _.noop);
+ stream = new MJpegStream(serverUrl, _.noop);
should.not.exist(stream.lastChunk);
await stream.start();
should.exist(stream.lastChunk);
@@ -96,7 +98,7 @@ describe('MJpeg Stream (e2e)', function () {
});
it('should error out if the server does not send any images before a timeout', async function () {
- stream = new MJpegStream(MJPEG_SERVER_URL, _.noop);
+ stream = new MJpegStream(serverUrl, _.noop);
await stream.start(0).should.eventually.be.rejectedWith(/never sent/);
});

chore: replace occurrences of 'localhost' with '127.0.01'; use random ports; closes #15399

- `base-driver` gets a new `helpers` module with a `getTestPort` function; this is now used throughout the tests
- `fake-driver` can't use random ports because it depends on `appium-base-driver`'s test suite, and that is _not_ the current appium-2.0-compatible `@appium/base-driver`