Auto-launching Chrome to Debug Mocha Tests on Mac
March 22, 2017 § 1 Comment
Are you tired of cutting and pasting URLs from node –inspect to launch Chrome?
This is what happens today:
$ alias mocha="node_modules/mocha/bin/mocha" $ alias mocha-debug="mocha --debug-brk --inspect --compilers ts:ts-node/register --recursive test/**/*-spec.ts" $ mocha-debugDebugger listening on port 9229. Warning: This is an experimental feature and could change at any time. To start debugging, open the following URL in Chrome: chrome-devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws=127.0.0.1:9229/2dcfe97d-49c4-40bc-8639-51e1508dc09d
Right now I need to manually launch Chrome and paste in that URL, which is a pain. After much experimentation, I finally found a StackOverflow question that pointed me to inspect-process. Now I can just do:
$ npm install -g inspect-process $ inspect node_modules/mocha/bin/_mocha --compilers ts:ts-node/register --recursive test/**/*-spec.ts
Whew! I am posting this here in the hopes it will help other people find the information more easily.
Note that you may need to to type ‘about:inspect’ in the Chrome debugger to find the connection: https://medium.com/@paul_irish/debugging-node-js-nightlies-with-chrome-devtools-7c4a1b95ae27