create-fedi-app

Testing

Test Fedi mini apps with mock WebLN and Nostr providers, Vitest unit tests, and Playwright e2e specs.

Fedi APIs only exist inside the wallet WebView. The scaffold provides mock providers and test infrastructure so you can CI without Fedi installed.

Mock providers

Fedi Dev Toolbar

Available in NODE_ENV=development only. Fixed bottom-right panel:

ToggleEffect
Mock WebLNInjects MockWebLNProvider into WebLNProvider
Mock NostrInjects MockNostrProvider into NostrProvider
fail: ON/OFFMockWebLN throws on payment
mock npubOverride mock Nostr public key display

MockWebLNProvider

import { MockWebLNProvider } from '@/lib/webln/mock';

const mock = new MockWebLNProvider({
  paymentDelay: 600,
  shouldFail: false,
});
MethodMock behavior
enable()Resolves unless shouldFail
sendPayment()Returns random 32-byte hex preimage after delay
makeInvoice()Returns fake lnbc... string
signMessage()Returns random 64-byte hex signature
getInfo()Returns "Fedi Dev Node" alias

MockNostrProvider

Uses deterministic test keypair (privkey 0x00...01). Signs events with real @noble/curves schnorr — valid cryptography, not a secure key.

import { MockNostrProvider } from '@/lib/nostr/mock';
const mock = new MockNostrProvider();
const pk = await mock.getPublicKey(); // always same test pubkey

Dev API bypasses

Modules include development shortcuts:

HeaderEffect
x-mock-preimage: devSkip WebLN payment verification on API routes

Used in payment-gated and ai-chat-gated verify endpoints. Stripped in production via NODE_ENV checks.

Vitest

Base template includes Vitest configuration:

bun test

Example unit test (hooks/__tests__/usePaymentFlow.test.tsx in webln-payments module):

import { renderHook, act } from '@testing-library/react';
import { MockWebLNProvider } from '@/lib/webln/mock';

// Wrap in WebLNProvider with mockProvider prop
const { result } = renderHook(() => usePaymentFlow(), { wrapper });

await act(async () => {
  const ok = await result.current.payExisting('lnbc100n1test');
  expect(ok).toBe(true);
});

vitest.setup.ts configures jsdom and testing-library matchers.

Playwright e2e

webln-payments module includes tests/e2e/webln-payment.spec.ts:

bunx playwright test

E2e tests run against localhost:3000 with mock providers enabled via dev toolbar or direct provider injection.

Testing checklist

ScenarioHow to test
Pay button UIMock WebLN in browser, click Pay
Payment gate cookiePay → verify → refresh protected route
Nostr connectMock Nostr, check npub display
Publish noteMock sign, check relay publish (mock relay or test relay)
AI chat gateMock preimage header on API
fediInternal v2Requires real Fedi — no mock available
Deny manageInstalledMiniAppsOpen /demo/ecash — no toast on load; tap Load → Deny + Remember → permission hint shows
Grant manageInstalledMiniAppsTap Load installed apps → Allow → list renders (or empty state)

CI recommendations

# GitHub Actions example
- run: bun install
- run: bun run typecheck
- run: bun run lint
- run: bun test
- run: bun run build

Skip Playwright in CI unless you start a dev server — or use @playwright/test webServer config.

Real device testing

Mocks validate logic; Fedi validates integration:

  1. Deploy preview URL (Vercel) or use ngrok on localhost
  2. Add URL as custom mini app in Fedi
  3. Test on Mutinynet with test sats
  4. Verify real preimages against your Lightning node

See Deployment for preview URLs.

On this page