1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 11:22:43 +02:00
metamask-extension/test/e2e/helpers.js

50 lines
1.3 KiB
JavaScript
Raw Normal View History

const path = require('path')
const Ganache = require('./ganache')
const FixtureServer = require('./fixture-server')
const { buildWebDriver } = require('./webdriver')
const tinyDelayMs = 200
const regularDelayMs = tinyDelayMs * 2
const largeDelayMs = regularDelayMs * 2
2018-05-25 03:17:26 +02:00
async function withFixtures (options, callback) {
const { fixtures, ganacheOptions, driverOptions } = options
const fixtureServer = new FixtureServer()
const ganacheServer = new Ganache()
let webDriver
try {
await ganacheServer.start(ganacheOptions)
await fixtureServer.start()
await fixtureServer.loadState(path.join(__dirname, 'fixtures', fixtures))
const { driver } = await buildWebDriver(driverOptions)
webDriver = driver
await callback({
driver,
})
if (process.env.SELENIUM_BROWSER === 'chrome') {
const errors = await driver.checkBrowserForConsoleErrors(driver)
if (errors.length) {
const errorReports = errors.map((err) => err.message)
const errorMessage = `Errors found in browser console:\n${errorReports.join('\n')}`
throw new Error(errorMessage)
}
}
} finally {
await fixtureServer.stop()
await ganacheServer.quit()
if (webDriver) {
await webDriver.quit()
}
}
}
2018-05-25 03:17:26 +02:00
module.exports = {
tinyDelayMs,
regularDelayMs,
largeDelayMs,
withFixtures,
}