diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 10d809f51..319d95c95 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -280,7 +280,7 @@ importers: specifier: 0.0.1-alpha.7 version: link:../../packages/cache '@synthetixio/synpress-core': - specifier: 0.0.1-alpha.7 + specifier: workspace:* version: link:../../packages/core '@viem/anvil': specifier: 0.0.7 diff --git a/wallets/metamask/package.json b/wallets/metamask/package.json index d9b2eed90..ed8776f7e 100644 --- a/wallets/metamask/package.json +++ b/wallets/metamask/package.json @@ -31,7 +31,7 @@ }, "dependencies": { "@synthetixio/synpress-cache": "0.0.1-alpha.7", - "@synthetixio/synpress-core": "0.0.1-alpha.7", + "@synthetixio/synpress-core": "workspace:*", "@viem/anvil": "0.0.7", "fs-extra": "11.2.0", "zod": "3.22.4" diff --git a/wallets/metamask/src/fixtures/metaMaskFixtures.ts b/wallets/metamask/src/fixtures/metaMaskFixtures.ts index 704032741..f5962ce8f 100644 --- a/wallets/metamask/src/fixtures/metaMaskFixtures.ts +++ b/wallets/metamask/src/fixtures/metaMaskFixtures.ts @@ -13,6 +13,8 @@ import { type Anvil, type CreateAnvilOptions, createPool } from '@viem/anvil' import fs from 'fs-extra' import { persistLocalStorage } from '../fixture-actions/persistLocalStorage' +const USECACHE = false; + type MetaMaskFixtures = { _contextPath: string metamask: MetaMask @@ -30,53 +32,58 @@ let _metamaskPage: Page export const metaMaskFixtures = (walletSetup: ReturnType, slowMo = 0) => { return base.extend({ _contextPath: async ({ browserName }, use, testInfo) => { - - const contextPath = await createTempContextDir(browserName, testInfo.testId) + if (USECACHE) { + const contextPath = await createTempContextDir(browserName, testInfo.testId) - await use(contextPath) + await use(contextPath) - const error = await removeTempContextDir(contextPath) - if (error) { - console.error(error) + const error = await removeTempContextDir(contextPath) + if (error) { + console.error(error) + } } }, context: async ({ context: currentContext, _contextPath }, use) => { - const cacheDirPath = path.join(process.cwd(), CACHE_DIR_NAME, walletSetup.hash) - if (!(await fs.exists(cacheDirPath))) { - throw new Error(`Cache for ${walletSetup.hash} does not exist. Create it first!`) - } - - // Copying the cache to the temporary context directory. - await fs.copy(cacheDirPath, _contextPath) - - const metamaskPath = await prepareExtension() - - // We don't need the `--load-extension` arg since the extension is already loaded in the cache. - const browserArgs = [`--disable-extensions-except=${metamaskPath}`] - - if (process.env.HEADLESS) { - browserArgs.push('--headless=new') - - if (slowMo > 0) { - console.warn('[WARNING] Slow motion makes no sense in headless mode. It will be ignored!') + let context + if (USECACHE) { + const cacheDirPath = path.join(process.cwd(), CACHE_DIR_NAME, walletSetup.hash) + if (!(await fs.exists(cacheDirPath))) { + throw new Error(`Cache for ${walletSetup.hash} does not exist. Create it first!`) } + + // Copying the cache to the temporary context directory. + await fs.copy(cacheDirPath, _contextPath) + + const metamaskPath = await prepareExtension() + + // We don't need the `--load-extension` arg since the extension is already loaded in the cache. + const browserArgs = [`--disable-extensions-except=${metamaskPath}`] + + if (process.env.HEADLESS) { + browserArgs.push('--headless=new') + + if (slowMo > 0) { + console.warn('[WARNING] Slow motion makes no sense in headless mode. It will be ignored!') + } + } + + context = await chromium.launchPersistentContext(_contextPath, { + headless: false, + args: browserArgs, + slowMo: process.env.HEADLESS ? 0 : slowMo + }) + + const { cookies, origins } = await currentContext.storageState() + + if (cookies) { + await context.addCookies(cookies) + } + if (origins && origins.length > 0) { + await persistLocalStorage(origins, context) + } + } - - const context = await chromium.launchPersistentContext(_contextPath, { - headless: false, - args: browserArgs, - slowMo: process.env.HEADLESS ? 0 : slowMo - }) - - const { cookies, origins } = await currentContext.storageState() - - if (cookies) { - await context.addCookies(cookies) - } - if (origins && origins.length > 0) { - await persistLocalStorage(origins, context) - } - + if (!context) return; // TODO: This should be stored in a store to speed up the tests. const extensionId = await getExtensionId(context, 'MetaMask')