- Next.js 16 App Router project with Tailwind CSS - Plant disease knowledge base (93 diseases, 25 plants) - Image upload with client+server preprocessing - ML inference pipeline with mock/demo fallback - Responsive results page with disease cards and treatment - Full test suite (285 passing tests)
6.4 KiB
6.4 KiB
07. Test Suite, Vercel Deployment Config, and CI Pipeline
meta: id: hyper-specific-plant-disease-id-07 feature: hyper-specific-plant-disease-id priority: P2 depends_on: [hyper-specific-plant-disease-id-02, hyper-specific-plant-disease-id-05, hyper-specific-plant-disease-id-06] tags: [testing, deployment, ci, qa]
objective:
- Write comprehensive unit and integration tests for all modules, configure Vercel deployment with proper environment variables and build settings, and set up a GitHub Actions CI pipeline that runs on every push.
deliverables:
__tests__/— organized test directory mirroring source structurejest.config.ts— Jest configuration for Next.js with@testing-library/react__tests__/lib/api/diseases.test.ts— knowledge base query tests__tests__/lib/image-processing.test.ts— resize and tensor conversion tests__tests__/lib/ml/inference.test.ts— softmax, confidence calibration, label mapping tests__tests__/components/ImageUpload.test.tsx— upload component interaction tests__tests__/components/DiseaseCard.test.tsx— card expand/collapse and rendering tests__tests__/components/ConfidenceBadge.test.tsx— badge color/label tests__tests__/components/Navbar.test.tsx— navigation and mobile menu tests__tests__/components/SymptomChecker.test.tsx— checklist interaction tests__tests__/pages/homepage.test.tsx— homepage render and element presence__tests__/pages/browse.test.tsx— browse page render and search filter__tests__/pages/results.test.tsx— results page with mock API data__tests__/api/health.test.ts— health endpoint integration test__tests__/api/plants.test.ts— plants API endpoint tests__tests__/api/diseases.test.ts— diseases API endpoint tests__tests__/api/upload.test.ts— upload endpoint with mock file__tests__/api/identify.test.ts— identify endpoint integration test.github/workflows/ci.yml— CI pipeline: lint → test → buildnext.config.js— final configuration for Vercel deploymentvercel.json— deployment config (framework, rewrites, headers, regions)
steps:
- Initialize Jest with
jest.config.ts:- Use
next/jestpreset. - Configure
@testing-library/reactand@testing-library/jest-dom. - Set up
jest.setup.tsfor global mocks (fetch, canvas, File, etc.).
- Use
- Write unit tests for all lib modules:
- Knowledge base queries: search by plant, search by disease, search by text, 404 handling.
- Image processing: resize maintains aspect ratio, tensor shape is correct, normalization range is [0,1].
- ML inference: softmax sums to 1, top-5 extraction, confidence thresholds.
- Write component tests using
@testing-library/react:ImageUpload: simulate drag/drop, file selection, validation errors, upload progress.DiseaseCard: click expands/collapses, content renders.ConfidenceBadge: correct color for each confidence level.SymptomChecker: toggle checkboxes updates counter.Navbar: links render, mobile menu toggles.LoadingSkeleton: renders correct variant and count.ErrorBoundary: catches error and renders fallback.
- Write integration tests for API routes:
- Use
next-test-api-route-handleror Jest with Vercel's test helpers. - Test each endpoint with valid and invalid inputs.
- Test response status codes and body shapes.
- Test error paths (404, 400, 413, 500).
- Use
- Write page integration tests:
- Homepage renders hero, upload CTA, featured plants.
- Browse page renders plant grid, search filters work.
- Results page renders with mock prediction data.
- 404 page shows for unknown routes.
- Create
.github/workflows/ci.yml:name: CI on: [push, pull_request] jobs: ci: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: { node-version: 20 } - run: npm ci - run: npm run lint - run: npm run test -- --coverage - run: npm run build - Finalize
next.config.js:- Enable SWC minification.
- Configure
images.remotePatternsif using external plant photos. - Set
experimental.serverActionsfor any server actions. - Add security headers (CSP, X-Frame-Options, etc.).
- Update
vercel.json:{ "framework": "nextjs", "regions": ["iad1"], "headers": [ { "source": "/(.*)", "headers": [ { "key": "X-Content-Type-Options", "value": "nosniff" }, { "key": "X-Frame-Options", "value": "DENY" }, { "key": "Referrer-Policy", "value": "strict-origin-when-cross-origin" } ]} ], "functions": { "api/identify/route.ts": { "memory": 1024, "maxDuration": 30 } } } - Add
.env.productiontemplate with production values. - Run full test suite and ensure 100% pass rate.
- Perform a dry-run Vercel deploy (
vercel --prod --dry-run) to validate config.
tests:
- All the test files listed in deliverables above — each must pass.
- Code coverage: ≥80% line coverage across lib/, components/, and API routes.
- Lint: ESLint passes with zero errors.
- Build:
next buildcompletes with zero warnings (or documented exceptions).
acceptance_criteria:
npm testpasses all tests (unit + integration + component).npm run buildcompletes successfully.- GitHub Actions CI runs and passes on every push.
- Vercel preview deployment succeeds.
- Code coverage report shows ≥80% across all modules.
- All API endpoints tested for both happy and error paths.
- Security headers present in Vercel response.
validation:
npm run lint # → No errors
npm run test # → All tests passing, coverage report generated
npm run build # → ✓ Compiled successfully
# CI: push to GitHub → Actions tab shows green checkmark
# Vercel: vercel --prod → deployment URL loads homepage
notes:
- Use
jest-canvas-mockfor canvas-dependent tests (image processing). - Use
next-test-api-route-handlerfor API route integration tests without running a full server. - For ML inference tests, mock the model loading and return deterministic fake predictions.
- If Vercel Hobby plan's 10s function timeout is too restrictive for the identify endpoint, consider upgrading or using a Vercel Serverless Function with increased limits.
- Add a
test-assets/directory with small sample plant images used across tests.