feat: vitest#7
Conversation
✅ Deploy Preview for unocss-inspector ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull Request Overview
This PR adds Vitest testing infrastructure and improves error handling throughout the codebase. The changes include:
- Setting up Vitest with configuration for testing Vue components and composables
- Adding comprehensive error handling with try-catch blocks in critical functions
- Improving type safety by replacing
anytypes with proper TypeScript types - Updating dependencies to newer versions
Reviewed Changes
Copilot reviewed 16 out of 18 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| vitest.config.ts | Adds Vitest configuration with Vue support, happy-dom environment, and coverage settings |
| pnpm-workspace.yaml | Updates dependency versions and adds test-related packages to catalog |
| package.json | Adds test dependencies and updates package manager version |
| packages/unplugin/src/index.ts | Adds error handling to HTML transformation and file loading operations |
| packages/unplugin/src/core/options.ts | Replaces any type with proper Component type from Vue |
| packages/unplugin/scripts/copy-from-inspector.ts | Improves error handling by replacing any with unknown |
| packages/inspector/src/composables/exports/element.ts | Adds try-catch error handling to triggering and style-setting functions |
| packages/inspector/src/composables/classList.ts | Wraps classList update logic in try-catch block |
| packages/inspector/src/composables/attributes.ts | Adds error handling to attribute update function |
| packages/inspector/src/components/panels/InlineStyles.vue | Adds proper type interface for VNode elements |
| packages/inspector/src/components/panels/DomTree.vue | Replaces any cast with proper `HTMLElement |
| packages/inspector/src/components.d.ts | Adds TypeScript declaration for Vue SFC imports |
| packages/inspector/src/Inspector.vue | Adds comprehensive error handling to all event handlers and UI operations |
| packages/inspector/tests/** | Adds test suites for composables and components |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
| catch (error) { | ||
| console.error('[UnoCSS Inspector] Failed to start selecting:', error) | ||
| stopSelecting() |
There was a problem hiding this comment.
In the startSelecting function's catch block, calling stopSelecting() could potentially throw another error and mask the original error. The catch block at line 97-100 should handle errors more defensively. Consider wrapping stopSelecting() in its own try-catch or ensuring it cannot throw.
| stopSelecting() | |
| try { | |
| stopSelecting() | |
| } catch (stopError) { | |
| console.error('[UnoCSS Inspector] Failed to stop selecting after startSelecting error:', stopError) | |
| } |
| } | ||
| catch (error) { | ||
| console.error('[UnoCSS Inspector] Error in handleClick:', error) | ||
| stopSelecting() |
There was a problem hiding this comment.
In the handleClick function's catch block, calling stopSelecting() could potentially throw another error and mask the original error. The catch block at line 157-160 should handle errors more defensively. Consider wrapping stopSelecting() in its own try-catch or ensuring it cannot throw.
| stopSelecting() | |
| try { | |
| stopSelecting() | |
| } | |
| catch (stopError) { | |
| console.error('[UnoCSS Inspector] Error in stopSelecting (called from handleClick catch):', stopError) | |
| } |
| y: Math.max(0, Math.min(newY, windowHeight.value - controlSize)), | ||
| catch (error) { | ||
| console.error('[UnoCSS Inspector] Error in handleControlDrag:', error) | ||
| stopControlDrag() |
There was a problem hiding this comment.
In the handleControlDrag function's catch block, calling stopControlDrag() could potentially throw another error and mask the original error. The catch block at line 210-213 should handle errors more defensively. Consider wrapping stopControlDrag() in its own try-catch or ensuring it cannot throw.
| stopControlDrag() | |
| try { | |
| stopControlDrag() | |
| } catch (stopError) { | |
| console.error('[UnoCSS Inspector] Error in stopControlDrag during handleControlDrag error handling:', stopError) | |
| } |
No description provided.