Fix component registry initialization for coverage tests#330
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
… setup Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
|
✅ All checks passed!
|
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
📦 Bundle Size Report
Size Limits
|
There was a problem hiding this comment.
Pull request overview
Fixes CI coverage failures caused by an uninitialized component registry by ensuring a single, shared Vitest setup runs for all test modes (including coverage) and that workspace package imports resolve correctly during tests.
Changes:
- Switched all Vitest configs to use the root
vitest.setup.tsxand removed the old rootvitest.setup.ts. - Added/expanded Vite/Vitest
resolve.aliasentries across the repo so@object-ui/*packages resolve to workspace source during tests. - Updated a couple of field widgets and a test file (non-registry-related changes).
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| vitest.setup.tsx | Centralized test setup: side-effect imports to register components + ResizeObserver polyfill. |
| vitest.setup.ts | Removed legacy root setup file now replaced by .tsx. |
| vitest.config.mts | Points setup to vitest.setup.tsx and adds missing @object-ui/* aliases for test resolution. |
| packages/plugin-timeline/vite.config.ts | Aligns test setup file path and adds workspace aliases for tests/build. |
| packages/plugin-markdown/vite.config.ts | Aligns test setup file path and adds workspace aliases for tests/build. |
| packages/plugin-kanban/vite.config.ts | Aligns test setup file path and adds workspace aliases for tests/build. |
| packages/plugin-grid/vite.config.ts | Updates aliases to point at package source dirs + uses root setup .tsx. |
| packages/plugin-form/vite.config.ts | Updates aliases to point at package source dirs + uses root setup .tsx. |
| packages/plugin-editor/vite.config.ts | Aligns test setup file path and adds workspace aliases for tests/build. |
| packages/plugin-charts/vite.config.ts | Aligns test setup file path and adds workspace aliases for tests/build. |
| packages/plugin-aggrid/vite.config.ts | Aligns test setup file path and adds workspace aliases for tests/build. |
| packages/fields/vite.config.ts | Adds aliases (including self-alias) and uses root vitest.setup.tsx for tests. |
| packages/fields/src/widgets/ObjectField.tsx | Changes internal JSON string initialization/sync behavior for the ObjectField widget. |
| packages/fields/src/widgets/BooleanField.tsx | Replaces randomized id generation with useId() for BooleanField. |
| packages/fields/src/standard-widgets.test.tsx | Minor cleanup in a widget test. |
| packages/components/vite.config.ts | Adds aliases (including self-alias) and uses root vitest.setup.tsx for tests. |
| apps/console/vite.config.ts | Points console tests at the root vitest.setup.tsx instead of a local setup file. |
| // Fallback if internal state was invalid JSON | ||
| // eslint-disable-next-line react-hooks/set-state-in-effect -- Required for controlled component sync | ||
| setJsonString(JSON.stringify(value, null, 2)); | ||
| } | ||
| }, [value]); | ||
| }, [value, jsonString]); |
There was a problem hiding this comment.
The effect depends on jsonString and also calls setJsonString(...). This makes the sync effect run on every keystroke, and when the user temporarily types invalid JSON (so value doesn’t update), the catch path will immediately reset the textarea back to JSON.stringify(value, ...), preventing users from correcting invalid intermediate states and potentially causing extra renders.
Consider making this effect run only when value changes (and explicitly opting out of exhaustive-deps), or refactor to avoid reading jsonString from the effect dependency list (e.g., keep a ref of the last successfully-parsed value/string) so local editing isn’t overwritten.
| import React, { useId } from 'react'; | ||
| import { Switch, Checkbox, Label } from '@object-ui/components'; | ||
| import { FieldWidgetProps } from './types'; | ||
|
|
||
| export function BooleanField({ value, onChange, field, readonly, ...props }: FieldWidgetProps<boolean>) { | ||
| if (readonly) { | ||
| return <span className="text-sm">{value ? 'Yes' : 'No'}</span>; | ||
| } | ||
|
|
||
| const config = (field || (props as any).schema) as any; | ||
| // Use simple type assertion for arbitrary custom properties not in BaseFieldMetadata | ||
| const widget = config?.widget; | ||
| const id = config?.name || `boolean-field-${Math.random().toString(36).substr(2, 9)}`; | ||
| // Generate unique ID using React's useId hook - must be before early returns (rules of hooks) | ||
| const generatedId = useId(); | ||
| const id = config?.name || generatedId; | ||
| const label = config?.label || 'Checkbox'; |
There was a problem hiding this comment.
This PR is described as fixing component registry initialization for coverage tests, but it also changes runtime field widget behavior (ObjectField state sync logic and BooleanField id generation). These look orthogonal to the test/registry issue and make the change set harder to reason about/revert.
If they’re not strictly required to fix the coverage failure, consider moving the widget changes into a separate PR (or explicitly calling out why they’re needed here).
CI coverage tests were failing with "Unknown component type: div" in
ServerDefinitions.test.tsxbecause the root vitest setup wasn't registering components.Changes
vitest.setup.ts→vitest.setup.tsxand added component registration imports (@object-ui/components,@object-ui/fields, plugins)vitest.config.mtswith missing aliases (@object-ui/core,@object-ui/types,@object-ui/react, field/plugin packages)apps/console/vite.config.tsto reference root setup; removed redundantapps/console/vitest.setup.tsxThe root setup file now handles component registration for all test runs (both regular and coverage), ensuring the component registry is populated before tests execute.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.