1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Add test-dapp to withFixtures environment (#8957)

The `withFixtures` helper function now has the option of starting the
test dapp as well. It will wait to ensure it has started up correctly,
and it'll shut it down when the test ends.
This commit is contained in:
Mark Stacey 2020-07-10 00:57:54 -03:00 committed by GitHub
parent 46675f78ae
commit 7ec0cd0f46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,21 +2,34 @@ const path = require('path')
const Ganache = require('./ganache')
const FixtureServer = require('./fixture-server')
const { buildWebDriver } = require('./webdriver')
const createStaticServer = require('../../development/create-static-server')
const tinyDelayMs = 200
const regularDelayMs = tinyDelayMs * 2
const largeDelayMs = regularDelayMs * 2
const dappPort = 8080
async function withFixtures (options, callback) {
const { fixtures, ganacheOptions, driverOptions, title } = options
const { dapp, fixtures, ganacheOptions, driverOptions, title } = options
const fixtureServer = new FixtureServer()
const ganacheServer = new Ganache()
let dappServer
let webDriver
try {
await ganacheServer.start(ganacheOptions)
await fixtureServer.start()
await fixtureServer.loadState(path.join(__dirname, 'fixtures', fixtures))
if (dapp) {
const dappDirectory = path.resolve(__dirname, '..', '..', 'node_modules', '@metamask', 'test-dapp', 'dist')
dappServer = createStaticServer(dappDirectory)
dappServer.listen(dappPort)
await new Promise((resolve, reject) => {
dappServer.on('listening', resolve)
dappServer.on('error', reject)
})
}
const { driver } = await buildWebDriver(driverOptions)
webDriver = driver
@ -41,6 +54,16 @@ async function withFixtures (options, callback) {
if (webDriver) {
await webDriver.quit()
}
if (dappServer) {
await new Promise((resolve, reject) => {
dappServer.close((error) => {
if (error) {
return reject(error)
}
return resolve()
})
})
}
}
}