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

How to properly debug tests without using the command line debugger? #2119

Closed
alanz1223 opened this issue Nov 17, 2016 · 5 comments
Closed

Comments

@alanz1223
Copy link

alanz1223 commented Nov 17, 2016

node v.7
jest 16.0.1

Currently using VSCode and I am trying to debug a very basic test but I am having great difficulty doing so. I am using the node inspect flag to use the chrome devtools but my debugger statements and breakpoints are being ignored and the test just continues to run. At this point I am considering other debugging mechanisms to run a simple GUI based debugger. Are there any alternatives that you guys have had success using?

Here are the commands I run

node --inspect --debug-brk --harmony node_modules/jest/bin/jest.js -i

As you see I include the -i so that the tests run within the same process.
After doing this, I paste the given link into chrome and pause at the first line where jest is required, and after pressing "play" the test continues the run while ignoring the breakpoints and debugger statements and all the errors are actually logged on the shell and not the console within the devtools as one would expect.

I've been battling this issue on and off for about a week and would really like to switch to Jest as my testing framework, but that would be impossible if I can't properly debug my tests.

@damonbauer
Copy link

@alanz1223 - right now, this won't work. More info here: #1652

@cpojer has already pinged the nodejs team (nodejs/node#7593) and they've got a PR open to fix this (nodejs/node#9272)

Until that time, you can use node-inspector, and set up an npm script like so:

"test-debug": "./node_modules/.bin/node-debug ./node_modules/.bin/jest -i --watch"

and run it like:

$ npm run test-debug

and even run specific tests like

$ npm run test-debug -- NameOfTheTestFile

@hpurmann
Copy link

@damonbauer thx for the links and the node-inspector help. Still, I get a "websocket_closed" inside the chrome window.

Stacktrace:

yarn test-debug v0.17.8
$ ./node_modules/.bin/node-debug ./node_modules/.bin/jest -i --watch
Node Inspector v0.12.8
Visit http://127.0.0.1:8080/?port=5858 to start debugging.
Debugging `./node_modules/.bin/jest`

Debugger listening on [::]:5858
/Users/hpurmann/dev/actano/yourchoice/node_modules/node-inspector/lib/InjectorClient.js:111
      cb(error, NM[0].ref);
                     ^

TypeError: Cannot read property 'ref' of undefined
    at InjectorClient.<anonymous> (/Users/hpurmann/dev/actano/yourchoice/node_modules/node-inspector/lib/InjectorClient.js:111:22)
    at /Users/hpurmann/dev/actano/yourchoice/node_modules/node-inspector/lib/DebuggerClient.js:121:7
    at Object.value (/Users/hpurmann/dev/actano/yourchoice/node_modules/node-inspector/lib/callback.js:23:20)
    at Debugger._processResponse (/Users/hpurmann/dev/actano/yourchoice/node_modules/node-inspector/lib/debugger.js:95:21)
    at Protocol.execute (_debugger.js:121:14)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at Socket.Readable.push (_stream_readable.js:134:10)
    at TCP.onread (net.js:548:20)

Running on node 6.9.1 through nvm.

@hpurmann
Copy link

Nevermind, it works on 6.2.1 (but now I know why I used to hate the node-inspector: It's soooo slow).

@cpojer
Copy link
Member

cpojer commented Dec 7, 2016

Duplicate of #1652.

@cpojer cpojer closed this as completed Dec 7, 2016
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants