From 7e3f1263f21147cae75c1fb69ee36a6e5b7a41c9 Mon Sep 17 00:00:00 2001 From: kumavis Date: Tue, 10 Sep 2019 23:43:41 +0800 Subject: [PATCH] test:e2e - refactor missed spec file --- test/e2e/ethereum-on.spec.js | 62 ++++-------------------------------- 1 file changed, 6 insertions(+), 56 deletions(-) diff --git a/test/e2e/ethereum-on.spec.js b/test/e2e/ethereum-on.spec.js index c9ef38a4a..71ecbd70a 100644 --- a/test/e2e/ethereum-on.spec.js +++ b/test/e2e/ethereum-on.spec.js @@ -19,8 +19,9 @@ const { verboseReportOnFailure, waitUntilXWindowHandles, switchToWindowWithTitle, + setupFetchMocking, + prepareExtensionForTesting, } = require('./helpers') -const fetchMockResponses = require('./fetch-mocks.js') describe('MetaMask', function () { let extensionId @@ -35,61 +36,10 @@ describe('MetaMask', function () { this.bail(true) before(async function () { - let extensionUrl - switch (process.env.SELENIUM_BROWSER) { - case 'chrome': { - const extPath = path.resolve('dist/chrome') - 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"]' + - ');' - ) + const result = await prepareExtensionForTesting() + driver = result.driver + extensionId = result.extensionId + await setupFetchMocking(driver) }) afterEach(async function () {