Add unit and integration tests for all PaperBlog function units#3
Add unit and integration tests for all PaperBlog function units#3
Conversation
- Add Jest testing infrastructure (jest.config.ts, jest.setup.ts) using next/jest
- Add 61 TypeScript/Jest tests across 6 test files:
- src/__tests__/lib/papers.test.ts: all 7 lib/papers.ts functions
- src/__tests__/components/PaperCard.test.tsx: PaperCard component
- src/__tests__/components/Navbar.test.tsx: Navbar component
- src/__tests__/api/mcp.test.ts: GET manifest + POST with all 5 tools
- src/__tests__/api/papers.test.ts: GET /api/papers (default/date/search/limit)
- src/__tests__/api/papers-id.test.ts: GET /api/papers/[id] (found/not-found)
- Add 54 Python/pytest tests across 2 test files:
- tests/test_fetch_papers.py: parse_arxiv_id, scrape_paper_list, scrape_paper_detail,
summarize_with_openai, summarize_with_hf, generate_summary, build_paper, fetch_html
- tests/test_summarize.py: summarize_with_openai, summarize_with_hf, generate_summary, process_file
- Add pytest.ini, requirements-dev.txt, and npm test script
Co-authored-by: wyfbean <83335052+wyfbean@users.noreply.github.com>
Co-authored-by: wyfbean <83335052+wyfbean@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds an initial automated test suite to PaperBlog, covering the Next.js filesystem-backed paper APIs/components and the Python scraping/summarization scripts, plus the supporting test infrastructure.
Changes:
- Add pytest unit tests for
scripts/fetch_papers.pyandscripts/summarize.py, with all external HTTP/AI calls mocked. - Add Jest + React Testing Library unit tests for
src/lib/papers.ts, key UI components, and Next.js API route handlers. - Add test tooling/configuration (
pytest.ini,requirements-dev.txt, Jest config/setup) and update ignore patterns.
Reviewed changes
Copilot reviewed 13 out of 15 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_fetch_papers.py | Pytest unit tests for fetch/scrape/summarize/build pipeline (network mocked). |
| tests/test_summarize.py | Pytest unit tests for summarize script + file update behavior. |
| src/tests/lib/papers.test.ts | Jest tests for filesystem-backed papers library with fs mocked. |
| src/tests/components/PaperCard.test.tsx | RTL rendering/behavior tests for PaperCard. |
| src/tests/components/Navbar.test.tsx | RTL rendering/conditional link tests for Navbar. |
| src/tests/api/papers.test.ts | Jest tests for GET /api/papers handler with lib mocked. |
| src/tests/api/papers-id.test.ts | Jest tests for GET /api/papers/[id] handler with lib mocked. |
| src/tests/api/mcp.test.ts | Jest tests for MCP manifest + tool execution paths with lib mocked. |
| requirements-dev.txt | Add Python dev test dependencies (pytest + mocking libs). |
| pytest.ini | Configure pytest to discover tests from tests/. |
| package.json | Add Jest scripts and JS/React testing devDependencies. |
| jest.setup.ts | Register @testing-library/jest-dom matchers. |
| jest.config.ts | Add Next.js-based Jest configuration. |
| .gitignore | Ignore Python bytecode and pytest cache artifacts. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import type { Config } from "jest"; | ||
| import nextJest from "next/jest.js"; | ||
|
|
||
| const createJestConfig = nextJest({ | ||
| // Provide the path to your Next.js app to load next.config.js and .env files in your test environment | ||
| dir: "./", | ||
| }); |
There was a problem hiding this comment.
jest.config.ts will be loaded by Jest at startup, but the repo doesn't appear to include a TypeScript config loader (ts-node or esbuild-register). Jest treats these as optional peer deps; without one, npm test may fail before running any tests because it can't evaluate a .ts config file. Fix by adding ts-node (or esbuild-register) to devDependencies, or by converting the config to a JS/CJS config file that Node can load directly.
| "jest": "^30.2.0", | ||
| "jest-environment-jsdom": "^30.2.0", | ||
| "tailwindcss": "^4", | ||
| "ts-jest": "^29.4.6", |
There was a problem hiding this comment.
ts-jest is included in devDependencies, but the Jest config is using next/jest (Babel/SWC-based transforms) and doesn't reference the ts-jest preset/transformer. If it's not intentionally kept for future work, consider removing it to reduce devDependencies and avoid confusion about which transformer is actually in use.
| "ts-jest": "^29.4.6", |
| "dev": "next dev", | ||
| "build": "next build", | ||
| "start": "next start", | ||
| "lint": "eslint" | ||
| "lint": "eslint", | ||
| "test": "jest", | ||
| "test:watch": "jest --watch" |
There was a problem hiding this comment.
PR description states the frontend now has “full test coverage”, but the added Jest suite appears focused on src/lib, src/components, and API routes; key Next.js app routes/pages (e.g. src/app/page.tsx, src/app/archive/page.tsx, src/app/papers/[slug]/page.tsx) still have no tests. Consider either expanding coverage to those app-route modules (especially the generateStaticParams / generateMetadata logic) or adjusting the PR description to avoid implying complete frontend coverage.
No tests existed for any part of the codebase. This adds full test coverage across both the TypeScript/Next.js frontend and the Python scraping/summarization scripts.
TypeScript tests (Jest + React Testing Library) — 61 tests
src/__tests__/lib/papers.test.ts— All 7 functions insrc/lib/papers.tswithfsmocked:getAllDates,getPapersForDate,getLatestPapers,getAllPapers,getPaperById,searchPapers,saveDailyPaperssrc/__tests__/components/PaperCard.test.tsx— Rendering, author overflow, summary/abstract fallback, tags, and all action linkssrc/__tests__/components/Navbar.test.tsx— Navigation links, conditional Archive visibilitysrc/__tests__/api/mcp.test.ts—GETmanifest andPOSTexecution for all 5 MCP tools (get_latest_papers,get_papers_by_date,get_paper_by_id,search_papers,list_dates) with@/lib/papersmockedsrc/__tests__/api/papers.test.ts—GET /api/papersdefault, date filter, search, and limit variantssrc/__tests__/api/papers-id.test.ts—GET /api/papers/[id]found and not-found pathsPython tests (pytest) — 54 tests
tests/test_fetch_papers.py—parse_arxiv_id,scrape_paper_list,scrape_paper_detail,summarize_with_openai,summarize_with_hf,generate_summary,build_paper,fetch_htmltests/test_summarize.py—summarize_with_openai,summarize_with_hf,generate_summary,process_fileOpenAI and HF Inference API calls are fully mocked; no real network traffic is needed.
Infrastructure
jest.config.ts+jest.setup.tsusingnext/jest; API route tests use@jest-environment nodedocblock to get WebRequest/Responseglobalspytest.inipointing attests/requirements-dev.txt(pytest,pytest-mock,requests-mock)npm test/npm run test:watchscripts added topackage.json__pycache__/and.pytest_cache/added to.gitignoreOriginal prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.