Add comprehensive unit tests (Jest + RTL) and Cypress E2E tests — 95%+ coverage#41
Open
devin-ai-integration[bot] wants to merge 2 commits into
Open
Add comprehensive unit tests (Jest + RTL) and Cypress E2E tests — 95%+ coverage#41devin-ai-integration[bot] wants to merge 2 commits into
devin-ai-integration[bot] wants to merge 2 commits into
Conversation
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a complete testing infrastructure to the ecommerce app, going from 0% to 95%+ test coverage.
What's included:
Phase 1 — Testing dependencies:
test,test:watch,test:e2e,cypress:openPhase 2 — Jest configuration:
jest.config.jsusingnext/jestwith CSS module mocking and coverage collectionjest.setup.jswith jest-dom matchersPhase 3 — 17 unit test suites, 93 tests:
context/__tests__/StateContext.test.js— all cart logic (onAdd, onRemove, toggleCartItemQuanitity, incQty, decQty, showCart, reset)components/__tests__/— Footer, Product, HeroBanner, FooterBanner, Layout, Navbar, Cartpages/__tests__/— index (+ getServerSideProps), success, _apppages/product/__tests__/slug.test.jsx— ProductDetails + getStaticPaths/getStaticPropspages/api/__tests__/— stripe handler (POST, 405, error paths), hello handlerlib/__tests__/— client, getStripe (singleton caching), utils (runFireworks confetti)Phase 4 — Cypress E2E tests:
home.cy.js— hero banner, product cards, footer banner, navigationproduct-detail.cy.js— product page navigation, qty increment/decrement, add to cartcart.cy.js— add/remove items, qty controls, empty cart messagecheckout.cy.js— Pay with Stripe flow (API intercept)Coverage results:
Review & Testing Checklist for Human
npm testto verify all 93 unit tests passnpm test -- --coverageto verify 95%+ coverage reportnpm run dev), then runnpx cypress run— note these require Sanity backend data or will rely on interceptsNotes
@testing-library/react@^12(not ^14) due to React 17 peer dependency compatibility--legacy-peer-depsfor npm install due to some peer dep conflictscy.intercept()for the home page Sanity API calls; other E2E tests work against the live appcomponents/index.jsbarrel file shows low coverage (14%) because it's just re-exports — the actual components all have 100% coverageLink to Devin session: https://app.devin.ai/sessions/0c4802d1afb7449dab465fa7b827bcd6
Requested by: @davidbean-hash
Devin Review