-
-
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): Add E2E test for
prepareExtension
(#915)
- Loading branch information
1 parent
605f8b8
commit dc1f73f
Showing
10 changed files
with
151 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
declare global { | ||
namespace NodeJS { | ||
interface ProcessEnv { | ||
CI: boolean | ||
HEADLESS: boolean | ||
} | ||
} | ||
} | ||
|
||
export {} |
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,36 @@ | ||
import { defineConfig, devices } from '@playwright/test' | ||
|
||
/** | ||
* See https://playwright.dev/docs/test-configuration. | ||
*/ | ||
export default defineConfig({ | ||
// Look for test files in the "tests/e2e" directory, relative to this configuration file. | ||
testDir: './test/e2e', | ||
|
||
// Run all tests in parallel. | ||
// TODO: Enable later once we have more tests. | ||
fullyParallel: false, | ||
|
||
// Fail the build on CI if you accidentally left test.only in the source code. | ||
forbidOnly: !!process.env.CI, | ||
|
||
// Opt out of parallel tests on CI. | ||
workers: process.env.CI ? 1 : undefined, | ||
|
||
// Concise 'dot' for CI, default 'html' when running locally. See https://playwright.dev/docs/test-reporters. | ||
reporter: process.env.CI ? 'dot' : 'html', | ||
|
||
// Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. | ||
use: { | ||
// Collect traces for all failed tests. See https://playwright.dev/docs/trace-viewer. | ||
trace: 'retain-on-failure' | ||
}, | ||
|
||
// Configure projects for major browsers. | ||
projects: [ | ||
{ | ||
name: 'chromium', | ||
use: { ...devices['Desktop Chrome'] } | ||
} | ||
] | ||
}) |
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,45 @@ | ||
import { type Page, chromium, test as base } from '@playwright/test' | ||
import { prepareExtension } from '../../src/prepareExtension' | ||
|
||
const test = base.extend({ | ||
context: async ({ context: _ }, use) => { | ||
const metamaskPath = await prepareExtension() | ||
|
||
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') | ||
} | ||
|
||
await use(context) | ||
}, | ||
page: async ({ context }, use) => { | ||
const metamaskOnboardingPage = context.pages()[1] as Page | ||
await use(metamaskOnboardingPage) | ||
} | ||
}) | ||
|
||
const { describe, expect } = test | ||
|
||
describe('prepareExtension', () => { | ||
test('onboarding page opens up', async ({ page }) => { | ||
await expect(page).toHaveTitle('MetaMask') | ||
await expect( | ||
page.getByRole('heading', { name: "Let's get started" }) | ||
).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
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 |
---|---|---|
@@ -1,10 +1,16 @@ | ||
{ | ||
"extends": "./tsconfig.build.json", | ||
"compilerOptions": { | ||
"rootDir": "." | ||
"rootDir": ".", | ||
"exactOptionalPropertyTypes": false // Allows for `undefined` in `playwright.config.ts` | ||
}, | ||
"include": [ | ||
"src", | ||
"test" | ||
], | ||
"files": [ | ||
"environment.d.ts", | ||
"playwright.config.ts", | ||
"vitest.config.ts", | ||
] | ||
} |
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,7 @@ | ||
import { defineConfig } from 'vitest/config' | ||
|
||
export default defineConfig({ | ||
test: { | ||
dir: 'test/unit' | ||
} | ||
}) |