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:
|
2023-03-27 19:48:02 +03:00
|
|
|
import '@cypress/code-coverage/support'
|
2022-06-14 22:40:52 +03:00
|
|
|
|
2023-04-25 02:00:04 +03:00
|
|
|
import assert from 'assert'
|
|
|
|
|
2022-09-09 21:54:54 +03:00
|
|
|
import { FeatureFlag } from '../../src/featureFlags/flags/featureFlags'
|
2023-04-25 02:00:04 +03:00
|
|
|
import { injected } from './ethereum'
|
2022-09-09 21:54:54 +03:00
|
|
|
|
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-12-20 22:54:56 +03:00
|
|
|
selectedWallet?: string
|
|
|
|
noWallet?: boolean
|
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,
|
2023-03-06 21:14:26 +03:00
|
|
|
url:
|
|
|
|
(url.startsWith('/') && url.length > 2 && !url.startsWith('/#') ? `/#${url}` : url) +
|
|
|
|
`${url.includes('?') ? '&' : '?'}chain=goerli`,
|
2022-06-14 22:40:52 +03:00
|
|
|
onBeforeLoad(win) {
|
|
|
|
options?.onBeforeLoad?.(win)
|
|
|
|
win.localStorage.clear()
|
2022-12-20 23:36:57 +03:00
|
|
|
|
|
|
|
const userState = {
|
|
|
|
selectedWallet: options?.noWallet !== true ? options?.selectedWallet || 'INJECTED' : undefined,
|
|
|
|
fiatOnrampDismissed: true,
|
2022-12-20 22:54:56 +03:00
|
|
|
}
|
2022-12-20 23:36:57 +03:00
|
|
|
win.localStorage.setItem('redux_localstorage_simple_user', JSON.stringify(userState))
|
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'
|
2023-02-16 00:55:35 +03:00
|
|
|
res.alias = res.body.method
|
2022-06-14 00:43:58 +03:00
|
|
|
res.continue()
|
|
|
|
})
|
2022-12-13 19:43:02 +03:00
|
|
|
|
|
|
|
// Graphql security policies are based on Origin headers.
|
|
|
|
// These are stripped by cypress because chromeWebSecurity === false; this adds them back in.
|
|
|
|
cy.intercept('https://api.uniswap.org/v1/graphql', (res) => {
|
|
|
|
res.headers['origin'] = 'https://app.uniswap.org'
|
|
|
|
res.continue()
|
|
|
|
})
|
|
|
|
cy.intercept('https://beta.api.uniswap.org/v1/graphql', (res) => {
|
|
|
|
res.headers['origin'] = 'https://app.uniswap.org'
|
|
|
|
res.continue()
|
|
|
|
})
|
2022-06-14 00:43:58 +03:00
|
|
|
})
|
2022-07-18 16:46:31 +03:00
|
|
|
|
2022-12-21 02:08:20 +03:00
|
|
|
Cypress.on('uncaught:exception', () => {
|
|
|
|
// returning false here prevents Cypress from failing the test
|
2022-07-18 16:46:31 +03:00
|
|
|
return false
|
|
|
|
})
|