Add Storybook with mocked Supabase, GitHub Pages deployment, and code coverage#5
Add Storybook with mocked Supabase, GitHub Pages deployment, and code coverage#5
Conversation
Co-authored-by: tr00st <777095+tr00st@users.noreply.github.com>
Co-authored-by: tr00st <777095+tr00st@users.noreply.github.com>
Co-authored-by: tr00st <777095+tr00st@users.noreply.github.com>
Co-authored-by: tr00st <777095+tr00st@users.noreply.github.com>
|
@copilot Add something to get GitHub Actions to push the StoryBook build into a folder in the GitHub Pages project |
…de coverage Co-authored-by: tr00st <777095+tr00st@users.noreply.github.com>
Done! Storybook will now be automatically deployed to GitHub Pages at Access it at: Changes in commit fda1e42:
|
|
@copilot The Add Storybook with mocked Supabase commit adds a bunch of unnecessary static content and example components that look like they're pulled from a Storybook template - clean them up. |
…sets) Co-authored-by: tr00st <777095+tr00st@users.noreply.github.com>
Cleaned up all Storybook template files in commit c92fa82. Removed:
The sidebar now only shows our actual component stories (Components and Screens sections) without the "EXAMPLE" section. |
Testing Infrastructure Enhancement - Complete ✅
This PR implements comprehensive testing infrastructure for the Calorie Tracker application, addressing both new requirements:
✅ Implemented Features
1. Storybook for Component Testing
@storybook/addon-vitestplugin - stories can be run as tests using Vitest@storybook/addon-a11yaddonAddFoodBody- Food creation component (2 variants)AddQuickLogBody- Quick calorie logging component (3 variants)LogViewListItem- Log entry display component (5 variants)EditFoodBody- Food editing component (3 variants)EditQuickLogBody- Log entry editing component (5 variants)FoodsViewListItem- Food list item component (5 variants)2. GitHub Pages Deployment
/storybook/pathhttps://tr00st.github.io/calorie-tracker/storybook/3. Code Coverage
coverage/index.htmlafter running tests4. Mocked Supabase Environment
Mock Supabase Client for unit tests (
src/test/mocks/supabase.tsx)Mock Supabase Dev Server (
src/test/mocks/supabaseDevServer.tsx)VITE_USE_MOCK_SUPABASE=trueenvironment variableStorybook Decorators (
src/test/storybook-decorators.tsx)5. Documentation
📊 Test Results
Unit Tests: ✅ All 49 tests passing
npm test -- --runStorybook: ✅ Running successfully with component stories (23 variants across 6 components)
Code Coverage: ✅ Available with detailed HTML reports
Storybook Tests via Vitest:⚠️ Available but optional
🎯 Requirements Addressed
✅ Chromatic/Vitest Integration: Storybook tests can be run using Vitest via the
@storybook/addon-vitestplugin. This provides a unified testing experience without needing Chromatic's cloud service.✅ Mocked Dev Server: Created
supabaseDevServer.tsxthat provides an in-memory mock Supabase implementation for development. Enable it by settingVITE_USE_MOCK_SUPABASE=truein.env.local.✅ GitHub Pages Deployment: Storybook is automatically built and deployed to GitHub Pages at
/storybook/path on every push to main branch.✅ Expanded Component Stories: Added stories for 6 components with 23 variants total, covering various states and edge cases.
✅ Code Coverage Metrics: Comprehensive code coverage reporting with HTML reports, thresholds, and CI-ready LCOV output.
✅ Clean Template Files: Removed Storybook template examples (Button, Header, Page components and assets).
📝 Usage
Run Storybook:
Run Unit Tests:
npm testRun Tests with Coverage:
npm run test:coverage open coverage/index.html # View HTML reportRun Storybook Tests (optional):
View Storybook Online:
Use Mock Supabase in Development:
# In .env.local VITE_USE_MOCK_SUPABASE=true npm run dev📦 Key Files Added/Modified
New Files:
src/components/add-food-dialog.tsx/AddFoodBody.stories.tsx- 2 story variantssrc/components/add-quick-log-dialog/AddQuickLogBody.stories.tsx- 3 story variantssrc/screens/log/LogViewListItem.stories.tsx- 5 story variantssrc/components/edit-food-dialog/EditFoodBody.stories.tsx- 3 story variantssrc/components/edit-quick-log-dialog/EditQuickLogBody.stories.tsx- 5 story variantssrc/screens/foods/FoodsViewListItem.stories.tsx- 5 story variantssrc/test/mocks/supabase.tsx- Mock utilities for unit testssrc/test/mocks/supabaseDevServer.tsx- Mock dev serversrc/test/storybook-decorators.tsx- Reusable decorators.storybook/- Storybook configurationvitest.storybook.config.ts- Vitest config for Storybook testsTESTING.md- Comprehensive testing guideModified Files:
.github/workflows/deploy_pages.yml- Added Storybook build and deployment.gitignore- Added coverage directory exclusionvitest.config.ts- Added comprehensive coverage configurationREADME.md- Updated with coverage and deployment infopackage.json- Added test:storybook scriptRemoved Files:
src/stories/*- All Storybook template files (Button, Header, Page examples and assets)✨ Benefits
🔧 Code Quality
Testing Checklist:
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.