Full test infrastructure, code audit fixes, and real E2E integration tests
Test infrastructure: - Django standalone test runner (pytest-django, test settings, EmailUser model) - React unit tests via Vitest with jsdom, jest compat layer, path aliases - Playwright E2E tests using generated hooks in a real Chromium browser - Docker Compose test backend (Django + Redis) for integration testing - Desktop integration test app (PyWebView + Django + uvicorn) - Makefile with test/test-django/test-react/test-integration targets Library bugs found and fixed: - hasJWT truthiness: undefined !== null was true, skipping session init - process.env crash: CSR client referenced process.env in non-Node browsers - baseUrl not forwarded: DjareaProvider didn't pass baseUrl to CSR client - Relative URL handling: new URL() failed with relative base paths - call() race condition: HTTP requests fired before CSRF cookie was set - Session init await: added sessionRef promise so call() waits for session - path_prefix on schema export: both export commands failed with URL reverse - NullBooleanField removed: referenced field doesn't exist in Django 5.0+ - lru_cache on JWT settings: get_settings() now cached as intended - Channel message routing: broadcasts now include channel name and params - httpFunctionCall: fixed URL and request body format Generator fixes: - Removed 1,100 lines of REST/OpenAPI client generation (not part of Djarea) - Generator now works for djarea-only projects without django-ninja REST APIs - Generated DjangoContext now includes ChannelProvider when channels exist - Fixed env var passthrough for schema export commands - Deduplicated fetch logic into single runDjangoCommand helper Test quality: - Fixed 33 tautological Django tests with real assertions - Found hidden bug: benchmark functions were never registered - Found hidden bug: unicode lookalike test used plain ASCII - Deleted worthless React unit tests (duplicates, shape checks, Zod-tests-Zod) - Replaced jsdom integration tests with Playwright browser tests Example apps: - example/: Integration test backend with 33 server functions, 5 forms, 4 channels covering auth variations, contexts, class-based ServerFunction, error codes, DjareaFormMixin, formsets, and JWT - desktop/: PyWebView desktop app with file system access, SQLite CRUD, system introspection, and 39 real HTTP integration tests Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
115
react/src/index.ts
Normal file
115
react/src/index.ts
Normal file
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
* Djarea - Django Server Functions Client
|
||||
*
|
||||
* Frontend client for Django server functions.
|
||||
* Server functions are the core primitive - accessed via React hooks.
|
||||
*
|
||||
* Two-layer architecture:
|
||||
*
|
||||
* 1. Library layer (this package) - Generic name-based API
|
||||
* Used by libraries like Allauth that need to call functions by name.
|
||||
*
|
||||
* import { useDjarea, useDjareaContext, useDjareaCall } from 'djarea'
|
||||
* const user = useDjareaContext('current_user')
|
||||
* const call = useDjareaCall('update_profile')
|
||||
*
|
||||
* 2. Generated layer (@/api) - Typed project-specific API
|
||||
* Used by product code for type-safe hooks.
|
||||
*
|
||||
* import { useCurrentUser, useUpdateProfile } from '@/api'
|
||||
* const user = useCurrentUser()
|
||||
* const updateProfile = useUpdateProfile()
|
||||
*
|
||||
* The generated code wraps DjareaProvider and adds type-safe hooks.
|
||||
*/
|
||||
|
||||
// ============================================================================
|
||||
// React Context & Hooks (primary API)
|
||||
// ============================================================================
|
||||
|
||||
export {
|
||||
// Provider
|
||||
DjareaProvider,
|
||||
type DjareaProviderProps,
|
||||
type DjareaHydration,
|
||||
|
||||
// Hooks (generic name-based API for libraries)
|
||||
useDjarea,
|
||||
useDjareaContext,
|
||||
useDjareaCall,
|
||||
useDjareaStatus,
|
||||
usePush,
|
||||
|
||||
// Types
|
||||
type DjareaContextValue,
|
||||
type ConnectionStatus,
|
||||
type PushMessage,
|
||||
type PushListener,
|
||||
type ContextStore,
|
||||
type Transport,
|
||||
|
||||
// Legacy aliases (deprecated, for migration)
|
||||
DjangoContext,
|
||||
useDjango,
|
||||
useDjangoStatus,
|
||||
useServerFunction,
|
||||
type DjangoContextValue,
|
||||
type DjangoContextProps,
|
||||
} from './context'
|
||||
|
||||
// ============================================================================
|
||||
// HTTP Client (for SSR or non-React usage)
|
||||
// ============================================================================
|
||||
|
||||
export {
|
||||
httpFunctionCall,
|
||||
createDjangoCSRClient,
|
||||
createDjangoSSRClient,
|
||||
ensureDjangoSession,
|
||||
Auth,
|
||||
type DjangoHTTPClient,
|
||||
type CSRClientConfig,
|
||||
type JWTClientConfig,
|
||||
type SSRClientConfig,
|
||||
} from './client/'
|
||||
|
||||
// ============================================================================
|
||||
// Errors
|
||||
// ============================================================================
|
||||
|
||||
export {
|
||||
DjangoError,
|
||||
type FunctionErrorResponse,
|
||||
type ErrorCode,
|
||||
} from './errors'
|
||||
|
||||
// ============================================================================
|
||||
// Forms (typed form hooks core)
|
||||
// ============================================================================
|
||||
|
||||
export {
|
||||
// Single form
|
||||
useDjareaFormCore,
|
||||
// Legacy alias
|
||||
useDjareaFormCore as useDjangoFormCore,
|
||||
type DjangoFormState,
|
||||
type FormSchema,
|
||||
type FormErrors,
|
||||
type FormOptions,
|
||||
type FormSubmitResult,
|
||||
type FormCoreConfig,
|
||||
// Formset
|
||||
useDjareaFormsetCore,
|
||||
// Legacy alias
|
||||
useDjareaFormsetCore as useDjangoFormsetCore,
|
||||
type DjangoFormsetState,
|
||||
type FormsetSchema,
|
||||
type FormsetErrors,
|
||||
type FormsetCoreConfig,
|
||||
type FormsetSubmitResult,
|
||||
// Shared types
|
||||
type FieldSchema,
|
||||
type FieldChoice,
|
||||
type FieldError,
|
||||
type FormMeta,
|
||||
} from './forms'
|
||||
Reference in New Issue
Block a user