Skip to content

Fix/test app import mismatch - #927

Open
mrunalC27 wants to merge 3 commits into
adithyan-css:mainfrom
mrunalC27:fix/test-app-import-mismatch
Open

Fix/test app import mismatch#927
mrunalC27 wants to merge 3 commits into
adithyan-css:mainfrom
mrunalC27:fix/test-app-import-mismatch

Conversation

@mrunalC27

Copy link
Copy Markdown

Description

Closes #862. api/index.js exports the Express app as the default export (module.exports = app), but tests/api.test.js was importing it as a named export (const { app } = require(...)), so app in the tests was always undefined.

Changes

  • tests/api.test.js: changed the import to match the actual export shape (const app = require('../api/index')).
  • api/index.js: guarded startServer(PORT) so it doesn't run when NODE_ENV === 'test', preventing a real TCP port from binding during test runs (this was causing the TCPSERVERWRAP open-handle warning and the "log after tests are done" warning).

Went with fixing the test import rather than restructuring the api/index.js export, since vercel.json points @vercel/node directly at api/index.js and expects a callable export — wrapping it in { app, handler } would've broken the Vercel deployment path.
Confirmed tests/api.test.js is the only consumer of this import.

Testing

npm test — all 4 tests now pass, no open handles, no stray logs.

@vercel

vercel Bot commented Jul 3, 2026

Copy link
Copy Markdown

@mrunalC27 is attempting to deploy a commit to the adithyansubramani1-1657's projects Team on Vercel.

A member of the Team first needs to authorize it.

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.

npm test fails on all 4 tests — app is undefined due to export/import mismatch in tests/api.test.js

1 participant