From cce84ba203a00af0f577d4554492eacf807ac160 Mon Sep 17 00:00:00 2001 From: matstyler Date: Thu, 11 Jul 2024 13:57:17 +0200 Subject: [PATCH] fix: test scripts --- .github/workflows/test.yml | 2 +- .gitignore | 2 +- examples/new-dawn/README.md | 6 +++--- examples/new-dawn/cypress.config.ts | 18 +++++++++--------- examples/new-dawn/package.json | 8 ++++---- package.json | 4 ++-- turbo.json | 4 ++-- wallets/ethereum-wallet-mock/cypress.config.ts | 4 ++-- wallets/ethereum-wallet-mock/package.json | 9 ++++----- .../ethereum-wallet-mock/src/cypress/index.ts | 2 +- ...lSynpress.ts => configureBeforeSynpress.ts} | 2 +- wallets/metamask/cypress.config.ts | 4 ++-- wallets/metamask/package.json | 8 ++++---- ...lSynpress.ts => configureBeforeSynpress.ts} | 2 +- .../cypress/support/importMetaMaskWallet.ts | 5 +++++ wallets/metamask/src/prepareExtension.ts | 1 + 16 files changed, 43 insertions(+), 38 deletions(-) rename wallets/ethereum-wallet-mock/src/cypress/utils/{installSynpress.ts => configureBeforeSynpress.ts} (85%) rename wallets/metamask/src/cypress/{installSynpress.ts => configureBeforeSynpress.ts} (87%) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 30dd8c25e..c9b123047 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -67,7 +67,7 @@ jobs: - name: Run E2E tests (headful) run: | - xvfb-run pnpm run test:e2e:headful + xvfb-run pnpm run test:playwright:headful - name: Archive Playwright report uses: actions/upload-artifact@v3 diff --git a/.gitignore b/.gitignore index 8cd3a9a0d..564fad603 100644 --- a/.gitignore +++ b/.gitignore @@ -38,7 +38,7 @@ playwright-report playwright/.cache ### Cypress -wallets/metamask/downloads +wallets/**/downloads ### Synpress diff --git a/examples/new-dawn/README.md b/examples/new-dawn/README.md index 102ae8257..c89dc3e13 100644 --- a/examples/new-dawn/README.md +++ b/examples/new-dawn/README.md @@ -66,9 +66,9 @@ pnpm run build:cache:headless ```bash # Use one of our scripts: -pnpm run test:e2e:headful -pnpm run test:e2e:headless -pnpm run test:e2e:headless:ui +pnpm run test:playwright:headful +pnpm run test:playwright:headless +pnpm run test:playwright:headless:ui # Or use Playwright directly: playwright test diff --git a/examples/new-dawn/cypress.config.ts b/examples/new-dawn/cypress.config.ts index 8c9cd8242..9b20f18f4 100644 --- a/examples/new-dawn/cypress.config.ts +++ b/examples/new-dawn/cypress.config.ts @@ -1,15 +1,15 @@ -import { installSynpress } from '@synthetixio/synpress/cypress' -import { defineConfig } from 'cypress' +import { configureBeforeSynpress } from "@synthetixio/synpress/cypress"; +import { defineConfig } from "cypress"; export default defineConfig({ chromeWebSecurity: false, e2e: { - baseUrl: 'http://localhost:9999', - specPattern: 'test/cypress/**/*.cy.{js,jsx,ts,tsx}', - supportFile: 'test/cypress/support/e2e.{js,jsx,ts,tsx}', + baseUrl: "http://localhost:9999", + specPattern: "test/cypress/**/*.cy.{js,jsx,ts,tsx}", + supportFile: "test/cypress/support/e2e.{js,jsx,ts,tsx}", testIsolation: false, async setupNodeEvents(on, config) { - return installSynpress(on, config) - } - } -}) + return configureBeforeSynpress(on, config); + }, + }, +}); diff --git a/examples/new-dawn/package.json b/examples/new-dawn/package.json index 4a828a533..4d5d04e5c 100644 --- a/examples/new-dawn/package.json +++ b/examples/new-dawn/package.json @@ -8,10 +8,10 @@ "build:cache:force": "synpress --force", "build:cache:headless": "synpress --headless", "serve:test-dapp": "serve node_modules/@metamask/test-dapp/dist -p 9999", - "test:e2e:headful": "playwright test", - "test:e2e:headful:cypress": "cypress run --browser chrome --headed", - "test:e2e:headless": "HEADLESS=true playwright test", - "test:e2e:headless:ui": "HEADLESS=true playwright test --ui" + "test:cypress:headful": "cypress run --browser chrome --headed", + "test:playwright:headful": "playwright test", + "test:playwright:headless": "HEADLESS=true playwright test", + "test:playwright:headless:ui": "HEADLESS=true playwright test --ui" }, "dependencies": { "@playwright/test": "1.44.0", diff --git a/package.json b/package.json index d8639d08e..b50630817 100644 --- a/package.json +++ b/package.json @@ -15,8 +15,8 @@ "sort-package-json": "sort-package-json 'package.json' '{packages,wallets,examples}/*/package.json'", "sort-package-json:check": "sort-package-json 'package.json' '{packages,wallets,examples}/*/package.json' --check", "test": "turbo test", - "test:e2e:headful": "turbo test:e2e:headful --filter=@synthetixio/synpress-metamask --filter=@synthetixio/ethereum-wallet-mock", - "test:e2e:headless": "turbo test:e2e:headless --filter=@synthetixio/synpress-metamask --filter=@synthetixio/ethereum-wallet-mock", + "test:playwright:headful": "turbo test:playwright:headful --filter=@synthetixio/synpress-metamask --filter=@synthetixio/ethereum-wallet-mock", + "test:playwright:headless": "turbo test:playwright:headless --filter=@synthetixio/synpress-metamask --filter=@synthetixio/ethereum-wallet-mock", "update:deps": "ncu -u -ws --root" }, "lint-staged": { diff --git a/turbo.json b/turbo.json index df889c5a7..58c44315a 100644 --- a/turbo.json +++ b/turbo.json @@ -11,10 +11,10 @@ "build:cache": { "dependsOn": ["build"] }, - "test:e2e:headful": { + "test:playwright:headful": { "dependsOn": ["build", "build:cache"] }, - "test:e2e:headless": { + "test:playwright:headless": { "dependsOn": ["build", "build:cache"] }, "docs:build": { diff --git a/wallets/ethereum-wallet-mock/cypress.config.ts b/wallets/ethereum-wallet-mock/cypress.config.ts index e57319d60..bbb872aac 100644 --- a/wallets/ethereum-wallet-mock/cypress.config.ts +++ b/wallets/ethereum-wallet-mock/cypress.config.ts @@ -1,5 +1,5 @@ import { defineConfig } from 'cypress' -import { installSynpress } from './src/cypress' +import { configureBeforeSynpress } from './src/cypress' export default defineConfig({ chromeWebSecurity: false, @@ -10,7 +10,7 @@ export default defineConfig({ fixturesFolder: 'src/cypress/fixtures', testIsolation: false, async setupNodeEvents(on, config) { - return installSynpress(on, config) + return configureBeforeSynpress(on, config) } } }) diff --git a/wallets/ethereum-wallet-mock/package.json b/wallets/ethereum-wallet-mock/package.json index 99dd7fef6..c65ec236b 100644 --- a/wallets/ethereum-wallet-mock/package.json +++ b/wallets/ethereum-wallet-mock/package.json @@ -26,11 +26,10 @@ "build:dist": "tsup --tsconfig tsconfig.build.json", "build:types": "tsc --emitDeclarationOnly --project tsconfig.build.json", "clean": "rimraf dist types", - "test:e2e:headful": "playwright test", - "test:e2e:headful:cypress": "cypress run --browser chrome --headed", - "test:e2e:headless": "HEADLESS=true playwright test", - "test:e2e:headless:cypress": "cypress run --headless --browser chrome", - "test:e2e:headless:ui": "HEADLESS=true playwright test --ui", + "test:cypress:headful": "cypress run --browser chrome --headed", + "test:playwright:headful": "playwright test", + "test:playwright:headless": "HEADLESS=true playwright test", + "test:playwright:headless:ui": "HEADLESS=true playwright test --ui", "test:watch": "vitest watch", "types:check": "tsc --noEmit" }, diff --git a/wallets/ethereum-wallet-mock/src/cypress/index.ts b/wallets/ethereum-wallet-mock/src/cypress/index.ts index 8360764af..31cddcda6 100644 --- a/wallets/ethereum-wallet-mock/src/cypress/index.ts +++ b/wallets/ethereum-wallet-mock/src/cypress/index.ts @@ -1,2 +1,2 @@ -export { default as installSynpress } from './utils/installSynpress' +export { default as configureBeforeSynpress } from './utils/configureBeforeSynpress' export { default as EthereumWalletMock } from './EthereumWalletMock' diff --git a/wallets/ethereum-wallet-mock/src/cypress/utils/installSynpress.ts b/wallets/ethereum-wallet-mock/src/cypress/utils/configureBeforeSynpress.ts similarity index 85% rename from wallets/ethereum-wallet-mock/src/cypress/utils/installSynpress.ts rename to wallets/ethereum-wallet-mock/src/cypress/utils/configureBeforeSynpress.ts index 95dea8fd4..2ea15a399 100644 --- a/wallets/ethereum-wallet-mock/src/cypress/utils/installSynpress.ts +++ b/wallets/ethereum-wallet-mock/src/cypress/utils/configureBeforeSynpress.ts @@ -4,7 +4,7 @@ import { initEthereumWalletMock } from './initEthereumWalletMock' let port: number -export default function installSynpress(on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions) { +export default function configureBeforeSynpress(on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions) { const browsers = config.browsers.filter((b) => b.name === 'chrome') if (browsers.length === 0) { throw new Error('No Chrome browser found in the configuration') diff --git a/wallets/metamask/cypress.config.ts b/wallets/metamask/cypress.config.ts index bee56d649..5a15e82e4 100644 --- a/wallets/metamask/cypress.config.ts +++ b/wallets/metamask/cypress.config.ts @@ -1,5 +1,5 @@ import { defineConfig } from 'cypress' -import installSynpress from './src/cypress/installSynpress' +import configureBeforeSynpress from './src/cypress/configureBeforeSynpress' export default defineConfig({ chromeWebSecurity: false, @@ -9,7 +9,7 @@ export default defineConfig({ supportFile: 'src/cypress/support/e2e.{js,jsx,ts,tsx}', testIsolation: false, async setupNodeEvents(on, config) { - return installSynpress(on, config) + return configureBeforeSynpress(on, config) } } }) diff --git a/wallets/metamask/package.json b/wallets/metamask/package.json index 7a1d8ae94..6499255af 100644 --- a/wallets/metamask/package.json +++ b/wallets/metamask/package.json @@ -29,10 +29,10 @@ "clean": "rimraf dist types", "test": "vitest run", "test:coverage": "vitest run --coverage", - "test:e2e:headful": "playwright test", - "test:e2e:headful:cypress": "cypress run --browser chrome --headed", - "test:e2e:headless": "HEADLESS=true playwright test", - "test:e2e:headless:ui": "HEADLESS=true playwright test --ui", + "test:cypress:headful": "cypress run --browser chrome --headed", + "test:playwright:headful": "playwright test", + "test:playwright:headless": "HEADLESS=true playwright test", + "test:playwright:headless:ui": "HEADLESS=true playwright test --ui", "test:watch": "vitest watch", "types:check": "tsc --noEmit" }, diff --git a/wallets/metamask/src/cypress/installSynpress.ts b/wallets/metamask/src/cypress/configureBeforeSynpress.ts similarity index 87% rename from wallets/metamask/src/cypress/installSynpress.ts rename to wallets/metamask/src/cypress/configureBeforeSynpress.ts index 8c37620d8..95a730cd0 100644 --- a/wallets/metamask/src/cypress/installSynpress.ts +++ b/wallets/metamask/src/cypress/configureBeforeSynpress.ts @@ -4,7 +4,7 @@ import { initMetaMask } from './support/initMetaMask' let port: number -export default function installSynpress(on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions) { +export default function configureBeforeSynpress(on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions) { const browsers = config.browsers.filter((b) => b.name === 'chrome') if (browsers.length === 0) { throw new Error('No Chrome browser found in the configuration') diff --git a/wallets/metamask/src/cypress/support/importMetaMaskWallet.ts b/wallets/metamask/src/cypress/support/importMetaMaskWallet.ts index 449a45057..7a7dff271 100644 --- a/wallets/metamask/src/cypress/support/importMetaMaskWallet.ts +++ b/wallets/metamask/src/cypress/support/importMetaMaskWallet.ts @@ -1,5 +1,6 @@ import { type BrowserContext, type Page, chromium } from '@playwright/test' import { importWallet } from '../../playwright/pages/OnboardingPage/actions' +import { onboardingPage } from '../../selectors' const SEED_PHRASE = 'test test test test test test test test test test test junk' @@ -14,9 +15,13 @@ export default async function importMetaMaskWallet(port: number) { const context = browser.contexts()[0] as BrowserContext + await context.waitForEvent('response') + // First page (index equal 0) is the cypress page, second one (index equal 1) is the extension page const extensionPage = context.pages()[1] as Page + await extensionPage.waitForSelector(onboardingPage.GetStartedPageSelectors.termsOfServiceCheckbox) + await importWallet(extensionPage, SEED_PHRASE, 'password') await extensionPage.close() diff --git a/wallets/metamask/src/prepareExtension.ts b/wallets/metamask/src/prepareExtension.ts index 94e66cd44..955a2001e 100644 --- a/wallets/metamask/src/prepareExtension.ts +++ b/wallets/metamask/src/prepareExtension.ts @@ -11,6 +11,7 @@ export async function prepareExtension(forceCache = true) { outputDir = ensureCacheDirExists() } else { outputDir = path.resolve('./', 'downloads') + outputDir = process.platform === 'win32' ? `file:\\\\\\${outputDir}` : outputDir if (!(await fs.exists(outputDir))) { fs.mkdirSync(outputDir)