Skip to content

Instantly share code, notes, and snippets.

@jaredhirsch
Last active November 6, 2019 23:53
Show Gist options
  • Save jaredhirsch/77efa18b6564d9a7a5daa4d3aeb42d98 to your computer and use it in GitHub Desktop.
Save jaredhirsch/77efa18b6564d9a7a5daa4d3aeb42d98 to your computer and use it in GitHub Desktop.
attaching debuggers to things

(Note: I moved this info into the main FxA readme at https://github.com/mozilla/fxa.)

Attaching a debugger to a running node process, sadly, requires running google chrome (AFAIK).

How to do it:

  1. Start google chrome and open up chrome://inspect.

  2. Run a node process using the --inspect or --inspect-brk flags (see specific command-line incantations below)

  3. In chrome, you should see the process show up in the Remote Target pane with an 'inspect' link. Click it to jump into the debugger.

Attaching to tests in payments server (jest):

For jest, you'll want to pass the --runInBand argument, so it doesn't fork off the test runner to a separate process (that isn't available to the inspector).

node --inspect-brk ./node_modules/.bin/jest --runInBand --config server/jest.config.js filematcher where filematcher is a partial regex that matches the test you want to debug. If you omit filematcher, it'll just run all tests.

Attaching to tests in fxa-shared (mocha):

For mocha, you'll want to pass the --timeout 0 option, otherwise the test will fail if you step through it and exceed the default timeout (currently 2 seconds on fxa-shared).

node --inspect-brk ./node_modules/.bin/mocha --timeout 0 path/to/file

Attaching to server processes

Theoretically, it should be easy to do this with pm2 (Danny suggested ./pm2 sendSignal SIGUSR1 $id, where $id is the pm2 id) . I haven't gotten that working yet.

Here's what has worked for me:

  1. Start the whole server as usual (npm install && npm start from top-level in the monorepo)
  2. Stop the pm2-managed version of whatever server you care about, ./pm2 stop NN where NN is the pm2 id listed when you do ./pm2 ls. Not the pid.
  3. Start the server in a special per-server way:
Payments Server

Start the server with npm run start-dev-debug. You should see the process pop up in the chrome://inspect panel in google chrome. You're off to the races, either set a breakpoint or add the debugger; operator to the code you want tto debug.

Content Server

Start the server with npm run start-dev-debug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment