Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat: Implemented connectToDapp, addNewAccount in Cypress #1181

Merged
merged 17 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ test-results
playwright-report
playwright/.cache

### Cypress
wallets/**/downloads

### Synpress

.cache-synpress
Expand Down
3 changes: 2 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"**/test-results",
"**/playwright-report",
"**/.cache-synpress",
"**/.vitepress/cache"
"**/.vitepress/cache",
"**/downloads"
]
},
"formatter": {
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
4 changes: 2 additions & 2 deletions examples/new-dawn/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { installSynpress } from '@synthetixio/synpress/cypress'
import { configureSynpress } from '@synthetixio/synpress/cypress'
import { defineConfig } from 'cypress'

export default defineConfig({
Expand All @@ -9,7 +9,7 @@ export default defineConfig({
supportFile: 'test/cypress/support/e2e.{js,jsx,ts,tsx}',
testIsolation: false,
async setupNodeEvents(on, config) {
return installSynpress(on, config)
return configureSynpress(on, config)
}
}
})
10 changes: 5 additions & 5 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 All @@ -21,7 +21,7 @@
"devDependencies": {
"@metamask/test-dapp": "8.1.0",
"@types/node": "20.11.17",
"cypress": "13.9.0",
"cypress": "13.13.0",
"serve": "14.2.1",
"typescript": "5.3.3"
}
Expand Down
3 changes: 2 additions & 1 deletion examples/new-dawn/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
"skipLibCheck": true,
"types": ["cypress"]
},
"include": ["test"],
"files": ["environment.d.ts"]
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
57 changes: 55 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions release/src/cypress/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from '@synthetixio/ethereum-wallet-mock/cypress'
export * from '@synthetixio/synpress-metamask/cypress'
2 changes: 1 addition & 1 deletion release/src/playwright/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from '@synthetixio/ethereum-wallet-mock/playwright'
export { MetaMask, getExtensionId, metaMaskFixtures } from '@synthetixio/synpress-metamask'
export * from '@synthetixio/synpress-metamask/playwright'
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 { configureSynpress } 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 configureSynpress(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 configureSynpress } from './utils/configureSynpress'
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 configureSynpress(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
16 changes: 16 additions & 0 deletions wallets/metamask/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { defineConfig } from 'cypress'
import configureSynpress from './src/cypress/configureSynpress'

export default defineConfig({
userAgent: 'synpress',
chromeWebSecurity: true,
e2e: {
baseUrl: 'http://localhost:9999',
specPattern: 'test/cypress/**/*.cy.{js,jsx,ts,tsx}',
supportFile: 'src/cypress/support/e2e.{js,jsx,ts,tsx}',
testIsolation: false,
async setupNodeEvents(on, config) {
return configureSynpress(on, config)
}
}
})
24 changes: 16 additions & 8 deletions wallets/metamask/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
"version": "0.0.1-alpha.7",
"type": "module",
"exports": {
"types": "./types/index.d.ts",
"default": "./dist/index.js"
"./cypress": {
"types": "./types/cypress/index.d.ts",
"default": "./dist/cypress/index.js"
},
"./playwright": {
"types": "./types/playwright/index.d.ts",
"default": "./dist/playwright/index.js"
}
},
"main": "./dist/index.js",
"types": "./types/index.d.ts",
Expand All @@ -15,17 +21,18 @@
],
"scripts": {
"build": "pnpm run clean && pnpm run build:dist && pnpm run build:types",
"build:cache": "synpress-cache test/wallet-setup",
"build:cache:headless": "synpress-cache test/wallet-setup --headless",
"build:cache:headless:force": "synpress-cache test/wallet-setup --headless --force",
"build:cache": "synpress-cache test/playwright/wallet-setup",
"build:cache:headless": "synpress-cache test/playwright/wallet-setup --headless",
"build:cache:headless:force": "synpress-cache test/playwright/wallet-setup --headless --force",
"build:dist": "tsup --tsconfig tsconfig.build.json",
"build:types": "tsc --emitDeclarationOnly --project tsconfig.build.json",
"clean": "rimraf dist types",
"test": "vitest run",
"test:coverage": "vitest run --coverage",
"test:e2e:headful": "playwright test",
"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 All @@ -41,6 +48,7 @@
"@types/fs-extra": "11.0.4",
"@types/node": "20.11.17",
"@vitest/coverage-v8": "1.2.2",
"cypress": "13.13.0",
"rimraf": "5.0.5",
"tsup": "8.0.2",
"typescript": "5.3.3",
Expand Down
2 changes: 1 addition & 1 deletion wallets/metamask/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { defineConfig, devices } from '@playwright/test'
*/
export default defineConfig({
// Look for test files in the "test/e2e" directory, relative to this configuration file.
testDir: './test/e2e',
testDir: './test/playwright/e2e',

// We're increasing the timeout to 60 seconds to allow all traces to be recorded.
// Sometimes it threw an error saying that traces were not recorded in the 30 seconds timeout limit.
Expand Down
11 changes: 11 additions & 0 deletions wallets/metamask/src/cypress/MetaMask.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { lockPage } from '../selectors'
import { MetaMaskAbstract } from '../type/MetaMaskAbstract'

// @ts-ignore
// TODO: To be implemented
export class MetaMask extends MetaMaskAbstract {
unlock() {
cy.get(lockPage.passwordInput).type(this.password)
cy.get(lockPage.submitButton).click()
}
}
Loading
Loading