mirror of
https://github.com/luxfi/extension.git
synced 2026-10-30 16:56:33 +00:00
- Add Playwright test infrastructure with Chrome extension support - Add E2E tests: basic-setup, onboarding-flow, sidebar-loads, wallet-connection - Add test-chrome job that runs after builds in CI - Add test-firefox job with web-ext validation and load test - Add test-safari job with Xcode build for macOS and iOS Simulator - Update workflow to run tests on PRs as well as releases - Add validate:firefox script for local Firefox manifest validation Tests verify: - Extension loads successfully - Background script/service worker initializes - Manifest is valid - Onboarding page opens on install
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import type { BrowserContext, Page } from '@playwright/test'
|
|
import { sleep } from './timing'
|
|
|
|
export async function openExtensionSidebar(context: BrowserContext, extensionId: string): Promise<Page> {
|
|
const sidebarUrl = `chrome-extension://${extensionId}/sidepanel.html`
|
|
const page = await context.newPage()
|
|
await page.goto(sidebarUrl)
|
|
return page
|
|
}
|
|
|
|
export async function waitForBackgroundReady(context: BrowserContext): Promise<void> {
|
|
const maxAttempts = 30
|
|
let attempts = 0
|
|
|
|
while (attempts < maxAttempts) {
|
|
// Check for background pages first
|
|
const backgroundPages = context.backgroundPages()
|
|
if (backgroundPages.length > 0) {
|
|
const background = backgroundPages[0]
|
|
const isReady = await background
|
|
?.evaluate(() => {
|
|
// Check if the window is available (background is ready)
|
|
return typeof window !== 'undefined'
|
|
})
|
|
.catch(() => false)
|
|
|
|
if (isReady) {
|
|
return
|
|
}
|
|
}
|
|
|
|
// Also check for service workers (modern extensions use these)
|
|
const serviceWorkers = context.serviceWorkers()
|
|
if (serviceWorkers.length > 0) {
|
|
// Service workers are ready if they exist
|
|
// We can't evaluate inside them like background pages
|
|
return
|
|
}
|
|
|
|
await sleep(100)
|
|
attempts++
|
|
}
|
|
|
|
throw new Error('Background script failed to initialize within timeout')
|
|
}
|