mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 18:00:18 +01:00
test - e2e - dedupe fetchMocking + compose script as fn
This commit is contained in:
parent
869c83fd2c
commit
3afd69b3ec
@ -17,8 +17,8 @@ const {
|
|||||||
findElements,
|
findElements,
|
||||||
loadExtension,
|
loadExtension,
|
||||||
verboseReportOnFailure,
|
verboseReportOnFailure,
|
||||||
|
setupFetchMocking,
|
||||||
} = require('./helpers')
|
} = require('./helpers')
|
||||||
const fetchMockResponses = require('./fetch-mocks.js')
|
|
||||||
|
|
||||||
describe('MetaMask', function () {
|
describe('MetaMask', function () {
|
||||||
let extensionId
|
let extensionId
|
||||||
@ -63,31 +63,7 @@ describe('MetaMask', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
await driver.executeScript(
|
await setupFetchMocking(driver)
|
||||||
'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 () {
|
||||||
|
@ -16,9 +16,8 @@ const {
|
|||||||
verboseReportOnFailure,
|
verboseReportOnFailure,
|
||||||
findElement,
|
findElement,
|
||||||
findElements,
|
findElements,
|
||||||
|
setupFetchMocking,
|
||||||
} = require('./helpers')
|
} = require('./helpers')
|
||||||
const fetchMockResponses = require('./fetch-mocks.js')
|
|
||||||
|
|
||||||
|
|
||||||
describe('Using MetaMask with an existing account', function () {
|
describe('Using MetaMask with an existing account', function () {
|
||||||
let extensionId
|
let extensionId
|
||||||
@ -66,31 +65,7 @@ describe('Using MetaMask with an existing account', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
await driver.executeScript(
|
await setupFetchMocking(driver)
|
||||||
'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 () {
|
||||||
|
@ -4,6 +4,8 @@ const pify = require('pify')
|
|||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const { delay } = require('./func')
|
const { delay } = require('./func')
|
||||||
const { until } = require('selenium-webdriver')
|
const { until } = require('selenium-webdriver')
|
||||||
|
const fetchMockResponses = require('./fetch-mocks.js')
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
assertElementNotPresent,
|
assertElementNotPresent,
|
||||||
@ -17,6 +19,36 @@ module.exports = {
|
|||||||
switchToWindowWithUrlThatMatches,
|
switchToWindowWithUrlThatMatches,
|
||||||
verboseReportOnFailure,
|
verboseReportOnFailure,
|
||||||
waitUntilXWindowHandles,
|
waitUntilXWindowHandles,
|
||||||
|
setupFetchMocking,
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setupFetchMocking (driver) {
|
||||||
|
// define fetchMocking script, to be evaluated in the browser
|
||||||
|
function fetchMocking() {
|
||||||
|
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 ) }
|
||||||
|
} else if (url === "https://ethgasstation.info/json/predictTable.json") {
|
||||||
|
return { json: async () => JSON.parse( fetchMockResponses.ethGasPredictTable ) }
|
||||||
|
} else if (url.match(/chromeextensionmm/)) {
|
||||||
|
return { json: async () => JSON.parse( fetchMockResponses.metametrics ) }
|
||||||
|
} else if (url === "https://dev.blockscale.net/api/gasexpress.json") {
|
||||||
|
return { json: async () => JSON.parse( fetchMockResponses.gasExpress ) }
|
||||||
|
}
|
||||||
|
return window.origFetch(...args)
|
||||||
|
}
|
||||||
|
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'])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// eval the fetchMocking script in the browser
|
||||||
|
await driver.executeScript(`(${fetchMocking})()`)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadExtension (driver, extensionId) {
|
async function loadExtension (driver, extensionId) {
|
||||||
|
@ -19,8 +19,8 @@ const {
|
|||||||
loadExtension,
|
loadExtension,
|
||||||
openNewPage,
|
openNewPage,
|
||||||
verboseReportOnFailure,
|
verboseReportOnFailure,
|
||||||
|
setupFetchMocking,
|
||||||
} = require('./helpers')
|
} = require('./helpers')
|
||||||
const fetchMockResponses = require('./fetch-mocks.js')
|
|
||||||
|
|
||||||
describe('MetaMask', function () {
|
describe('MetaMask', function () {
|
||||||
let extensionId
|
let extensionId
|
||||||
@ -65,31 +65,7 @@ describe('MetaMask', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
await driver.executeScript(
|
await setupFetchMocking(driver)
|
||||||
'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 () {
|
||||||
|
@ -17,8 +17,8 @@ const {
|
|||||||
findElements,
|
findElements,
|
||||||
loadExtension,
|
loadExtension,
|
||||||
verboseReportOnFailure,
|
verboseReportOnFailure,
|
||||||
|
setupFetchMocking,
|
||||||
} = require('./helpers')
|
} = require('./helpers')
|
||||||
const fetchMockResponses = require('./fetch-mocks.js')
|
|
||||||
|
|
||||||
describe('MetaMask', function () {
|
describe('MetaMask', function () {
|
||||||
let extensionId
|
let extensionId
|
||||||
@ -63,31 +63,7 @@ describe('MetaMask', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
await driver.executeScript(
|
await setupFetchMocking(driver)
|
||||||
'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 () {
|
||||||
|
@ -21,8 +21,8 @@ const {
|
|||||||
switchToWindowWithTitle,
|
switchToWindowWithTitle,
|
||||||
verboseReportOnFailure,
|
verboseReportOnFailure,
|
||||||
waitUntilXWindowHandles,
|
waitUntilXWindowHandles,
|
||||||
|
setupFetchMocking,
|
||||||
} = require('./helpers')
|
} = require('./helpers')
|
||||||
const fetchMockResponses = require('./fetch-mocks.js')
|
|
||||||
|
|
||||||
describe('MetaMask', function () {
|
describe('MetaMask', function () {
|
||||||
let extensionId
|
let extensionId
|
||||||
@ -68,31 +68,7 @@ describe('MetaMask', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
await driver.executeScript(
|
await setupFetchMocking(driver)
|
||||||
'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 () {
|
||||||
|
@ -16,9 +16,8 @@ const {
|
|||||||
verboseReportOnFailure,
|
verboseReportOnFailure,
|
||||||
findElement,
|
findElement,
|
||||||
findElements,
|
findElements,
|
||||||
|
setupFetchMocking,
|
||||||
} = require('./helpers')
|
} = require('./helpers')
|
||||||
const fetchMockResponses = require('./fetch-mocks.js')
|
|
||||||
|
|
||||||
|
|
||||||
describe('Using MetaMask with an existing account', function () {
|
describe('Using MetaMask with an existing account', function () {
|
||||||
let extensionId
|
let extensionId
|
||||||
@ -63,31 +62,7 @@ describe('Using MetaMask with an existing account', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
await driver.executeScript(
|
await setupFetchMocking(driver)
|
||||||
'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 () {
|
||||||
|
@ -19,9 +19,8 @@ const {
|
|||||||
switchToWindowWithTitle,
|
switchToWindowWithTitle,
|
||||||
verboseReportOnFailure,
|
verboseReportOnFailure,
|
||||||
waitUntilXWindowHandles,
|
waitUntilXWindowHandles,
|
||||||
|
setupFetchMocking,
|
||||||
} = require('./helpers')
|
} = require('./helpers')
|
||||||
const fetchMockResponses = require('./fetch-mocks.js')
|
|
||||||
|
|
||||||
|
|
||||||
describe('Using MetaMask with an existing account', function () {
|
describe('Using MetaMask with an existing account', function () {
|
||||||
let extensionId
|
let extensionId
|
||||||
@ -77,31 +76,7 @@ describe('Using MetaMask with an existing account', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
await driver.executeScript(
|
await setupFetchMocking(driver)
|
||||||
'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 () {
|
||||||
|
Loading…
Reference in New Issue
Block a user