Split tests into modular files#6
Conversation
Restructure the test suite by removing the large monolithic test/jsondb.test.js and splitting its contents into focused test files. Added new tests under test/cli, test/config, test/doctor, test/package, test/runtime, test/schema, and test/sync, and moved examples.test.js into test/examples/examples.test.js (updated import path). This improves maintainability and clarity by grouping related tests and reducing a single massive test file.
Allow fixtures to be organized in nested folders and propagate context for schema manifest generation. - Discover source files recursively (listSourceFilesInDirectory) and return sorted relative paths. - Derive resource names from fixture basenames (path.basename) so nested paths map to a single resource key. - Enable recursive watching for sourceDir in both the CLI and server watchers so changes in nested folders are picked up. - Pass resource/config/diagnostic/fieldPath context into itemManifest and use renderFieldMap for object items so nested array/object fields are rendered correctly in the schema manifest. - Update README with docs and examples for nested fixture folders, schemaManifest.customizeField usage, sample generated manifest, and related notes (includes mention of schemaOutFile). These changes make it possible to group fixtures by domain (e.g. db/cms/pages.json) while keeping simple resource routes and richer UI metadata in the generated schema manifest.
Introduce REST response formats and fixture-based resource naming strategies. Add config-public utilities (mergeManifest, parseFixturePath, resourceNameFromPath, resource naming strategies), expose them from index, and wire format parsing/rendering into the REST handler (support .json/.md/.html and custom formats, with default json fallback). Add resources.naming and resources.customizeResource handling when resolving source resource names, plus duplicate-resource diagnostics for nested fixtures. Update schema manifest to support customizeResource and mergeManifest-based field/resource customization with non-serializable diagnostics. Update README and types, and add tests for REST formats, mergeManifest, resource naming/customization, and duplicate resource detection.
Introduce a reader pipeline to support custom source formats. Adds config.sources.readers default and example, new types for reader context/results, and built-in readers for JSON/JSONC/CSV/.schema.mjs/.schema.json(.c). Refactor schema loading to use readSourceFile, normalize multi-source results, compute source hashes, and surface structured diagnostics for reader errors and invalid results. Update parseFixturePath to preserve generic extensions. Include README and SPEC docs for Source Readers and extensive tests covering reader behavior, ordering, multi-source returns, and error conditions.
Move schema-related functionality into modular files under src/features/schema (fields, generated, project, relations, resource, sources, validation). Adds robust source reading (CSV/JSON/JSONC/MJS), field inference/normalization, resource building, relation validation, seed normalization/id generation, and schema validation/constraints. Refactors src/schema.js to delegate to these new modules and centralizes generation of REST/GraphQL metadata and diagnostics to improve maintainability and testability.
Split the monolithic CLI and several core modules into smaller, focused files and feature namespaces. The top-level src/cli.js now delegates to src/cli/index.js (runCli) and command handlers under src/cli/commands (create, doctor, generate, schema, serve, sync, types), plus args and output helpers. Many implementation files were moved/rewired into features/ and shared/ (runtime, config, schema, sync, csv, db, doctor, generate/hono, integrations, etc.) with re-exports to preserve original public API surface. This refactor improves modularity, testability and maintainability while preserving backward-compatible imports.
Add a pluggable runtime system and event hub, replacing direct JSON state handling with runtime adapters. Implements createRuntime and built-in adapters (json, memory, static) plus atomic file writes and in-memory behavior; introduces createRuntimeEventHub for live event streaming. Refactor JsonDbCollection/JsonDbDocument/JsonFixtureDb to use the runtime adapters and emit runtime events on successful writes. Move JSON I/O and atomic write logic into src/features/storage/json.js and add memory/static adapters and tests. Add HTTP feature registry (including SSE runtime log and graphql handler) and wire it into the server with a /__jsondb/log endpoint. Add generator registry for CLI generate command and modularized schema metadata generation. Update default config to include runtime options and TypeScript definitions to expose runtime APIs and events. Add tests covering atomic write, runtimes, static read-only behavior, and live event emission.
Introduce a new 'source' runtime adapter that reads/writes plain JSON fixture files and exposes source-file persistence and live events. The adapter enforces writable JSON-backed resources, reuses json runtime state helpers, and populates source metadata for sync. Integrate the adapter into builtin runtimes, update syncJsonFixtureDb to hydrate the runtime and write source metadata, and simplify openJsonFixtureDb hydration logic. Also: update types to include 'source', make server and source discovery ignore dot-folders inside db, add tests for source writes and dot-folder ignoring, and add related utility functions. Removed legacy allResourcesUseDefaultJsonRuntime logic.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (108)
📝 WalkthroughWalkthroughThis PR undergoes a major architectural refactoring, extracting monolithic modules into a feature-organized structure under ChangesCore Architectural Reorganization & Feature Addition
Sequence Diagram(s)sequenceDiagram
participant CLI
participant ConfigLoader
participant SourceReaders
participant SchemaBuilder
participant RuntimeAdapter
participant HTTPServer
CLI->>ConfigLoader: loadConfig(options)
ConfigLoader->>ConfigLoader: Parse --cwd, --config
ConfigLoader->>ConfigLoader: Merge defaults + user config
CLI->>SourceReaders: Discover & read sources from db/
SourceReaders->>SourceReaders: Custom readers run first
SourceReaders->>SourceReaders: Fall back to built-in readers
SourceReaders->>SchemaBuilder: Return schema/data sources
SchemaBuilder->>SchemaBuilder: Build resources from sources
SchemaBuilder->>SchemaBuilder: Validate relations & seeds
SchemaBuilder->>SchemaBuilder: Generate schema metadata
CLI->>RuntimeAdapter: Create runtime (json/memory/source/static)
RuntimeAdapter->>RuntimeAdapter: Hydrate resources
RuntimeAdapter->>RuntimeAdapter: Emit versioned events on writes
HTTPServer->>HTTPServer: Register HTTP feature registry
HTTPServer->>HTTPServer: preMock: runtime-log feature
HTTPServer->>HTTPServer: postMock: GraphQL feature
HTTPServer->>HTTPServer: Handle REST with format negotiation
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
|
Restructure the test suite by removing the large monolithic test/jsondb.test.js and splitting its contents into focused test files. Added new tests under test/cli, test/config, test/doctor, test/package, test/runtime, test/schema, and test/sync, and moved examples.test.js into test/examples/examples.test.js (updated import path). This improves maintainability and clarity by grouping related tests and reducing a single massive test file.
Summary by CodeRabbit
New Features
Documentation