1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 19:26:13 +02:00

test:e2e - refactor missed spec file

This commit is contained in:
kumavis 2019-09-10 23:43:41 +08:00
parent 17e7b1a8cb
commit d2376ac268

View File

@ -19,8 +19,9 @@ const {
verboseReportOnFailure, verboseReportOnFailure,
waitUntilXWindowHandles, waitUntilXWindowHandles,
switchToWindowWithTitle, switchToWindowWithTitle,
setupFetchMocking,
prepareExtensionForTesting,
} = require('./helpers') } = require('./helpers')
const fetchMockResponses = require('./fetch-mocks.js')
describe('MetaMask', function () { describe('MetaMask', function () {
let extensionId let extensionId
@ -35,61 +36,10 @@ describe('MetaMask', function () {
this.bail(true) this.bail(true)
before(async function () { before(async function () {
let extensionUrl const result = await prepareExtensionForTesting()
switch (process.env.SELENIUM_BROWSER) { driver = result.driver
case 'chrome': { extensionId = result.extensionId
const extPath = path.resolve('dist/chrome') await setupFetchMocking(driver)
driver = buildChromeWebDriver(extPath)
extensionId = await getExtensionIdChrome(driver)
await delay(largeDelayMs)
extensionUrl = `chrome-extension://${extensionId}/home.html`
break
}
case 'firefox': {
const extPath = path.resolve('dist/firefox')
driver = buildFirefoxWebdriver()
await installWebExt(driver, extPath)
await delay(largeDelayMs)
extensionId = await getExtensionIdFirefox(driver)
extensionUrl = `moz-extension://${extensionId}/home.html`
break
}
}
// 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)
})
beforeEach(async function () {
await driver.executeScript(
'window.origFetch = window.fetch.bind(window);' +
'window.fetch = ' +
'(...args) => { ' +
'if (args[0] === "https://ethgasstation.info/json/ethgasAPI.json") { return ' +
'Promise.resolve({ json: () => Promise.resolve(JSON.parse(\'' + fetchMockResponses.ethGasBasic + '\')) }); } else if ' +
'(args[0] === "https://ethgasstation.info/json/predictTable.json") { return ' +
'Promise.resolve({ json: () => Promise.resolve(JSON.parse(\'' + fetchMockResponses.ethGasPredictTable + '\')) }); } else if ' +
'(args[0].match(/chromeextensionmm/)) { return ' +
'Promise.resolve({ json: () => Promise.resolve(JSON.parse(\'' + fetchMockResponses.metametrics + '\')) }); } else if ' +
'(args[0] === "https://dev.blockscale.net/api/gasexpress.json") { return ' +
'Promise.resolve({ json: () => Promise.resolve(JSON.parse(\'' + fetchMockResponses.gasExpress + '\')) }); } ' +
'return window.origFetch(...args); };' +
'function cancelInfuraRequest(requestDetails) {' +
'console.log("Canceling: " + requestDetails.url);' +
'return {' +
'cancel: true' +
'};' +
' }' +
'window.chrome && window.chrome.webRequest && window.chrome.webRequest.onBeforeRequest.addListener(' +
'cancelInfuraRequest,' +
'{urls: ["https://*.infura.io/*"]},' +
'["blocking"]' +
');'
)
}) })
afterEach(async function () { afterEach(async function () {