Convert the more complicated CommonJS exports to ES6-style

This commit is contained in:
Travis Ralston 2019-12-19 17:57:50 -07:00
parent 344dac4fb9
commit 4aec432b30
14 changed files with 91 additions and 86 deletions

View file

@ -1,5 +1,6 @@
/*
Copyright 2018 New Vector Ltd
Copyright 2019 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@ -18,7 +19,7 @@ const request = require('request-promise-native');
const cheerio = require('cheerio');
const url = require("url");
module.exports.approveConsent = async function(consentUrl) {
export async function approveConsent(consentUrl) {
const body = await request.get(consentUrl);
const doc = cheerio.load(body);
const v = doc("input[name=v]").val();
@ -27,4 +28,4 @@ module.exports.approveConsent = async function(consentUrl) {
const formAction = doc("form").attr("action");
const absAction = url.resolve(consentUrl, formAction);
await request.post(absAction).form({v, u, h});
};
}

View file

@ -1,5 +1,6 @@
/*
Copyright 2018 New Vector Ltd
Copyright 2019 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@ -16,7 +17,7 @@ limitations under the License.
const assert = require('assert');
async function openMemberInfo(session, name) {
export async function openMemberInfo(session, name) {
const membersAndNames = await getMembersInMemberlist(session);
const matchingLabel = membersAndNames.filter((m) => {
return m.displayName === name;
@ -24,9 +25,7 @@ async function openMemberInfo(session, name) {
await matchingLabel.click();
}
module.exports.openMemberInfo = openMemberInfo;
module.exports.verifyDeviceForUser = async function(session, name, expectedDevice) {
export async function verifyDeviceForUser(session, name, expectedDevice) {
session.log.step(`verifies e2e device for ${name}`);
const membersAndNames = await getMembersInMemberlist(session);
const matchingLabel = membersAndNames.filter((m) => {
@ -59,9 +58,9 @@ module.exports.verifyDeviceForUser = async function(session, name, expectedDevic
const closeMemberInfo = await session.query(".mx_MemberInfo_cancel");
await closeMemberInfo.click();
session.log.done();
};
}
async function getMembersInMemberlist(session) {
export async function getMembersInMemberlist(session) {
const memberPanelButton = await session.query(".mx_RightPanel_membersButton");
try {
await session.query(".mx_RightPanel_headerButton_highlight", 500);
@ -78,5 +77,3 @@ async function getMembersInMemberlist(session) {
return {label: el, displayName: await session.innerText(el)};
}));
}
module.exports.getMembersInMemberlist = getMembersInMemberlist;

View file

@ -1,5 +1,6 @@
/*
Copyright 2018 New Vector Ltd
Copyright 2019 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@ -28,7 +29,7 @@ async function openSettings(session, section) {
}
}
module.exports.enableLazyLoading = async function(session) {
export async function enableLazyLoading(session) {
session.log.step(`enables lazy loading of members in the lab settings`);
const settingsButton = await session.query('.mx_BottomLeftMenu_settings');
await settingsButton.click();
@ -38,9 +39,9 @@ module.exports.enableLazyLoading = async function(session) {
const closeButton = await session.query(".mx_RoomHeader_cancelButton");
await closeButton.click();
session.log.done();
};
}
module.exports.getE2EDeviceFromSettings = async function(session) {
export async function getE2EDeviceFromSettings(session) {
session.log.step(`gets e2e device/key from settings`);
await openSettings(session, "security");
const deviceAndKey = await session.queryAll(".mx_SettingsTab_section .mx_SecurityUserSettingsTab_deviceInfo code");
@ -51,4 +52,4 @@ module.exports.getE2EDeviceFromSettings = async function(session) {
await closeButton.click();
session.log.done();
return {id, key};
};
}

View file

@ -1,5 +1,6 @@
/*
Copyright 2018 New Vector Ltd
Copyright 2019 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@ -16,7 +17,7 @@ limitations under the License.
const assert = require('assert');
module.exports.scrollToTimelineTop = async function(session) {
export async function scrollToTimelineTop(session) {
session.log.step(`scrolls to the top of the timeline`);
await session.page.evaluate(() => {
return Promise.resolve().then(async () => {
@ -40,9 +41,9 @@ module.exports.scrollToTimelineTop = async function(session) {
});
});
session.log.done();
};
}
module.exports.receiveMessage = async function(session, expectedMessage) {
export async function receiveMessage(session, expectedMessage) {
session.log.step(`receives message "${expectedMessage.body}" from ${expectedMessage.sender}`);
// wait for a response to come in that contains the message
// crude, but effective
@ -66,10 +67,10 @@ module.exports.receiveMessage = async function(session, expectedMessage) {
});
assertMessage(lastMessage, expectedMessage);
session.log.done();
};
}
module.exports.checkTimelineContains = async function(session, expectedMessages, sendersDescription) {
export async function checkTimelineContains(session, expectedMessages, sendersDescription) {
session.log.step(`checks timeline contains ${expectedMessages.length} ` +
`given messages${sendersDescription ? ` from ${sendersDescription}`:""}`);
const eventTiles = await getAllEventTiles(session);
@ -101,7 +102,7 @@ module.exports.checkTimelineContains = async function(session, expectedMessages,
});
session.log.done();
};
}
function assertMessage(foundMessage, expectedMessage) {
assert(foundMessage, `message ${JSON.stringify(expectedMessage)} not found in timeline`);

View file

@ -1,5 +1,6 @@
/*
Copyright 2019 New Vector Ltd
Copyright 2019 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@ -37,7 +38,7 @@ async function getSasCodes(session) {
return sasLabels;
}
module.exports.startSasVerifcation = async function(session, name) {
export async function startSasVerifcation(session, name) {
await startVerification(session, name);
// expect "Verify device" dialog and click "Begin Verification"
await assertDialog(session, "Verify device");
@ -50,9 +51,9 @@ module.exports.startSasVerifcation = async function(session, name) {
// click "Got it" when verification is done
await acceptDialog(session);
return sasCodes;
};
}
module.exports.acceptSasVerification = async function(session, name) {
export async function acceptSasVerification(session, name) {
await assertDialog(session, "Incoming Verification Request");
const opponentLabelElement = await session.query(".mx_IncomingSasDialog_opponentProfile h2");
const opponentLabel = await session.innerText(opponentLabelElement);
@ -66,4 +67,4 @@ module.exports.acceptSasVerification = async function(session, name) {
// click "Got it" when verification is done
await acceptDialog(session);
return sasCodes;
};
}

View file

@ -1,5 +1,6 @@
/*
Copyright 2018 New Vector Ltd
Copyright 2019 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@ -14,14 +15,14 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
module.exports.range = function(start, amount, step = 1) {
export function range(start, amount, step = 1) {
const r = [];
for (let i = 0; i < amount; ++i) {
r.push(start + (i * step));
}
return r;
};
}
module.exports.delay = function(ms) {
export function delay(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
};
}