2020-05-13 15:29:54 +03:00
|
|
|
// ***********************************************************
|
|
|
|
// This file is processed and loaded automatically before your test files.
|
|
|
|
//
|
|
|
|
// You can read more here:
|
|
|
|
// https://on.cypress.io/configuration
|
|
|
|
// ***********************************************************
|
|
|
|
|
|
|
|
// Import commands.ts using ES2015 syntax:
|
2022-06-14 22:40:52 +03:00
|
|
|
import { injected } from './ethereum'
|
|
|
|
import assert = require('assert')
|
|
|
|
|
2022-09-09 21:54:54 +03:00
|
|
|
import { FeatureFlag } from '../../src/featureFlags/flags/featureFlags'
|
|
|
|
|
2022-06-14 22:40:52 +03:00
|
|
|
declare global {
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
|
|
namespace Cypress {
|
|
|
|
interface ApplicationWindow {
|
|
|
|
ethereum: typeof injected
|
|
|
|
}
|
|
|
|
interface VisitOptions {
|
|
|
|
serviceWorker?: true
|
2022-09-09 21:54:54 +03:00
|
|
|
featureFlags?: Array<FeatureFlag>
|
2022-06-14 22:40:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// sets up the injected provider to be a mock ethereum provider with the given mnemonic/index
|
|
|
|
// eslint-disable-next-line no-undef
|
|
|
|
Cypress.Commands.overwrite(
|
|
|
|
'visit',
|
|
|
|
(original, url: string | Partial<Cypress.VisitOptions>, options?: Partial<Cypress.VisitOptions>) => {
|
|
|
|
assert(typeof url === 'string')
|
|
|
|
|
|
|
|
cy.intercept('/service-worker.js', options?.serviceWorker ? undefined : { statusCode: 404 }).then(() => {
|
|
|
|
original({
|
|
|
|
...options,
|
2022-10-06 23:16:58 +03:00
|
|
|
url: (url.startsWith('/') && url.length > 2 && !url.startsWith('/#') ? `/#${url}` : url) + '?chain=goerli',
|
2022-06-14 22:40:52 +03:00
|
|
|
onBeforeLoad(win) {
|
|
|
|
options?.onBeforeLoad?.(win)
|
|
|
|
win.localStorage.clear()
|
2022-08-16 01:39:16 +03:00
|
|
|
win.localStorage.setItem('redux_localstorage_simple_user', '{"selectedWallet":"INJECTED"}')
|
2022-09-09 21:54:54 +03:00
|
|
|
|
|
|
|
if (options?.featureFlags) {
|
|
|
|
const featureFlags = options.featureFlags.reduce(
|
|
|
|
(flags, flag) => ({
|
|
|
|
...flags,
|
|
|
|
[flag]: 'enabled',
|
|
|
|
}),
|
|
|
|
{}
|
|
|
|
)
|
|
|
|
win.localStorage.setItem('featureFlags', JSON.stringify(featureFlags))
|
|
|
|
}
|
|
|
|
|
2022-06-14 22:40:52 +03:00
|
|
|
win.ethereum = injected
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
)
|
2022-06-14 00:43:58 +03:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
// Infura security policies are based on Origin headers.
|
|
|
|
// These are stripped by cypress because chromeWebSecurity === false; this adds them back in.
|
|
|
|
cy.intercept(/infura.io/, (res) => {
|
|
|
|
res.headers['origin'] = 'http://localhost:3000'
|
|
|
|
res.continue()
|
|
|
|
})
|
|
|
|
})
|
2022-07-18 16:46:31 +03:00
|
|
|
|
|
|
|
Cypress.on('uncaught:exception', (_err, _runnable) => {
|
|
|
|
// returning false here prevents Cypress from
|
|
|
|
// failing the test
|
|
|
|
return false
|
|
|
|
})
|