2020-01-20 19:50:25 +01:00
|
|
|
const path = require('path')
|
|
|
|
const Ganache = require('./ganache')
|
|
|
|
const FixtureServer = require('./fixture-server')
|
|
|
|
const { buildWebDriver } = require('./webdriver')
|
|
|
|
|
2019-09-07 09:13:58 +02:00
|
|
|
const tinyDelayMs = 200
|
|
|
|
const regularDelayMs = tinyDelayMs * 2
|
|
|
|
const largeDelayMs = regularDelayMs * 2
|
2018-05-25 03:17:26 +02:00
|
|
|
|
2020-01-20 19:50:25 +01: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,
|
|
|
|
})
|
|
|
|
} finally {
|
|
|
|
await fixtureServer.stop()
|
|
|
|
await ganacheServer.quit()
|
|
|
|
if (webDriver) {
|
|
|
|
await webDriver.quit()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-25 03:17:26 +02:00
|
|
|
module.exports = {
|
2019-09-07 09:13:58 +02:00
|
|
|
tinyDelayMs,
|
|
|
|
regularDelayMs,
|
|
|
|
largeDelayMs,
|
2020-01-20 19:50:25 +01:00
|
|
|
withFixtures,
|
2019-09-07 09:13:58 +02:00
|
|
|
}
|