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:
88
react/src/generator/lib/fetch.mjs
Normal file
88
react/src/generator/lib/fetch.mjs
Normal file
@@ -0,0 +1,88 @@
|
||||
/**
|
||||
* Schema Fetching
|
||||
*
|
||||
* Fetches djarea and channels schemas from Django management commands.
|
||||
*/
|
||||
|
||||
import { spawn } from 'child_process'
|
||||
import path from 'path'
|
||||
|
||||
/**
|
||||
* Run a Django management command and parse JSON output.
|
||||
*/
|
||||
function runDjangoCommand(source, cwd, command) {
|
||||
const managePath = path.resolve(cwd, source.django.managePath)
|
||||
const manageDir = path.dirname(managePath)
|
||||
|
||||
let cmd, args
|
||||
if (source.django.command) {
|
||||
cmd = source.django.command[0]
|
||||
args = [...source.django.command.slice(1), 'manage.py', command, '--indent', '0']
|
||||
} else {
|
||||
const python = source.django.python || 'python'
|
||||
cmd = python
|
||||
args = [managePath, command, '--indent', '0']
|
||||
}
|
||||
|
||||
const env = source.django.env
|
||||
? { ...process.env, ...source.django.env }
|
||||
: undefined
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const proc = spawn(cmd, args, {
|
||||
cwd: manageDir,
|
||||
stdio: ['ignore', 'pipe', 'pipe'],
|
||||
shell: process.platform === 'win32',
|
||||
env,
|
||||
})
|
||||
|
||||
let stdout = ''
|
||||
let stderr = ''
|
||||
|
||||
proc.stdout.on('data', (data) => { stdout += data.toString() })
|
||||
proc.stderr.on('data', (data) => { stderr += data.toString() })
|
||||
|
||||
proc.on('close', (code) => {
|
||||
if (code !== 0) {
|
||||
reject(new Error(`Django command failed (exit ${code}):\n${stderr}`))
|
||||
return
|
||||
}
|
||||
|
||||
const jsonStart = stdout.indexOf('{')
|
||||
if (jsonStart === -1) {
|
||||
reject(new Error(`No JSON found in Django output:\n${stdout}\n${stderr}`))
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
resolve(JSON.parse(stdout.slice(jsonStart)))
|
||||
} catch (err) {
|
||||
reject(new Error(`Failed to parse JSON from Django:\n${err.message}\n${stdout}`))
|
||||
}
|
||||
})
|
||||
|
||||
proc.on('error', (err) => {
|
||||
reject(new Error(`Failed to spawn Django command: ${err.message}`))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch channels schema from Django.
|
||||
*/
|
||||
export async function fetchChannelsSchema(source, cwd) {
|
||||
if (!source.django) {
|
||||
throw new Error('Channels schema export requires django source configuration')
|
||||
}
|
||||
return runDjangoCommand(source, cwd, 'export_channels_schema')
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch djarea schema from Django.
|
||||
*/
|
||||
export async function fetchDjareaSchema(source, cwd) {
|
||||
if (!source.django) {
|
||||
throw new Error('Djarea schema export requires django source configuration')
|
||||
}
|
||||
return runDjangoCommand(source, cwd, 'export_djarea_schema')
|
||||
}
|
||||
Reference in New Issue
Block a user