Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ease debugging Node.js from within VSCode #9510

Merged
merged 1 commit into from
Mar 14, 2022

Conversation

benjamn
Copy link
Member

@benjamn benjamn commented Mar 11, 2022

The other day my Chrome browser (dev channel) started crashing spontaneously on startup, which kept me from using the Chrome DevTools to debug Apollo Client tests running in Node.js.

Since I mostly use VSCode for editing these days, I decided to see if I could debug Node.js from entirely within VSCode. After all, a VSCode frontend for the V8 debugging protocol is advertised here. This would be appealing not just as a backup for Chrome, but also because it allows setting temporary breakpoints in source files (as well as inspecting local variables and the call stack) without leaving VSCode.

So far this experiment has worked out quite nicely, so this PR shares my VSCode configuration for this repository, for anyone else who wants to try this style of debugging.

Steps:

  1. Add some breakpoints to a test you'd like to debug, either using debugger statements or VSCode breakpoints (click the red dot at the far left of any line)
  2. Within your clone of this repository, run npm run test:debug, or npm run test:debug src/cache/inmemory to scope which tests are run
  3. Switch to the debugging panel of VSCode, choose Attach to Node.js inspector from the drop-down menu towards the top, and press the green triangle to start debugging
  4. Find the debugger control arrows, and press the leftmost button to continue past the very first statement in the program (likely in jest.js)
  5. Wait until Node.js stops at the breakpoints you set!

@benjamn benjamn self-assigned this Mar 11, 2022
@benjamn benjamn merged commit 0249c8b into release-3.6 Mar 14, 2022
@benjamn benjamn deleted the vscode-node.js-attach-config branch March 14, 2022 14:36
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant