test: add automated test suite for backend and frontend (#820)#833
Open
Rudra-clrscr wants to merge 3 commits into
Open
test: add automated test suite for backend and frontend (#820)#833Rudra-clrscr wants to merge 3 commits into
Rudra-clrscr wants to merge 3 commits into
Conversation
…4#820) - Add Jest+Supertest coverage for the Express /predict proxy route (success, timeout, connection-refused, and upstream 4xx/5xx cases). Uncovered a real bug in the process: routes/predictionRoutes.js used require("./middleware/cacheMiddleware") with a wrong relative path, throwing on every real /predict call right before contacting Flask and making the endpoint always fail with a 503 in production. - Fix frontend/src/pages/App.jsx, which did not compile: a duplicate `function App() {` declaration left over from a bad merge, an unclosed div, a reference to an undefined `analyzeEmojis` (should be `analyzeEmojiSentiment`) that would crash on every rendered result, invalid <button> nested inside <button> in the tab bar, and a dead import of a nonexistent module path. - Fix a stray non-JS line at the top of ManipulationIndex.jsx that also broke the production build. - Add Vitest + React Testing Library and a minimal test for the prediction form (disabled-until-input state, successful submission, and error-with-retry rendering). - Document how to run the Python, Node, and frontend test suites in CONTRIBUTING.md. The existing Python pytest suite under backend/tests/ already covered /predict input validation, edge cases, and explanations, so no new Python tests were needed for that acceptance criterion.
|
Someone is attempting to deploy a commit to the Aditya Sharma's projects Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Pull request overview
Adds automated test coverage across the Node/Express backend and React frontend (closing #820), and includes a few targeted fixes to unblock production builds and make the /predict flow testable/reliable.
Changes:
- Added Jest + Supertest coverage for the Node
/predictproxy route (success + error mapping scenarios). - Added Vitest + React Testing Library with a minimal prediction-form test suite and shared test setup.
- Fixed several pre-existing frontend build/runtime issues (App.jsx merge fallout, invalid imports/markup) and removed a broken duplicate require in the backend route.
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| frontend/vite.config.js | Configures Vitest (jsdom env, setup file, globals). |
| frontend/src/test/setup.js | Adds RTL cleanup and a jsdom matchMedia polyfill for tests. |
| frontend/src/pages/App.predictionForm.test.jsx | Adds RTL tests for the prediction form behavior (success + retryable error UI). |
| frontend/src/pages/App.jsx | Fixes build/runtime issues and corrects emoji sentiment helper usage. |
| frontend/src/components/ManipulationIndex.jsx | Removes a stray non-JS line that broke builds. |
| frontend/package.json | Adds vitest/RTL deps and a npm test script for the frontend. |
| frontend/package-lock.json | Locks new frontend test dependencies. |
| CONTRIBUTING.md | Documents how to run Python, Node, and frontend test suites. |
| backend/tests/predictionRoutes.test.js | Adds Jest/Supertest tests for backend /predict proxy behavior. |
| backend/routes/predictionRoutes.js | Removes a broken redundant require so /predict can reach Flask/Redis correctly. |
Files not reviewed (1)
- frontend/package-lock.json: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+44
to
+49
| api.get.mockImplementation((url) => { | ||
| if (url === '/api/wordcloud') { | ||
| return Promise.resolve({ data: { success: true, data: [] } }); | ||
| } | ||
| return Promise.resolve({ data: { success: false } }); | ||
| }); |
Comment on lines
+50
to
+54
| vi.stubGlobal( | ||
| 'fetch', | ||
| vi.fn(() => Promise.resolve({ ok: true, json: () => Promise.resolve({ top_features: [] }) })), | ||
| ); | ||
| }); |
Comment on lines
+905
to
909
| {result && result !== "Error" && text && analyzeEmojiSentiment(text).count > 0 && ( | ||
| <div className="mt-4 pt-3 border-t border-slate-700/20"> | ||
| <p className="text-xs font-semibold opacity-70 mb-2 flex items-center gap-1"> | ||
| <span>😊</span> Emoji Sentiment | ||
| </p> |
added 2 commits
July 14, 2026 03:12
…rors This branch's App.jsx/ManipulationIndex.jsx fix (duplicate function App(), unclosed div, stray non-JS line) was an earlier, less complete pass than the one later done in fix/frontend-eslint-errors (which also removed dead state/functions and fixed the emoji regex 'u' flag). Since several other PRs from this same batch (issues Userunknown84#822/Userunknown84#823/Userunknown84#824) already build on that later, more complete version, this branch's divergent App.jsx would conflict with all of them on merge for no reason - this branch never added anything unique to App.jsx beyond the structural parse fix. Replacing with the identical, more complete version so this branch's diff against main is a strict subset of what the other branches already carry, and merging in any order produces no conflict here. Verified: App.predictionForm.test.jsx still passes (3/3), vite build still succeeds.
The container's Flask process defaults to FLASK_HOST=127.0.0.1 (a deliberate secure default for bare-metal runs), so inside the CI container it never listens on an interface reachable through the -p 5000:5000 port mapping, and the smoke test's curl always times out. docker-compose.yml already sets FLASK_HOST=0.0.0.0 for the same reason; the CI workflow's docker run step needs the same override.
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
Closes #820.
backend/tests/already covered/predictinput validation, edge cases, and explanation responses, so nonew Python tests were needed for that acceptance criterion.
backend/tests/predictionRoutes.test.js(Jest +Supertest) covering the
/predictproxy route — success, missing-text400, ML API timeout (504), connection-refused (503), and upstream 4xx/5xx
handling (400 passthrough / 502).
for the prediction form (
App.predictionForm.test.jsx) covering thedisabled-until-input state, a successful submission, and error+retry
rendering.
CONTRIBUTING.md: documented how to run all three test suites.Bugs found and fixed while writing these tests
routes/predictionRoutes.jscalledrequire("./middleware/cacheMiddleware")with a wrong relative path(missing
..). This threw on every real/predictrequest rightbefore contacting Flask, meaning the endpoint always failed with a 503
in production.
redisClientis already imported correctly at the top ofthe file, so the broken duplicate require was just deleted.
frontend/src/pages/App.jsxdid not compile at all:function App() {declaration and an unclosedhandlePredictfunction/try-catch, left over from a bad merge</div>for the main card wrapperanalyzeEmojisfunction (the real function isanalyzeEmojiSentiment) that would throw on every rendered predictionresult
<button>nested inside<button>in the tab bar (Reacthydration warning / invalid HTML)
./components/ResultBadgepathfrontend/src/components/ManipulationIndex.jsxhad a straynon-JS line (
#Manipulation) at the top of the file that also broke theproduction build.
All of the above were pre-existing bugs on
main, not introduced by thisbranch —
vite buildand the new/existing test suites now pass.Test plan
cd backend && pytest tests/— existing suite passes (a couple ofpre-existing, unrelated failures in other suites due to an undefined
internal_endpoint_requiredname elsewhere inapi.py; not touched bythis PR)
cd backend && npm test— 22 Jest tests pass;node --testsuites forkeywordRules/rateLimiter pass. (
avatarUpload/fileValidationnode:testsuites fail due to a pre-existing unrelated syntax error in
middleware/fileValidation.jsonmain— not touched by this PR)cd frontend && npm run build— succeedscd frontend && npm test— 3/3 pass