Skip to content

Commit

Permalink
fix: test scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
matstyler committed Jul 11, 2024
1 parent 35635e2 commit cce84ba
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ playwright-report
playwright/.cache

### Cypress
wallets/metamask/downloads
wallets/**/downloads

### Synpress

Expand Down
6 changes: 3 additions & 3 deletions examples/new-dawn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions examples/new-dawn/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -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);
},
},
});
8 changes: 4 additions & 4 deletions examples/new-dawn/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions wallets/ethereum-wallet-mock/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineConfig } from 'cypress'
import { installSynpress } from './src/cypress'
import { configureBeforeSynpress } from './src/cypress'

export default defineConfig({
chromeWebSecurity: false,
Expand All @@ -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)
}
}
})
9 changes: 4 additions & 5 deletions wallets/ethereum-wallet-mock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion wallets/ethereum-wallet-mock/src/cypress/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { default as installSynpress } from './utils/installSynpress'
export { default as configureBeforeSynpress } from './utils/configureBeforeSynpress'
export { default as EthereumWalletMock } from './EthereumWalletMock'
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions wallets/metamask/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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)
}
}
})
8 changes: 4 additions & 4 deletions wallets/metamask/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
5 changes: 5 additions & 0 deletions wallets/metamask/src/cypress/support/importMetaMaskWallet.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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()
Expand Down
1 change: 1 addition & 0 deletions wallets/metamask/src/prepareExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit cce84ba

Please sign in to comment.