Skip to content

Add comprehensive testing infrastructure with ~99% coverage#42

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1747943400-add-testing-infrastructure
Open

Add comprehensive testing infrastructure with ~99% coverage#42
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1747943400-add-testing-infrastructure

Conversation

@devin-ai-integration
Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration Bot commented May 22, 2026

Summary

Adds a full testing stack to the ecommerce sample app (which previously had zero test coverage) and achieves 99.41% statement, 97.5% branch, 98.36% function, and 99.33% line coverage.

Testing Infrastructure

  • Jest with jsdom environment for unit/integration tests
  • React Testing Library (@testing-library/react@12 for React 17 compatibility)
  • Playwright for E2E tests
  • Mock setup: CSS modules via identity-obj-proxy, image imports via fileMock, Next.js mocks (router, link, head)
  • Coverage thresholds: 90% for branches, functions, lines, statements

Test Scripts Added

  • npm test — run all unit/integration tests
  • npm run test:coverage — run tests with coverage report
  • npm run test:e2e — run Playwright E2E tests
  • npm run test:all — run both unit and E2E tests

Tests Written (153 tests across 16 suites)

  • Components (7 suites): Cart, Footer, FooterBanner, HeroBanner, Layout, Navbar, Product — rendering, interactions, props, conditional rendering, checkout flow
  • Pages (3 suites): Home (getServerSideProps), Success (cart reset, confetti), Product Detail (getStaticPaths/getStaticProps, quantity controls, add to cart, buy now)
  • API Routes (2 suites): hello (status/response), stripe (session creation, image URL transformation, price conversion, error handling, method validation)
  • Context (1 suite): StateContext — add/remove/toggle cart items, quantity controls, boundary conditions
  • Lib (3 suites): Sanity client initialization + urlFor, Stripe singleton loader, confetti utility timing
  • E2E (4 specs): Homepage, product browsing, cart interactions, success page

Coverage Report

File               | % Stmts | % Branch | % Funcs | % Lines
All files          |   99.41 |     97.5 |   98.36 |   99.33
 components        |     100 |      100 |     100 |     100
 context           |     100 |    91.66 |     100 |     100
 lib               |     100 |      100 |     100 |     100
 pages             |     100 |      100 |     100 |     100
 pages/api         |     100 |      100 |     100 |     100
 pages/product     |      96 |      100 |   88.88 |   95.83

Review & Testing Checklist for Human

  • Run npm run test:coverage locally and verify coverage output matches reported numbers
  • Review mock implementations in __mocks__/ to ensure they accurately represent the modules they replace (next/router, next/link, next/head)
  • Run npm run test:e2e with the dev server to verify E2E tests pass against a real Sanity backend (requires valid .env with Sanity credentials)

Notes

  • Used @testing-library/react@12 for React 17 compatibility (project uses React 17.0.2)
  • --legacy-peer-deps was needed during install due to peer dependency constraints
  • E2E tests require a running dev server with valid Sanity API credentials to pass
  • Lint passes with zero errors (existing warnings in source code are pre-existing)
  • components/index.js and pages/_app.js are excluded from coverage as they are framework re-exports

Link to Devin session: https://app.devin.ai/sessions/d6e354b4057e4d47ba1194093f08c9e6
Requested by: @davidbean-hash


Devin Review

Status Commit
⚪ Not started

Run Devin Review

💡 Connect your GitHub account to enable automatic code reviews.

Open in Devin Review (Staging)

@devin-ai-integration
Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants