You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Steps To Reproduce using next-test-api-route-handler repo
it seems like the repo unit tests also demonstrate it
next-test-api-route-handler on main is 📦 4.0.2 via ⬢ v18.17.1 took 24.8s
➜ npm test
> next-test-api-route-handler@4.0.2 test
> npm run test:unit --
> next-test-api-route-handler@4.0.2 test:unit
> NODE_OPTIONS='--no-warnings' NODE_ENV=test jest '/unit-.*\.test\.tsx?' --testPathIgnorePatterns '/dist/'
PASS test/unit-index-imports.test.ts
PASS test/unit-msw.test.ts
PASS test/unit-external.test.ts
PASS test/unit-index.test.ts
A worker process has failed to exit gracefully and has been force exited. This is likely caused by tests leaking due to improper teardown. Try running with --detectOpenHandles to find leaks. Active timers can also cause this, ensure that .unref() was called on them.
Test Suites: 4 passed, 4 total
Tests: 93 passed, 93 total
Snapshots: 0 total
Time: 1.821 s
Ran all test suites matching /\/unit-.*\.test\.tsx?/i.
The text was updated successfully, but these errors were encountered:
Thanks for this detailed report! I knew there'd be some cases I was overlooking. I'll investigate tonight.
UPDATE: Ah, I see. I couldn't replicate this with npx node@21 node_modules/.bin/jest or npx node@20 node_modules/.bin/jest but it did pop up with npx node@18 node_modules/.bin/jest. Seems the test still passes even with the hang. There is likely some node@18 related issue with no backported fix.
Turns out later versions of Node terminate persistent server connections more optimally than Node@18 does. Explicitly calling server.closeAllConnections() after calling server.close() did the trick.
Thanks again for opening this issue, I learned from fixing this.
### [4.0.3](v4.0.2...v4.0.3) (2024-01-18)
#### 🪄 Fixes
* **src:** ensure ephemeral test servers only listen on localhost ([d7774b3](d7774b3))
* **src:** forcefully close all connections after closing test server (fixes [#962](#962)) ([d03ca21](d03ca21))
i am looking for a nice way to unit test my route handlers.
many thanks for this package.
when using the appHandler, there seems to be an open promise after my tests complete:
Jest did not exit one second after the test run has completed.
is this expected behavior, or am i perhaps missing some sort of tear down call ?
Jest --detectOpenHandles
My route and test
Steps To Reproduce using next-test-api-route-handler repo
The text was updated successfully, but these errors were encountered: