Skip to content

Add comprehensive test suite and improve Expo integration#3

Merged
andyfischer merged 4 commits intomainfrom
claude/evaluate-prism-expo-0dO5C
Apr 6, 2026
Merged

Add comprehensive test suite and improve Expo integration#3
andyfischer merged 4 commits intomainfrom
claude/evaluate-prism-expo-0dO5C

Conversation

@andyfischer
Copy link
Copy Markdown
Contributor

Summary

This PR adds a complete test suite for the prism-framework-expo package and improves the Expo integration with better documentation, error handling, and developer experience features.

Key Changes

Testing Infrastructure

  • Added vitest configuration and test suite covering:
    • ExpoSqliteDatabase — database operations (get, list, run, close, schema initialization)
    • ExpoEventEmitter — event subscription/publishing with proper cleanup
    • createExpoFetch — endpoint routing, parameter handling, error normalization
    • expoLaunch — app initialization, database setup, middleware warnings, job startup
    • usePrismApp — React hook for async initialization with loading/error states
    • Full integration test with real SQLite operations via better-sqlite3 mock

Core Improvements

  • Database Injection: expoLaunch() now accepts pre-created ExpoSqliteDatabase instances, allowing endpoints to close over the same database reference (fixes a critical pattern for mobile apps)
  • Error Handling Parity: HttpError exceptions from callEndpoint() are now normalized to match webFetch error format ("Fetch error, status: N")
  • Request Context: createExpoFetch() now wraps calls in withRequestContext() so endpoints can access auth via getCurrentRequestContext()
  • Auth Support: Added getAuth option to both expoLaunch() and createExpoFetch() for providing authorization data on each request
  • Migration Support: Added migrateSchema() method to ExpoSqliteDatabase for tracking applied migrations (safer for app updates)

New Exports

  • ExpoEventEmitter — in-process event emitter (mobile equivalent of SSE)
  • usePrismApp — React hook for managing async initialization in Expo layouts
  • Authorization re-exported from core for mobile auth patterns

Documentation & Examples

  • Updated creating-mobile-apps.md with modern patterns (database injection, React hooks, auth)
  • Updated README.md with clearer setup examples and API documentation
  • Added sample Expo app structure:
    • _layout.tsx — demonstrates usePrismApp hook integration
    • prismSetup.ts — app and database initialization
    • notesService.ts — platform-agnostic service with database access
    • NotesScreen.tsx — React Native component using apiFetch

Implementation Details

  • ExpoEventEmitter uses Map<string, Set<callback>> for efficient key-based event routing with automatic cleanup
  • ExpoSqliteDatabase.migrateSchema() uses SHA-256 hashing of statements to track migrations
  • Test suite includes a createExpoSQLiteMock() wrapper around better-sqlite3 to simulate expo-sqlite's synchronous API
  • All tests use vitest with proper cleanup (temp directories, database connections)

Breaking Changes

None — all changes are additive or improve existing behavior.

https://claude.ai/code/session_0181oRm3itxnkB6WVZMjer4U

claude and others added 4 commits April 5, 2026 00:55
expoLaunch() now accepts pre-created ExpoSqliteDatabase instances so
endpoint handlers can close over the same db reference. Updated dependency
to ^0.6.0 for /core subpath. Added 22 unit tests and a sample app
demonstrating the recommended bootstrap pattern.

https://claude.ai/code/session_0181oRm3itxnkB6WVZMjer4U
- Error handling parity: HttpErrors normalized to webFetch format
- Auth context: getAuth option on createExpoFetch and expoLaunch
- ExpoEventEmitter: in-process SSE equivalent with key-based subscriptions
- usePrismApp() React hook for async initialization lifecycle
- migrateSchema(): tracks applied statements for safe app updates
- shutdown() on ExpoLaunchResult for clean database closing
- Dev warning when host option passed to expoFetch
- Integration tests with real SQLite via better-sqlite3
- Added Authorization export to prism-framework/core
- Sample Expo app with full project structure
- 48 tests total (unit, integration, React hook)

https://claude.ai/code/session_0181oRm3itxnkB6WVZMjer4U
@andyfischer andyfischer merged commit 2787469 into main Apr 6, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants