|
|
@ -1,11 +1,23 @@ |
|
|
|
const fs = require('fs') |
|
|
|
const fs = require('fs') |
|
|
|
|
|
|
|
const path = require('path') |
|
|
|
const mkdirp = require('mkdirp') |
|
|
|
const mkdirp = require('mkdirp') |
|
|
|
const pify = require('pify') |
|
|
|
const pify = require('pify') |
|
|
|
const assert = require('assert') |
|
|
|
const assert = require('assert') |
|
|
|
const { delay } = require('./func') |
|
|
|
|
|
|
|
|
|
|
|
const { |
|
|
|
|
|
|
|
delay, |
|
|
|
|
|
|
|
getExtensionIdChrome, |
|
|
|
|
|
|
|
getExtensionIdFirefox, |
|
|
|
|
|
|
|
buildChromeWebDriver, |
|
|
|
|
|
|
|
buildFirefoxWebdriver, |
|
|
|
|
|
|
|
installWebExt, |
|
|
|
|
|
|
|
} = require('./func') |
|
|
|
const { until } = require('selenium-webdriver') |
|
|
|
const { until } = require('selenium-webdriver') |
|
|
|
const fetchMockResponses = require('./fetch-mocks.js') |
|
|
|
const fetchMockResponses = require('./fetch-mocks.js') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const tinyDelayMs = 200 |
|
|
|
|
|
|
|
const regularDelayMs = tinyDelayMs * 2 |
|
|
|
|
|
|
|
const largeDelayMs = regularDelayMs * 2 |
|
|
|
|
|
|
|
|
|
|
|
module.exports = { |
|
|
|
module.exports = { |
|
|
|
assertElementNotPresent, |
|
|
|
assertElementNotPresent, |
|
|
@ -20,6 +32,47 @@ module.exports = { |
|
|
|
verboseReportOnFailure, |
|
|
|
verboseReportOnFailure, |
|
|
|
waitUntilXWindowHandles, |
|
|
|
waitUntilXWindowHandles, |
|
|
|
setupFetchMocking, |
|
|
|
setupFetchMocking, |
|
|
|
|
|
|
|
prepareExtensionForTesting, |
|
|
|
|
|
|
|
tinyDelayMs, |
|
|
|
|
|
|
|
regularDelayMs, |
|
|
|
|
|
|
|
largeDelayMs, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function prepareExtensionForTesting () { |
|
|
|
|
|
|
|
let driver, extensionId, extensionUrl |
|
|
|
|
|
|
|
const targetBrowser = process.env.SELENIUM_BROWSER |
|
|
|
|
|
|
|
switch (targetBrowser) { |
|
|
|
|
|
|
|
case 'chrome': { |
|
|
|
|
|
|
|
const extPath = path.resolve('dist/chrome') |
|
|
|
|
|
|
|
driver = buildChromeWebDriver(extPath, { responsive: true }) |
|
|
|
|
|
|
|
await delay(largeDelayMs) |
|
|
|
|
|
|
|
extensionId = await getExtensionIdChrome(driver) |
|
|
|
|
|
|
|
extensionUrl = `chrome-extension://${extensionId}/home.html` |
|
|
|
|
|
|
|
break |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
case 'firefox': { |
|
|
|
|
|
|
|
const extPath = path.resolve('dist/firefox') |
|
|
|
|
|
|
|
driver = buildFirefoxWebdriver({ responsive: true }) |
|
|
|
|
|
|
|
await installWebExt(driver, extPath) |
|
|
|
|
|
|
|
await delay(largeDelayMs) |
|
|
|
|
|
|
|
extensionId = await getExtensionIdFirefox(driver) |
|
|
|
|
|
|
|
extensionUrl = `moz-extension://${extensionId}/home.html` |
|
|
|
|
|
|
|
break |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
default: { |
|
|
|
|
|
|
|
throw new Error(`prepareExtensionForTesting - unable to prepare extension for unknown browser "${targetBrowser}"`) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Depending on the state of the application built into the above directory (extPath) and the value of
|
|
|
|
|
|
|
|
// METAMASK_DEBUG we will see different post-install behaviour and possibly some extra windows. Here we
|
|
|
|
|
|
|
|
// are closing any extraneous windows to reset us to a single window before continuing.
|
|
|
|
|
|
|
|
const [tab1] = await driver.getAllWindowHandles() |
|
|
|
|
|
|
|
await closeAllWindowHandlesExcept(driver, [tab1]) |
|
|
|
|
|
|
|
await driver.switchTo().window(tab1) |
|
|
|
|
|
|
|
await driver.get(extensionUrl) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { driver, extensionId, extensionUrl } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async function setupFetchMocking (driver) { |
|
|
|
async function setupFetchMocking (driver) { |
|
|
@ -28,13 +81,13 @@ async function setupFetchMocking (driver) { |
|
|
|
window.origFetch = window.fetch.bind(window) |
|
|
|
window.origFetch = window.fetch.bind(window) |
|
|
|
window.fetch = async (...args) => { |
|
|
|
window.fetch = async (...args) => { |
|
|
|
const url = args[0] |
|
|
|
const url = args[0] |
|
|
|
if (url === "https://ethgasstation.info/json/ethgasAPI.json") { |
|
|
|
if (url === 'https://ethgasstation.info/json/ethgasAPI.json') { |
|
|
|
return { json: async () => JSON.parse(fetchMockResponses.ethGasBasic) } |
|
|
|
return { json: async () => JSON.parse(fetchMockResponses.ethGasBasic) } |
|
|
|
} else if (url === "https://ethgasstation.info/json/predictTable.json") { |
|
|
|
} else if (url === 'https://ethgasstation.info/json/predictTable.json') { |
|
|
|
return { json: async () => JSON.parse(fetchMockResponses.ethGasPredictTable) } |
|
|
|
return { json: async () => JSON.parse(fetchMockResponses.ethGasPredictTable) } |
|
|
|
} else if (url.match(/chromeextensionmm/)) { |
|
|
|
} else if (url.match(/chromeextensionmm/)) { |
|
|
|
return { json: async () => JSON.parse(fetchMockResponses.metametrics) } |
|
|
|
return { json: async () => JSON.parse(fetchMockResponses.metametrics) } |
|
|
|
} else if (url === "https://dev.blockscale.net/api/gasexpress.json") { |
|
|
|
} else if (url === 'https://dev.blockscale.net/api/gasexpress.json') { |
|
|
|
return { json: async () => JSON.parse(fetchMockResponses.gasExpress) } |
|
|
|
return { json: async () => JSON.parse(fetchMockResponses.gasExpress) } |
|
|
|
} |
|
|
|
} |
|
|
|
return window.origFetch(...args) |
|
|
|
return window.origFetch(...args) |
|
|
|