diff --git a/src/scenario.js b/src/scenario.js index 946a4122ef..3538fa2d40 100644 --- a/src/scenario.js +++ b/src/scenario.js @@ -21,6 +21,7 @@ const join = require('./tests/join'); const sendMessage = require('./tests/send-message'); const acceptInvite = require('./tests/accept-invite'); const invite = require('./tests/invite'); +const {delay, range} = require('./util'); const { receiveMessage, checkTimelineContains, @@ -49,14 +50,6 @@ module.exports = async function scenario(createSession, restCreator) { await aLazyLoadingTest(alice, bob, charlies); } -function range(start, amount, step = 1) { - const r = []; - for (let i = 0; i < amount; ++i) { - r.push(start + (i * step)); - } - return r; -} - async function createRestUsers(restCreator) { const usernames = range(1, 10).map((i) => `charly-${i}`); const charlies = await restCreator.createSessionRange(usernames, 'testtest'); @@ -88,12 +81,12 @@ async function createE2ERoomAndTalk(alice, bob) { const bobDevice = await getE2EDeviceFromSettings(bob); // wait some time for the encryption warning dialog // to appear after closing the settings - await bob.delay(1000); + await delay(1000); await acceptDialogMaybe(bob, "encryption"); const aliceDevice = await getE2EDeviceFromSettings(alice); // wait some time for the encryption warning dialog // to appear after closing the settings - await alice.delay(1000); + await delay(1000); await acceptDialogMaybe(alice, "encryption"); await verifyDeviceForUser(bob, "alice", aliceDevice); await verifyDeviceForUser(alice, "bob", bobDevice); diff --git a/src/session.js b/src/session.js index 86cdd05e95..839b4a495b 100644 --- a/src/session.js +++ b/src/session.js @@ -17,6 +17,7 @@ limitations under the License. const puppeteer = require('puppeteer'); const Logger = require('./logger'); const LogBuffer = require('./logbuffer'); +const {delay} = require('./util'); module.exports = class RiotSession { constructor(browser, page, username, riotserver, hsUrl) { @@ -169,7 +170,7 @@ module.exports = class RiotSession { } delay(ms) { - return new Promise(resolve => setTimeout(resolve, ms)); + return delay(ms); } close() { diff --git a/src/util.js b/src/util.js new file mode 100644 index 0000000000..8080d771be --- /dev/null +++ b/src/util.js @@ -0,0 +1,27 @@ +/* +Copyright 2018 New Vector Ltd + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +module.exports.range = function(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) { + return new Promise((resolve) => setTimeout(resolve, ms)); +}