fix(nextjs): reset daemon client after project graph creation in withNx#34518
fix(nextjs): reset daemon client after project graph creation in withNx#34518FrozenPandaz merged 1 commit intomasterfrom
Conversation
|
View your CI Pipeline Execution ↗ for commit 0801a4b
☁️ Nx Cloud last updated this comment at |
✅ Deploy Preview for nx-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for nx-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Important
At least one additional CI pipeline execution has run since the conclusion below was written and it may no longer be applicable.
Nx Cloud has identified a possible root cause for your failed CI:
Our investigation shows this test failure is pre-existing in the master branch and unrelated to the daemon client reset changes. The error stems from a missing ESM submodule in @microsoft/api-extractor during Vite config processing, which has no connection to the Next.js withNx modifications in this PR.
No code changes were suggested for this issue.
Trigger a rerun:
🎓 Learn more about Self-Healing CI on nx.dev
## Current Behavior Running `nx test` for Next.js projects causes Jest to hang with: "Jest did not exit one second after the test run has completed." This happens because `next/jest` loads `next.config.js`, which calls `withNx` → `createProjectGraphAsync()`. The daemon client socket connection is left open, keeping the Node.js event loop alive and preventing Jest from exiting. ## Expected Behavior Jest exits cleanly after tests complete for Next.js projects. ## Related Issue(s) Fixes #32880
|
This should be fixed after #34506, I don't think this ones needed? |
Hmm, will test after that change lands. |
…Nx (#34518) ## Current Behavior Running `nx test` for Next.js projects causes Jest to hang with: ``` Jest did not exit one second after the test run has completed. ``` This happens because `next/jest` loads `next.config.js`, which calls `withNx` → `createProjectGraphAsync()`. The daemon client socket connection is left open, keeping the Node.js event loop alive and preventing Jest from exiting. Non-Next.js projects are unaffected since they don't trigger this code path. ## Expected Behavior Jest exits cleanly after tests complete for Next.js projects, without needing `forceExit: true`. ## Fix Pass `resetDaemonClient: true` to `createProjectGraphAsync()` in `packages/next/plugins/with-nx.ts`. This tells the project graph function to call `daemonClient.reset()` after fetching the graph, which closes the socket and allows Jest to exit. ### Verification | Scenario | Before | After | |----------|--------|-------| | `nx test next-app` | Hangs | Exits cleanly | | `NX_DAEMON=false nx test next-app` | Exits cleanly | Exits cleanly | | Direct `npx jest` | Exits cleanly | Exits cleanly | | Non-Next.js `nx test react-lib` | Exits cleanly | Exits cleanly | ## Related Issue(s) Fixes #32880 (cherry picked from commit de2dc7c)
…Nx (#34518) ## Current Behavior Running `nx test` for Next.js projects causes Jest to hang with: ``` Jest did not exit one second after the test run has completed. ``` This happens because `next/jest` loads `next.config.js`, which calls `withNx` → `createProjectGraphAsync()`. The daemon client socket connection is left open, keeping the Node.js event loop alive and preventing Jest from exiting. Non-Next.js projects are unaffected since they don't trigger this code path. ## Expected Behavior Jest exits cleanly after tests complete for Next.js projects, without needing `forceExit: true`. ## Fix Pass `resetDaemonClient: true` to `createProjectGraphAsync()` in `packages/next/plugins/with-nx.ts`. This tells the project graph function to call `daemonClient.reset()` after fetching the graph, which closes the socket and allows Jest to exit. ### Verification | Scenario | Before | After | |----------|--------|-------| | `nx test next-app` | Hangs | Exits cleanly | | `NX_DAEMON=false nx test next-app` | Exits cleanly | Exits cleanly | | Direct `npx jest` | Exits cleanly | Exits cleanly | | Non-Next.js `nx test react-lib` | Exits cleanly | Exits cleanly | ## Related Issue(s) Fixes #32880
|
This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request. |
Current Behavior
Running
nx testfor Next.js projects causes Jest to hang with:This happens because
next/jestloadsnext.config.js, which callswithNx→createProjectGraphAsync(). The daemon client socket connection is left open, keeping the Node.js event loop alive and preventing Jest from exiting. Non-Next.js projects are unaffected since they don't trigger this code path.Expected Behavior
Jest exits cleanly after tests complete for Next.js projects, without needing
forceExit: true.Fix
Pass
resetDaemonClient: truetocreateProjectGraphAsync()inpackages/next/plugins/with-nx.ts. This tells the project graph function to calldaemonClient.reset()after fetching the graph, which closes the socket and allows Jest to exit.Verification
nx test next-appNX_DAEMON=false nx test next-appnpx jestnx test react-libRelated Issue(s)
Fixes #32880