-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat(test-utils): add test utils improvements #448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Introduced `addPathsToFileNodes` function to recursively add paths to file nodes. - Added `createFileTree` function for generating file tree structures from simplified input formats. - Enhanced `filesRoute` and `fileTreeRoute` handlers to utilize new utilities for path management. - Updated type definitions for better clarity and structure in mock store files.
…ling - Added `@unicode-utils/core` as a dependency for improved path handling. - Updated `well-known.ts` to utilize `addPathsToFileNodes` for better file structure management. - Refactored type definitions in `types.ts` for clarity and consistency.
|
|
Caution Review failedThe pull request is closed. 📝 WalkthroughWalkthroughThis PR enhances the test-utils mock-store by introducing new dependencies, utilities for managing versioned file trees with path augmentation, default Unicode data constants, and refactored handlers for dynamically serving file structures with content and directory listing support. Changes
Sequence DiagramsequenceDiagram
participant Client
participant Handler as Files Handler
participant FileTree as File Tree
participant PathAugment as Path Augmentation
participant ContentOmit as Content Omission
participant Response
Client->>Handler: GET /v15.0.0/ucd/extracted/DerivedBidiClass.txt
Handler->>FileTree: createFileTree(files[version])
FileTree-->>Handler: FileTreeNodeWithContent[]
Handler->>PathAugment: addPathsToFileNodes(nodes, "v15.0.0", "ucd")
PathAugment-->>Handler: MockStoreNodeWithPath[]
Handler->>ContentOmit: omitContentRecursively(nodes)
ContentOmit-->>Handler: MockStoreNode[] (no _content)
Handler->>Handler: findFileByPath() → locate requested file
Handler->>Response: 200 + Content-Length + file data
Response-->>Client: File content with metadata
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly related PRs
Poem
✨ Finishing touches
📜 Recent review detailsConfiguration used: defaults Review profile: CHILL Plan: Pro ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (12)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🌏 Preview DeploymentsNote No deployable apps affected by changes in this PR. Built from commit: 🤖 This comment will be updated automatically when you push new commits to this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces significant improvements to the test-utils package by adding new utility functions for managing mock file stores, enhanced type definitions, and default file content. The changes enable more flexible test file tree creation and better handling of file paths in the mock store API. These changes are extracted from #420 and are expected to cause test failures until other related PRs are merged.
Key Changes:
- Added new utility functions for file tree manipulation (omitContentRecursively, omitChildrenAndContent, addPathsToFileNodes, createFileTree)
- Enhanced type definitions for mock store nodes with optional paths and content
- Implemented comprehensive file/directory request handling in the files handler
- Added default file content for Arabic shaping, bidi brackets, and derived bidi class
Reviewed changes
Copilot reviewed 11 out of 13 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/test-utils/package.json | Added new dependencies: @luxass/utils, @ucdjs/env, @unicode-utils/core |
| pnpm-lock.yaml | Updated lock file to reflect new package dependencies |
| packages/test-utils/src/mock-store/types.ts | Enhanced type definitions with MockStoreNode, MockStoreNodeWithPath, and updated MockStoreFiles |
| packages/test-utils/src/mock-store/utils.ts | Added DeepOmit type utility and helper functions for omitting content/children from nodes |
| packages/test-utils/src/mock-store/add-paths.ts | New utility to recursively add paths to file tree nodes |
| packages/test-utils/src/mock-store/file-tree.ts | New utility for creating file trees from simplified input format |
| packages/test-utils/src/mock-store/index.ts | Updated default file structure to use _content and removed path properties |
| packages/test-utils/src/mock-store/handlers/well-known.ts | Updated to use addPathsToFileNodes for manifest generation |
| packages/test-utils/src/mock-store/handlers/files.ts | Comprehensive rewrite to handle file/directory requests with proper headers |
| packages/test-utils/src/mock-store/handlers/file-tree.ts | Updated to normalize file trees and add paths |
| packages/test-utils/src/mock-store/default-files/*.ts | Added default file content for testing |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Greptile SummaryEnhanced test utilities for mocking UCD store API with improved file tree handling, path management, and default Unicode data files. Adds support for version-prefixed paths and synthetic Key Changes
ArchitectureThe changes improve the mock store's fidelity to the real UCD API by properly handling the synthetic Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Test as Test Suite
participant MockStore as mockStoreApi()
participant FileTree as file-tree handler
participant Files as files handler
participant WellKnown as well-known handler
participant AddPaths as addPathsToFileNodes()
Test->>MockStore: mockStoreApi(config)
activate MockStore
MockStore->>MockStore: Setup default files with mock content
MockStore->>MockStore: Normalize base URL
MockStore->>MockStore: Loop through MOCK_ROUTES
Note over MockStore: For each endpoint, setup handlers
MockStore->>FileTree: setup file-tree handler
activate FileTree
FileTree->>FileTree: Register GET /api/v1/versions/{version}/file-tree
FileTree->>AddPaths: addPathsToFileNodes(nodes, version, "ucd")
AddPaths-->>FileTree: Nodes with paths
FileTree->>FileTree: omitContentRecursively()
FileTree-->>MockStore: Handler registered
deactivate FileTree
MockStore->>Files: setup files handler
activate Files
Files->>Files: Register GET/HEAD /api/v1/files/{wildcard}
Files->>AddPaths: addPathsToFileNodes() for version files
AddPaths-->>Files: Nodes with paths
Files->>Files: findFileByPath() for specific file
Files->>Files: Return file content or directory listing
Files-->>MockStore: Handler registered
deactivate Files
MockStore->>WellKnown: setup well-known handlers
activate WellKnown
WellKnown->>WellKnown: Register GET /.well-known/ucd-config.json
WellKnown->>WellKnown: Register GET /.well-known/ucd-store/{version}.json
WellKnown->>AddPaths: addPathsToFileNodes() for manifest
AddPaths-->>WellKnown: Nodes with paths
WellKnown->>WellKnown: flattenFilePaths() for expectedFiles
WellKnown-->>MockStore: Handlers registered
deactivate WellKnown
MockStore->>MockStore: Register custom responses if provided
deactivate MockStore
Note over Test,WellKnown: Test execution
Test->>Files: GET /api/v1/files/16.0.0/ucd/UnicodeData.txt
activate Files
Files->>Files: Parse wildcard path
Files->>Files: Find file in tree
Files-->>Test: Return file content with headers
deactivate Files
Test->>FileTree: GET /api/v1/versions/16.0.0/file-tree
activate FileTree
FileTree->>FileTree: Get version files
FileTree->>FileTree: Normalize tree (handle synthetic ucd directory)
FileTree-->>Test: Return file tree without _content
deactivate FileTree
|
🔗 Linked issue
📚 Description
This PR apply some test utils modifications from #420, most tests will fail for now. But that is fine, we will fix it in all the other open PRs.
Summary by CodeRabbit
New Features
Chores
✏️ Tip: You can customize this high-level summary in your review settings.