Skip to content

Commit

Permalink
Get rid of arrow functions in mocha aparatus (#10013)
Browse files Browse the repository at this point in the history
  • Loading branch information
imurchie committed Jan 17, 2018
1 parent 909694b commit ac8be00
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 151 deletions.
152 changes: 76 additions & 76 deletions test/config-specs.js

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions test/driver-e2e-specs.js
Expand Up @@ -15,23 +15,23 @@ const should = chai.should();
const shouldStartServer = process.env.USE_RUNNING_SERVER !== "0";
const caps = {platformName: "Fake", deviceName: "Fake", app: TEST_FAKE_APP};

describe('FakeDriver - via HTTP', () => {
describe('FakeDriver - via HTTP', function () {
let server = null;
const baseUrl = `http://${TEST_HOST}:${TEST_PORT}/wd/hub/session`;
before(async () => {
before(async function () {
if (shouldStartServer) {
let args = {port: TEST_PORT, host: TEST_HOST};
server = await appiumServer(args);
}
});
after(async () => {
after(async function () {
if (server) {
await server.close();
}
});

describe('session handling', () => {
it('should start and stop a session', async () => {
describe('session handling', function () {
it('should start and stop a session', async function () {
let driver = wd.promiseChainRemote(TEST_HOST, TEST_PORT);
let [sessionId] = await driver.init(caps);
should.exist(sessionId);
Expand All @@ -40,7 +40,7 @@ describe('FakeDriver - via HTTP', () => {
await driver.title().should.eventually.be.rejectedWith(/terminated/);
});

it('should be able to run two FakeDriver sessions simultaneously', async () => {
it('should be able to run two FakeDriver sessions simultaneously', async function () {
let driver1 = wd.promiseChainRemote(TEST_HOST, TEST_PORT);
let [sessionId1] = await driver1.init(caps);
should.exist(sessionId1);
Expand All @@ -54,7 +54,7 @@ describe('FakeDriver - via HTTP', () => {
await driver2.quit();
});

it('should not be able to run two FakeDriver sessions simultaneously when one is unique', async () => {
it('should not be able to run two FakeDriver sessions simultaneously when one is unique', async function () {
let uniqueCaps = _.clone(caps);
uniqueCaps.uniqueApp = true;
let driver1 = wd.promiseChainRemote(TEST_HOST, TEST_PORT);
Expand All @@ -66,7 +66,7 @@ describe('FakeDriver - via HTTP', () => {
await driver1.quit();
});

it('should use the newCommandTimeout of the inner Driver on session creation', async () => {
it('should use the newCommandTimeout of the inner Driver on session creation', async function () {
let driver = wd.promiseChainRemote(TEST_HOST, TEST_PORT);

caps.newCommandTimeout = 0.25;
Expand All @@ -78,7 +78,7 @@ describe('FakeDriver - via HTTP', () => {
await driver.source().should.eventually.be.rejectedWith(/terminated/);
});

it('should accept valid W3C capabilities and start a W3C session', async () => {
it('should accept valid W3C capabilities and start a W3C session', async function () {
// Try with valid capabilities and check that it returns a session ID
const w3cCaps = {
capabilities: {
Expand Down Expand Up @@ -113,7 +113,7 @@ describe('FakeDriver - via HTTP', () => {
await request.delete({url: `${baseUrl}/${value.sessionId}`}).should.eventually.be.resolved;
});

it('should reject invalid W3C capabilities and respond with a 400 Bad Parameters error', async () => {
it('should reject invalid W3C capabilities and respond with a 400 Bad Parameters error', async function () {
const badW3Ccaps = {
capabilities: {
alwaysMatch: {},
Expand All @@ -126,7 +126,7 @@ describe('FakeDriver - via HTTP', () => {
message.should.match(/can't be blank/);
});

it('should accept a combo of W3C and JSONWP capabilities but default to W3C', async () => {
it('should accept a combo of W3C and JSONWP capabilities but default to W3C', async function () {
const combinedCaps = {
"desiredCapabilities": {
...caps,
Expand All @@ -151,7 +151,7 @@ describe('FakeDriver - via HTTP', () => {
});
});

it('should reject bad W3C capabilities with a BadParametersError (400)', async () => {
it('should reject bad W3C capabilities with a BadParametersError (400)', async function () {
const w3cCaps = {
"capabilities": {
"alwaysMatch": {
Expand All @@ -165,7 +165,7 @@ describe('FakeDriver - via HTTP', () => {
statusCode.should.equal(400);
});

it('should accept capabilities that are provided in the firstMatch array', async () => {
it('should accept capabilities that are provided in the firstMatch array', async function () {
const w3cCaps = {
"capabilities": {
"alwaysMatch": {},
Expand All @@ -182,23 +182,23 @@ describe('FakeDriver - via HTTP', () => {
});
});

describe('Logsink', () => {
describe('Logsink', function () {
let server = null;
let logs = [];
let logHandler = (level, message) => {
logs.push([level, message]);
};
let args = {port: TEST_PORT, host: TEST_HOST, logHandler};

before(async () => {
before(async function () {
server = await appiumServer(args);
});

after(async () => {
after(async function () {
await server.close();
});

it('should send logs to a logHandler passed in by a parent package', async () => {
it('should send logs to a logHandler passed in by a parent package', async function () {
logs.length.should.be.above(1);
logs[0].length.should.equal(2);
logs[0][1].should.include("Welcome to Appium");
Expand Down
72 changes: 36 additions & 36 deletions test/driver-specs.js
Expand Up @@ -17,15 +17,15 @@ chai.use(chaiAsPromised);

const SESSION_ID = 1;

describe('AppiumDriver', () => {
describe('getAppiumRouter', () => {
it('should return a route configuring function', async () => {
describe('AppiumDriver', function () {
describe('getAppiumRouter', function () {
it('should return a route configuring function', async function () {
let routeConfiguringFunction = getAppiumRouter({});
routeConfiguringFunction.should.be.a.function;
});
});

describe('AppiumDriver', () => {
describe('AppiumDriver', function () {
function getDriverAndFakeDriver () {
let appium = new AppiumDriver({});
let fakeDriver = new FakeDriver();
Expand All @@ -37,25 +37,25 @@ describe('AppiumDriver', () => {
};
return [appium, mockFakeDriver];
}
describe('createSession', () => {
describe('createSession', function () {
let appium;
let mockFakeDriver;
beforeEach(() => {
beforeEach(function () {
[appium, mockFakeDriver] = getDriverAndFakeDriver();
});
afterEach(async () => {
afterEach(async function () {
mockFakeDriver.restore();
await appium.deleteSession(SESSION_ID);
});

it('should call inner driver\'s createSession with desired capabilities', async () => {
it('should call inner driver\'s createSession with desired capabilities', async function () {
mockFakeDriver.expects("createSession")
.once().withExactArgs(BASE_CAPS, undefined, null, [])
.returns([SESSION_ID, BASE_CAPS]);
await appium.createSession(BASE_CAPS);
mockFakeDriver.verify();
});
it('should call inner driver\'s createSession with desired and default capabilities', async () => {
it('should call inner driver\'s createSession with desired and default capabilities', async function () {
let defaultCaps = {deviceName: 'Emulator'}
, allCaps = _.extend(_.clone(defaultCaps), BASE_CAPS);
appium.args.defaultCapabilities = defaultCaps;
Expand All @@ -65,7 +65,7 @@ describe('AppiumDriver', () => {
await appium.createSession(BASE_CAPS);
mockFakeDriver.verify();
});
it('should call inner driver\'s createSession with desired and default capabilities without overriding caps', async () => {
it('should call inner driver\'s createSession with desired and default capabilities without overriding caps', async function () {
// a default capability with the same key as a desired capability
// should do nothing
let defaultCaps = {platformName: 'Ersatz'};
Expand All @@ -76,7 +76,7 @@ describe('AppiumDriver', () => {
await appium.createSession(BASE_CAPS);
mockFakeDriver.verify();
});
it('should kill all other sessions if sessionOverride is on', async () => {
it('should kill all other sessions if sessionOverride is on', async function () {
appium.args.sessionOverride = true;

// mock three sessions that should be removed when the new one is created
Expand Down Expand Up @@ -140,24 +140,24 @@ describe('AppiumDriver', () => {
mockFakeDriver.verify();
});
});
describe('deleteSession', () => {
describe('deleteSession', function () {
let appium;
let mockFakeDriver;
beforeEach(() => {
beforeEach(function () {
[appium, mockFakeDriver] = getDriverAndFakeDriver();
});
afterEach(() => {
afterEach(function () {
mockFakeDriver.restore();
});
it('should remove the session if it is found', async () => {
it('should remove the session if it is found', async function () {
let [sessionId] = await appium.createSession(BASE_CAPS);
let sessions = await appium.getSessions();
sessions.should.have.length(1);
await appium.deleteSession(sessionId);
sessions = await appium.getSessions();
sessions.should.have.length(0);
});
it('should call inner driver\'s deleteSession method', async () => {
it('should call inner driver\'s deleteSession method', async function () {
const [sessionId] = await appium.createSession(BASE_CAPS);
mockFakeDriver.expects("deleteSession")
.once().withExactArgs(sessionId, [])
Expand All @@ -169,23 +169,23 @@ describe('AppiumDriver', () => {
await mockFakeDriver.object.deleteSession();
});
});
describe('getSessions', () => {
describe('getSessions', function () {
let appium;
let sessions;
before(() => {
before(function () {
appium = new AppiumDriver({});
});
afterEach(async () => {
afterEach(async function () {
for (let session of sessions) {
await appium.deleteSession(session.id);
}
});
it('should return an empty array of sessions', async () => {
it('should return an empty array of sessions', async function () {
sessions = await appium.getSessions();
sessions.should.be.an.array;
sessions.should.be.empty;
});
it('should return sessions created', async () => {
it('should return sessions created', async function () {
let session1 = await appium.createSession(_.extend(_.clone(BASE_CAPS), {cap: 'value'}));
let session2 = await appium.createSession(_.extend(_.clone(BASE_CAPS), {cap: 'other value'}));

Expand All @@ -198,48 +198,48 @@ describe('AppiumDriver', () => {
sessions[1].capabilities.should.eql(session2[1]);
});
});
describe('getStatus', () => {
describe('getStatus', function () {
let appium;
before(() => {
before(function () {
appium = new AppiumDriver({});
});
it('should return a status', async () => {
it('should return a status', async function () {
let status = await appium.getStatus();
status.build.should.exist;
status.build.version.should.exist;
});
});
describe('sessionExists', () => {
describe('sessionExists', function () {
});
describe('attachUnexpectedShutdownHandler', () => {
describe('attachUnexpectedShutdownHandler', function () {
let appium
, mockFakeDriver;
beforeEach(() => {
beforeEach(function () {
[appium, mockFakeDriver] = getDriverAndFakeDriver();
});
afterEach(async () => {
afterEach(async function () {
await mockFakeDriver.object.deleteSession();
mockFakeDriver.restore();
appium.args.defaultCapabilities = {};
});

it('should remove session if inner driver unexpectedly exits with an error', async () => {
it('should remove session if inner driver unexpectedly exits with an error', async function () {
let [sessionId,] = await appium.createSession(_.clone(BASE_CAPS)); // eslint-disable-line comma-spacing
_.keys(appium.sessions).should.contain(sessionId);
appium.sessions[sessionId].unexpectedShutdownDeferred.reject(new Error("Oops"));
// let event loop spin so rejection is handled
await sleep(1);
_.keys(appium.sessions).should.not.contain(sessionId);
});
it('should remove session if inner driver unexpectedly exits with no error', async () => {
it('should remove session if inner driver unexpectedly exits with no error', async function () {
let [sessionId,] = await appium.createSession(_.clone(BASE_CAPS)); // eslint-disable-line comma-spacing
_.keys(appium.sessions).should.contain(sessionId);
appium.sessions[sessionId].unexpectedShutdownDeferred.resolve();
// let event loop spin so rejection is handled
await sleep(1);
_.keys(appium.sessions).should.not.contain(sessionId);
});
it('should not remove session if inner driver cancels unexpected exit', async () => {
it('should not remove session if inner driver cancels unexpected exit', async function () {
let [sessionId,] = await appium.createSession(_.clone(BASE_CAPS)); // eslint-disable-line comma-spacing
_.keys(appium.sessions).should.contain(sessionId);
appium.sessions[sessionId].onUnexpectedShutdown.cancel();
Expand All @@ -248,12 +248,12 @@ describe('AppiumDriver', () => {
_.keys(appium.sessions).should.contain(sessionId);
});
});
describe('getDriverForCaps', () => {
it('should not blow up if user does not provide platformName', () => {
describe('getDriverForCaps', function () {
it('should not blow up if user does not provide platformName', function () {
let appium = new AppiumDriver({});
(() => { appium.getDriverForCaps({}); }).should.throw(/platformName/);
});
it('should get XCUITestDriver driver for automationName of XCUITest', () => {
it('should get XCUITestDriver driver for automationName of XCUITest', function () {
let appium = new AppiumDriver({});
let driver = appium.getDriverForCaps({
platformName: 'iOS',
Expand All @@ -262,7 +262,7 @@ describe('AppiumDriver', () => {
driver.should.be.an.instanceof(Function);
driver.should.equal(XCUITestDriver);
});
it('should get iosdriver for ios < 10', () => {
it('should get iosdriver for ios < 10', function () {
let appium = new AppiumDriver({});
let caps = {
platformName: 'iOS',
Expand Down Expand Up @@ -292,7 +292,7 @@ describe('AppiumDriver', () => {
driver = appium.getDriverForCaps(caps);
driver.should.equal(IosDriver);
});
it('should get xcuitestdriver for ios >= 10', () => {
it('should get xcuitestdriver for ios >= 10', function () {
let appium = new AppiumDriver({});
let caps = {
platformName: 'iOS',
Expand Down
4 changes: 2 additions & 2 deletions test/helpers.js
Expand Up @@ -12,12 +12,12 @@ const TEST_FAKE_APP = path.resolve(__dirname, "..", "..", "node_modules",
function initSession (caps) {
let resolve = () => {};
let driver;
before(async () => {
before(async function () {
driver = wd.promiseChainRemote({host: TEST_HOST, port: TEST_PORT});
resolve(driver);
await driver.init(caps);
});
after(async () => {
after(async function () {
await driver.quit();
});
return new B((_resolve) => {
Expand Down

0 comments on commit ac8be00

Please sign in to comment.