mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 18:00:18 +01:00
test:e2e - rework fetch-mocks
This commit is contained in:
parent
581763d510
commit
43007555bd
File diff suppressed because one or more lines are too long
5930
test/e2e/fetch-mocks.json
Normal file
5930
test/e2e/fetch-mocks.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -13,7 +13,7 @@ const {
|
||||
installWebExt,
|
||||
} = require('./func')
|
||||
const { until } = require('selenium-webdriver')
|
||||
const fetchMockResponses = require('./fetch-mocks.js')
|
||||
const fetchMockResponses = require('./fetch-mocks.json')
|
||||
|
||||
const tinyDelayMs = 200
|
||||
const regularDelayMs = tinyDelayMs * 2
|
||||
@ -81,31 +81,36 @@ async function prepareExtensionForTesting () {
|
||||
|
||||
async function setupFetchMocking (driver) {
|
||||
// define fetchMocking script, to be evaluated in the browser
|
||||
function fetchMocking () {
|
||||
function fetchMocking (fetchMockResponses) {
|
||||
window.origFetch = window.fetch.bind(window)
|
||||
window.fetch = async (...args) => {
|
||||
const url = args[0]
|
||||
if (url === 'https://ethgasstation.info/json/ethgasAPI.json') {
|
||||
return { json: async () => JSON.parse(fetchMockResponses.ethGasBasic) }
|
||||
return { json: async () => clone(fetchMockResponses.ethGasBasic) }
|
||||
} else if (url === 'https://ethgasstation.info/json/predictTable.json') {
|
||||
return { json: async () => JSON.parse(fetchMockResponses.ethGasPredictTable) }
|
||||
return { json: async () => clone(fetchMockResponses.ethGasPredictTable) }
|
||||
} else if (url.match(/chromeextensionmm/)) {
|
||||
return { json: async () => JSON.parse(fetchMockResponses.metametrics) }
|
||||
return { json: async () => clone(fetchMockResponses.metametrics) }
|
||||
} else if (url === 'https://dev.blockscale.net/api/gasexpress.json') {
|
||||
return { json: async () => JSON.parse(fetchMockResponses.gasExpress) }
|
||||
return { json: async () => clone(fetchMockResponses.gasExpress) }
|
||||
}
|
||||
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 }
|
||||
}
|
||||
if (window.chrome && window.chrome.webRequest) {
|
||||
window.chrome.webRequest.onBeforeRequest.addListener(cancelInfuraRequest, {urls: ['https://*.infura.io/*']}, ['blocking'])
|
||||
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})()`)
|
||||
await driver.executeScript(`(${fetchMocking})(${fetchMockResponsesJson})`)
|
||||
}
|
||||
|
||||
async function loadExtension (driver, extensionId) {
|
||||
|
@ -30,7 +30,7 @@ describe('MetaMask', function () {
|
||||
const largeDelayMs = regularDelayMs * 2
|
||||
|
||||
this.timeout(0)
|
||||
this.bail(true)
|
||||
// this.bail(true)
|
||||
|
||||
before(async function () {
|
||||
const result = await prepareExtensionForTesting()
|
||||
|
Loading…
Reference in New Issue
Block a user