mirror of
https://github.com/luxfi/wallet.git
synced 2026-07-27 03:37:41 +00:00
Copies apps/extension, apps/mobile and 10 pkgs (wallet, ui, config, utilities, sessions, gating, notifications, analytics, eslint-config, prices) into a standalone pnpm workspace. Resolves merge conflict markers in extension and mobile package.json files, strips build artifacts (.wxt, .output, Pods).
45 lines
1.5 KiB
TypeScript
45 lines
1.5 KiB
TypeScript
import os from 'os'
|
|
import path from 'path'
|
|
import { type BrowserContext, chromium } from '@playwright/test'
|
|
|
|
interface CreateExtensionContextOptions {
|
|
/** Prefix for the user data directory (for test isolation) */
|
|
userDataDirPrefix?: string
|
|
}
|
|
|
|
/**
|
|
* Creates a persistent browser context with the extension loaded.
|
|
* Returns both the context and cleanup function.
|
|
*/
|
|
export async function createExtensionContext(options: CreateExtensionContextOptions = {}): Promise<BrowserContext> {
|
|
const { userDataDirPrefix = 'playwright-extension' } = options
|
|
|
|
const extensionPath = path.join(__dirname, '../../build')
|
|
|
|
// Generate a unique user data directory for each test to ensure isolation
|
|
const userDataDir = path.join(
|
|
os.tmpdir(),
|
|
`${userDataDirPrefix}-${Date.now()}-${Math.random().toString(36).substring(7)}`,
|
|
)
|
|
|
|
// CI environments need different args for headless-like behavior
|
|
const isCI = process.env.CI === 'true'
|
|
|
|
const context = await chromium.launchPersistentContext(userDataDir, {
|
|
headless: false, // Chrome extensions require headed mode
|
|
args: [
|
|
`--disable-extensions-except=${extensionPath}`,
|
|
`--load-extension=${extensionPath}`,
|
|
'--no-default-browser-check',
|
|
'--disable-default-apps',
|
|
'--no-sandbox', // Required for CI
|
|
'--disable-setuid-sandbox',
|
|
'--disable-dev-shm-usage', // Overcome limited resource problems in CI
|
|
...(isCI ? ['--disable-gpu', '--disable-software-rasterizer'] : []),
|
|
],
|
|
viewport: { width: 1280, height: 720 },
|
|
})
|
|
|
|
return context
|
|
}
|