Files
status-web/e2e/global-setup.ts
Jules 99ce990804 feat(e2e): shared infra for extension-based wallet tests
* refactor(e2e): extract shared extension launcher from MetaMask fixture

Move the persistent-context + temp-profile + SW-derived extension-id
logic into launchExtensionContext (with beforeLaunch, afterClose,
extraChromeArgs, profilePrefix, viewport options) so other extensions
can reuse it. MetaMask fixture becomes a thin wrapper; behavior
unchanged for the existing Hub suite.

* feat(e2e): add congestion and balance controls to Anvil helper

Add setNextBlockBaseFee, setBlockGasLimit, disableAutoMining,
dropTransaction, setEthBalanceFor, and getEthBalance for staging
network conditions and localizing accounts on the forks.

* feat(e2e): add rpc-router and opt-in wallet test-server orchestration

Anvil only answers JSON-RPC at / while apps/api appends path suffixes
(/ethereum/mainnet/alchemy), so add a small host-side router that
strips the prefix and forwards by chain segment to the forks.

Wire wallet-send/wallet-swap Playwright projects behind the
RUN_WALLET_E2E env flag (env rather than argv: workers re-evaluate the
config without --project) with apps/api and the router as web servers,
narrow the @wallet grep so it no longer swallows the new tags, and add
setup:wallet / test:wallet-* scripts. setup:wallet passes
WXT_STATUS_API_URL explicitly because wxt build --mode development
otherwise bakes the production API URL.

* chore: add changeset

* ci: point changesets and workflow triggers at master

The main branch was renamed to master, so origin/main no longer exists:
the changeset status step failed to find the divergence point, and the
CI/E2E/Release push triggers never fired.
2026-07-10 18:59:46 +09:00

67 lines
2.3 KiB
TypeScript

import fs from 'node:fs'
import path from 'node:path'
import { loadEnvConfig } from './src/config/env.js'
import { runsHubProjects } from './src/config/test-servers.js'
async function globalSetup(): Promise<void> {
console.log('[global-setup] Validating environment...')
const env = loadEnvConfig()
// Validate MetaMask extension is present
if (!fs.existsSync(env.METAMASK_EXTENSION_PATH)) {
console.warn(
`[global-setup] MetaMask extension not found at: ${env.METAMASK_EXTENSION_PATH}\n` +
`Run "pnpm setup:metamask" to download it.\n` +
`Wallet-dependent tests will fail.`,
)
}
// Warn about missing seed phrase
if (!env.WALLET_SEED_PHRASE) {
console.warn(
'[global-setup] WALLET_SEED_PHRASE is not set. ' +
'Wallet-dependent tests will fail. ' +
'Set it in .env or .env.local.',
)
}
// Ensure output directories exist
const outputDir = path.resolve(import.meta.dirname, 'test-results')
fs.mkdirSync(path.join(outputDir, 'html-report'), { recursive: true })
fs.mkdirSync(path.join(outputDir, 'traces'), { recursive: true })
console.log('[global-setup] Environment validated.')
console.log(`[global-setup] Base URL: ${env.BASE_URL}`)
console.log(
`[global-setup] MetaMask: ${fs.existsSync(env.METAMASK_EXTENSION_PATH) ? 'found' : 'NOT found'}`,
)
// For a local Hub dev server, pre-compile the routes the tests hit so the first
// in-test navigation isn't racing Next's on-demand compile (Playwright's
// webServer only waits for the home route). Runs that don't include Hub
// projects don't start the Hub, so skip it there.
if (runsHubProjects() && /localhost|127\.0\.0\.1/.test(env.BASE_URL)) {
await warmUpRoutes(env.BASE_URL, ['/', '/pre-deposits'])
}
}
/** Hit routes once to trigger dev-server compilation; failures are non-fatal. */
async function warmUpRoutes(baseUrl: string, routes: string[]): Promise<void> {
for (const route of routes) {
const url = new URL(route, baseUrl).toString()
try {
await fetch(url, { redirect: 'follow' })
console.log(`[global-setup] Warmed up ${route}`)
} catch (error) {
console.warn(
`[global-setup] Warm-up failed for ${route}: ` +
`${error instanceof Error ? error.message : error}`,
)
}
}
}
export default globalSetup