mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
test - e2e - factor out setup phase + rename METAMASK_CONFIG to METAMASK_TEST_CONFIG
This commit is contained in:
parent
02f5502e16
commit
ebb9447593
@ -31,7 +31,8 @@ const {
|
||||
ENVIRONMENT_TYPE_FULLSCREEN,
|
||||
} = require('./lib/enums')
|
||||
|
||||
const firstTimeState = Object.assign({}, rawFirstTimeState, global.METAMASK_CONFIG)
|
||||
// METAMASK_TEST_CONFIG is used in e2e tests to set the default network to localhost
|
||||
const firstTimeState = Object.assign({}, rawFirstTimeState, global.METAMASK_TEST_CONFIG)
|
||||
|
||||
const STORAGE_KEY = 'metamask-config'
|
||||
const METAMASK_DEBUG = process.env.METAMASK_DEBUG
|
||||
|
@ -4,11 +4,8 @@ const webdriver = require('selenium-webdriver')
|
||||
const { By, Key, until } = webdriver
|
||||
const {
|
||||
delay,
|
||||
buildChromeWebDriver,
|
||||
buildFirefoxWebdriver,
|
||||
installWebExt,
|
||||
getExtensionIdChrome,
|
||||
getExtensionIdFirefox,
|
||||
createModifiedTestBuild,
|
||||
setupBrowserAndExtension,
|
||||
} = require('../func')
|
||||
const {
|
||||
findElement,
|
||||
@ -19,6 +16,7 @@ const {
|
||||
} = require('./helpers')
|
||||
|
||||
describe('MetaMask', function () {
|
||||
const browser = process.env.SELENIUM_BROWSER
|
||||
let extensionId
|
||||
let driver
|
||||
let tokenAddress
|
||||
@ -33,27 +31,15 @@ describe('MetaMask', function () {
|
||||
this.bail(true)
|
||||
|
||||
before(async function () {
|
||||
switch (process.env.SELENIUM_BROWSER) {
|
||||
case 'chrome': {
|
||||
const extPath = path.resolve('dist/chrome')
|
||||
driver = buildChromeWebDriver(extPath)
|
||||
extensionId = await getExtensionIdChrome(driver)
|
||||
await driver.get(`chrome-extension://${extensionId}/popup.html`)
|
||||
break
|
||||
}
|
||||
case 'firefox': {
|
||||
const extPath = path.resolve('dist/firefox')
|
||||
driver = buildFirefoxWebdriver()
|
||||
await installWebExt(driver, extPath)
|
||||
await delay(700)
|
||||
extensionId = await getExtensionIdFirefox(driver)
|
||||
await driver.get(`moz-extension://${extensionId}/popup.html`)
|
||||
}
|
||||
}
|
||||
const srcPath = path.resolve(`dist/${browser}`)
|
||||
const { extPath } = await createModifiedTestBuild({ browser, srcPath })
|
||||
const installResult = await setupBrowserAndExtension({ browser, extPath })
|
||||
driver = installResult.driver
|
||||
extensionUri = installResult.extensionUri
|
||||
})
|
||||
|
||||
afterEach(async function () {
|
||||
if (process.env.SELENIUM_BROWSER === 'chrome') {
|
||||
if (browser === 'chrome') {
|
||||
const errors = await checkBrowserForConsoleErrors(driver)
|
||||
if (errors.length) {
|
||||
const errorReports = errors.map(err => err.message)
|
||||
|
@ -3,12 +3,15 @@ require('geckodriver')
|
||||
const fs = require('fs')
|
||||
const os = require('os')
|
||||
const path = require('path')
|
||||
const pify = require('pify')
|
||||
const prependFile = pify(require('prepend-file'))
|
||||
const webdriver = require('selenium-webdriver')
|
||||
const Command = require('selenium-webdriver/lib/command').Command
|
||||
const By = webdriver.By
|
||||
|
||||
module.exports = {
|
||||
delay,
|
||||
createModifiedTestBuild,
|
||||
buildChromeWebDriver,
|
||||
buildFirefoxWebdriver,
|
||||
installWebExt,
|
||||
@ -20,6 +23,37 @@ function delay (time) {
|
||||
return new Promise(resolve => setTimeout(resolve, time))
|
||||
}
|
||||
|
||||
async function createModifiedTestBuild ({ browser, srcPath }) {
|
||||
// copy build to test-builds directory
|
||||
const extPath = path.resolve(`test-builds/${browser}`)
|
||||
await fs.ensureDir(extPath)
|
||||
await fs.copy(srcPath, extPath)
|
||||
// inject METAMASK_TEST_CONFIG setting default test network
|
||||
const config = { NetworkController: { provider: { type: 'localhost' } } }
|
||||
await prependFile(`${extPath}/background.js`, `window.METAMASK_TEST_CONFIG=${JSON.stringify(config)};\n`)
|
||||
return { extPath }
|
||||
}
|
||||
|
||||
async function setupBrowserAndExtension ({ browser, extPath }) {
|
||||
let drive, extensionId, extensionUri
|
||||
|
||||
if (browser === 'chrome') {
|
||||
driver = buildChromeWebDriver(extPath)
|
||||
extensionId = await getExtensionIdChrome(driver)
|
||||
extensionUri = `chrome-extension://${extensionId}/popup.html`
|
||||
} else if (browser === 'firefox') {
|
||||
driver = buildFirefoxWebdriver()
|
||||
await installWebExt(driver, extPath)
|
||||
await delay(700)
|
||||
extensionId = await getExtensionIdFirefox(driver)
|
||||
extensionUri = `moz-extension://${extensionId}/popup.html`
|
||||
} else {
|
||||
throw new Error(`Unknown Browser "${browser}"`)
|
||||
}
|
||||
|
||||
return { driver, extensionId, extensionUri }
|
||||
}
|
||||
|
||||
function buildChromeWebDriver (extPath) {
|
||||
const tmpProfile = path.join(os.tmpdir(), fs.mkdtempSync('mm-chrome-profile'));
|
||||
return new webdriver.Builder()
|
||||
|
@ -3,10 +3,8 @@ const mkdirp = require('mkdirp')
|
||||
const path = require('path')
|
||||
const assert = require('assert')
|
||||
const pify = require('pify')
|
||||
const prependFile = pify(require('prepend-file'))
|
||||
const webdriver = require('selenium-webdriver')
|
||||
const { By, Key } = webdriver
|
||||
const { delay, buildChromeWebDriver, buildFirefoxWebdriver, installWebExt, getExtensionIdChrome, getExtensionIdFirefox } = require('./func')
|
||||
const { By, Key } = require('selenium-webdriver')
|
||||
const { delay, createModifiedTestBuild, setupBrowserAndExtension } = require('./func')
|
||||
|
||||
describe('Metamask popup page', function () {
|
||||
const browser = process.env.SELENIUM_BROWSER
|
||||
@ -16,25 +14,11 @@ describe('Metamask popup page', function () {
|
||||
|
||||
before(async function () {
|
||||
const srcPath = path.resolve(`dist/${browser}`)
|
||||
const extPath = path.resolve(`test-builds/${browser}`)
|
||||
await fs.ensureDir(extPath)
|
||||
await fs.copy(srcPath, extPath)
|
||||
const config = { NetworkController: { provider: { type: 'localhost' } } }
|
||||
await prependFile(`${extPath}/background.js`, `window.METAMASK_CONFIG=${JSON.stringify(config)};\n`)
|
||||
const { extPath } = await createModifiedTestBuild({ browser, srcPath })
|
||||
const installResult = await setupBrowserAndExtension({ browser, extPath })
|
||||
driver = installResult.driver
|
||||
extensionUri = installResult.extensionUri
|
||||
|
||||
if (browser === 'chrome') {
|
||||
driver = buildChromeWebDriver(extPath)
|
||||
extensionId = await getExtensionIdChrome(driver)
|
||||
extensionUri = `chrome-extension://${extensionId}/popup.html`
|
||||
} else if (browser === 'firefox') {
|
||||
driver = buildFirefoxWebdriver()
|
||||
await installWebExt(driver, extPath)
|
||||
await delay(700)
|
||||
extensionId = await getExtensionIdFirefox(driver)
|
||||
extensionUri = `moz-extension://${extensionId}/popup.html`
|
||||
} else {
|
||||
throw new Error(`Unknown Browser "${browser}"`)
|
||||
}
|
||||
await driver.get(extensionUri)
|
||||
})
|
||||
|
||||
@ -53,7 +37,6 @@ describe('Metamask popup page', function () {
|
||||
// gather extra data if test failed
|
||||
if (this.currentTest.state === 'failed') {
|
||||
await verboseReportOnFailure(this.currentTest)
|
||||
await delay(1000000)
|
||||
}
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user