-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ test(metamask): Run tests in parallel
- Loading branch information
1 parent
c721a58
commit b8a62db
Showing
14 changed files
with
166 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { testWithSynpress } from 'fixtures' | ||
import { connectToDapp, getExtensionId, unlockForFixture } from '../../src' | ||
|
||
import basicSetup from './wallet-setup/basic.setup' | ||
|
||
const test = testWithSynpress(basicSetup, unlockForFixture) | ||
|
||
const { describe, expect } = test | ||
|
||
describe('connectToDapp', () => { | ||
test('should connect wallet to dapp', async ({ context, page }) => { | ||
const extensionId = await getExtensionId(context, 'MetaMask') | ||
|
||
await page.goto('https://metamask.github.io/test-dapp/') | ||
|
||
await page.locator('#connectButton').click() | ||
|
||
await connectToDapp(context, extensionId) | ||
|
||
await expect(page.locator('#accounts')).toHaveText('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { testWithSynpress } from 'fixtures' | ||
import { getExtensionId, unlockForFixture } from '../../src' | ||
|
||
import basicSetup from './wallet-setup/basic.setup' | ||
|
||
const test = testWithSynpress(basicSetup, unlockForFixture) | ||
|
||
const { describe, expect } = test | ||
|
||
describe('getExtensionId', () => { | ||
test('should return the extension id', async ({ context }) => { | ||
const extensionId = await getExtensionId(context, 'MetaMask') | ||
expect(extensionId).toMatch(/^[a-z]{32}$/) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { type BrowserContext, type Page, chromium, test as base } from '@playwright/test' | ||
import { OnboardingPage, prepareExtension } from '../../src' | ||
|
||
const SEED_PHRASE = 'test test test test test test test test test test test junk' | ||
const PASSWORD = 'Tester@1234' | ||
|
||
let sharedContext: BrowserContext | undefined | ||
|
||
const test = base.extend<{ | ||
metamaskPage: Page | ||
}>({ | ||
context: async ({ context: _ }, use) => { | ||
if (sharedContext) { | ||
await use(sharedContext) | ||
|
||
return | ||
} | ||
|
||
const metamaskPath = await prepareExtension() | ||
|
||
// biome-ignore format: the array should not be formatted | ||
const browserArgs = [ | ||
`--disable-extensions-except=${metamaskPath}`, | ||
`--load-extension=${metamaskPath}` | ||
] | ||
|
||
if (process.env.HEADLESS) { | ||
browserArgs.push('--headless=new') | ||
} | ||
|
||
const context = await chromium.launchPersistentContext('', { | ||
headless: false, | ||
args: browserArgs | ||
}) | ||
|
||
try { | ||
await context.waitForEvent('page', { timeout: 5000 }) | ||
} catch { | ||
throw new Error('[FIXTURE] MetaMask extension did not load in time') | ||
} | ||
|
||
sharedContext = context | ||
await use(context) | ||
}, | ||
metamaskPage: async ({ context }, use) => { | ||
const metamaskOnboardingPage = context.pages()[1] as Page | ||
await use(metamaskOnboardingPage) | ||
} | ||
}) | ||
|
||
const { describe, expect } = test | ||
|
||
describe('importWallet', () => { | ||
test('should go through the onboarding flow and import wallet from seed phrase', async ({ metamaskPage }) => { | ||
const onboardingPage = new OnboardingPage(metamaskPage) | ||
|
||
await onboardingPage.importWallet(SEED_PHRASE, PASSWORD) | ||
|
||
await expect(metamaskPage.getByText('Account 1')).toBeVisible() | ||
await expect(metamaskPage.getByText('0xf39...2266')).toBeVisible() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { testWithSynpress } from 'fixtures' | ||
import { UnlockPageSelectors, lock, unlockForFixture } from '../../src' | ||
|
||
import basicSetup from './wallet-setup/basic.setup' | ||
|
||
const test = testWithSynpress(basicSetup, unlockForFixture) | ||
|
||
const { describe, expect } = test | ||
|
||
describe('lock', () => { | ||
test('should lock the wallet', async ({ metamaskPage }) => { | ||
await lock(metamaskPage) | ||
|
||
await expect(metamaskPage.locator(UnlockPageSelectors.submitButton)).toBeVisible() | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { testWithSynpress } from 'fixtures' | ||
import { HomePageSelectors, lock, unlock, unlockForFixture } from '../../src' | ||
|
||
import basicSetup from './wallet-setup/basic.setup' | ||
|
||
const test = testWithSynpress(basicSetup, unlockForFixture) | ||
|
||
const { describe, expect } = test | ||
|
||
describe('unlock', () => { | ||
test('should unlock the wallet', async ({ metamaskPage }) => { | ||
await lock(metamaskPage) | ||
|
||
await unlock(metamaskPage, basicSetup.walletPassword) | ||
|
||
await expect(metamaskPage.locator(HomePageSelectors.logo)).toBeVisible() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { defineWalletSetup } from 'core' | ||
import { importWallet } from './utils/importWallet' | ||
|
||
const SEED_PHRASE = 'test test test test test test test test test test test junk' | ||
|
||
const PASSWORD = 'Tester@1234' | ||
|
||
export default defineWalletSetup(PASSWORD, async (_, walletPage) => { | ||
await importWallet(walletPage, SEED_PHRASE, PASSWORD) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import type { Page } from '@playwright/test' | ||
import { OnboardingPage } from '../../../../src' | ||
|
||
export async function importWallet(walletPage: Page, seedPhrase: string, password: string) { | ||
const onboardingPage = new OnboardingPage(walletPage) | ||
|
||
await onboardingPage.importWallet(seedPhrase, password) | ||
} |