From 8eb8fc15910b8aaf8a7e152135bcd628c189698a Mon Sep 17 00:00:00 2001 From: seaona <54408225+seaona@users.noreply.github.com> Date: Tue, 12 Apr 2022 18:33:16 +0200 Subject: [PATCH] Remove unused function (#14423) * Remove unused function * Removed fetch mocks file as it's no longer used --- test/data/fetch-mocks.json | 73 ------------------------------------- test/e2e/webdriver/index.js | 49 ------------------------- 2 files changed, 122 deletions(-) delete mode 100644 test/data/fetch-mocks.json diff --git a/test/data/fetch-mocks.json b/test/data/fetch-mocks.json deleted file mode 100644 index f9b2885f2..000000000 --- a/test/data/fetch-mocks.json +++ /dev/null @@ -1,73 +0,0 @@ -{ - "gasPricesBasic": { - "average": 85, - "fast": 200, - "safeLow": 80 - }, - "metametrics": { - "mockMetaMetricsResponse": true - }, - "swaps": { - "featureFlags": { - "bsc": { - "mobile_active": false, - "extension_active": true, - "fallback_to_v1": true - }, - "ethereum": { - "mobile_active": false, - "extension_active": true, - "fallback_to_v1": true - }, - "polygon": { - "mobile_active": false, - "extension_active": true, - "fallback_to_v1": false - } - } - }, - "tokenList": { - "0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0": { - "address": "0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0", - "symbol": "MATIC", - "decimals": 18, - "name": "Polygon", - "iconUrl": "https://raw.githubusercontent.com/MetaMask/eth-contract-metadata/master/images/matic-network-logo.svg", - "aggregators": [ - "airswapLight", - "bancor", - "coinGecko", - "kleros", - "oneInch", - "paraswap", - "pmm", - "totle", - "zapper", - "zerion", - "zeroEx" - ], - "occurrences": 11 - }, - "0x0d8775f648430679a709e98d2b0cb6250d2887ef": { - "address": "0x0d8775f648430679a709e98d2b0cb6250d2887ef", - "symbol": "BAT", - "decimals": 18, - "name": "Basic Attention Tok", - "iconUrl": "https://s3.amazonaws.com/airswap-token-images/BAT.png", - "aggregators": [ - "airswapLight", - "bancor", - "coinGecko", - "kleros", - "oneInch", - "paraswap", - "pmm", - "totle", - "zapper", - "zerion", - "zeroEx" - ], - "occurrences": 11 - } - } -} diff --git a/test/e2e/webdriver/index.js b/test/e2e/webdriver/index.js index 9753c03fe..13fcbb29f 100644 --- a/test/e2e/webdriver/index.js +++ b/test/e2e/webdriver/index.js @@ -1,5 +1,4 @@ const { Browser } = require('selenium-webdriver'); -const fetchMockResponses = require('../../data/fetch-mocks.json'); const Driver = require('./driver'); const ChromeDriver = require('./chrome'); const FirefoxDriver = require('./firefox'); @@ -12,7 +11,6 @@ async function buildWebDriver({ responsive, port, type } = {}) { extensionId, extensionUrl, } = await buildBrowserWebDriver(browser, { responsive, port, type }); - await setupFetchMocking(seleniumDriver); const driver = new Driver(seleniumDriver, browser, extensionUrl); return { @@ -35,53 +33,6 @@ async function buildBrowserWebDriver(browser, webDriverOptions) { } } -async function setupFetchMocking(driver) { - // define fetchMocking script, to be evaluated in the browser - function fetchMocking(mockResponses) { - window.origFetch = window.fetch.bind(window); - window.fetch = async (...args) => { - const url = args[0]; - // api.metaswap.codefi.network/gasPrices - if ( - url.match(/^http(s)?:\/\/api\.metaswap\.codefi\.network\/gasPrices/u) - ) { - return { json: async () => clone(mockResponses.gasPricesBasic) }; - } else if (url.match(/chromeextensionmm/u)) { - return { json: async () => clone(mockResponses.metametrics) }; - } else if (url.match(/^https:\/\/(swap\.metaswap\.codefi\.network)/u)) { - if (url.match(/featureFlags$/u)) { - return { json: async () => clone(mockResponses.swaps.featureFlags) }; - } - } else if ( - url.match(/^https:\/\/(token-api\.airswap-prod\.codefi\.network)/u) - ) { - if (url.match(/tokens\/1337$/u)) { - return { json: async () => clone(mockResponses.tokenList) }; - } - } - return window.origFetch(...args); - }; - if (window.chrome && window.chrome.webRequest) { - window.chrome.webRequest.onBeforeRequest.addListener( - cancelInfuraRequest, - { urls: ['https://*.infura.io/*'] }, - ['blocking'], - ); - } - function cancelInfuraRequest(requestDetails) { - console.log(`fetchMocking - Canceling request: "${requestDetails.url}"`); - return { cancel: true }; - } - function clone(obj) { - return JSON.parse(JSON.stringify(obj)); - } - } - // fetchMockResponses are parsed last minute to ensure that objects are uniquely instantiated - const fetchMockResponsesJson = JSON.stringify(fetchMockResponses); - // eval the fetchMocking script in the browser - await driver.executeScript(`(${fetchMocking})(${fetchMockResponsesJson})`); -} - module.exports = { buildWebDriver, };