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

Debugger doesn't hit breakpoints when running Jest tests #59056

Closed
rswerve opened this issue Sep 20, 2018 · 12 comments
Closed

Debugger doesn't hit breakpoints when running Jest tests #59056

rswerve opened this issue Sep 20, 2018 · 12 comments
Assignees
Labels
debug Debug viewlet, configurations, breakpoints, adapter issues info-needed Issue requires more information from poster

Comments

@rswerve
Copy link

rswerve commented Sep 20, 2018

Issue Type: Bug

Trace attached.
debugadapter.txt

Steps to Reproduce:

  1. Write Jest tests
  2. Set breakpoints in the tests
  3. Use launch.json to run the tests

The breakpoints say "breakpoint set but not yet bound" and remained grayed out for the duration of the tests.

I'd expect the breakpoints to be hit. Console.log in the files with breakpoints do work and the tests run properly. This persists when all extensions are disabled.

VS Code version: Code 1.27.2 (f46c4c4, 2018-09-12T07:04:11.329Z)
OS version: Darwin x64 16.7.0

System Info
Item Value
CPUs Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz (8 x 2500)
GPU Status 2d_canvas: enabled
checker_imaging: disabled_off
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
native_gpu_memory_buffers: enabled
rasterization: enabled
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled
Load (avg) 2, 3, 3
Memory (System) 16.00GB (0.39GB free)
Process Argv /Applications/Visual Studio Code.app/Contents/MacOS/Electron -psn_0_19890935
Screen Reader no
VM 0%
Extensions (15)
Extension Author (truncated) Version
sort-lines Tyr 1.7.0
vscode-eslint dba 1.6.0
xml Dot 2.3.2
tslint eg2 1.0.39
macros ged 1.2.1
beautify Hoo 1.4.3
docthis joe 0.7.1
terraform mau 1.3.4
vs-code-quick-require mil 0.2.4
prettify-json moh 0.0.3
vsliveshare ms- 0.3.709
debugger-for-chrome msj 4.10.1
vetur oct 0.12.6
partial-diff ryu 1.4.0
code-settings-sync Sha 3.1.2

(7 theme extensions excluded)

@weinand weinand added the debug Debug viewlet, configurations, breakpoints, adapter issues label Sep 20, 2018
@roblourens
Copy link
Member

#54485

I don't see the files with breakpoints being loaded. What's your launch config like? Have you seen the docs?

@roblourens roblourens added the info-needed Issue requires more information from poster label Sep 20, 2018
@rswerve
Copy link
Author

rswerve commented Sep 20, 2018

I have read the docs, but the tests are running as expected, so I'm not sure what "loaded" means here.

I think the launch config is in the trace, but here it is, including commented options that I tried changing to no avail.

    {
        "type": "node",
        "request": "launch",
        "name": "Jest Tests",
        "program": "${workspaceRoot}/node_modules/platform-vic/lib/index",
        "args": [
            "test"
        ],
        "runtimeArgs": [
            "--nolazy"
        ],
        "protocol": "inspector",
        "console": "integratedTerminal"
        // "runtimeVersion": "10.10.0",
        // "cwd": "${workspaceRoot}",
        // "preLaunchTask": null,
        // "runtimeExecutable": null,
        // "env": { "NODE_ENV": "test" },
        // "internalConsoleOptions": "openOnSessionStart",
    }

I'm passing "test" to our test-runner, which then runs Jest.

@roblourens
Copy link
Member

I meant to paste the link to the Jest docs for vscode in my last comment, and left it out by mistake. https://jestjs.io/docs/en/troubleshooting#debugging-in-vs-code

They recommend using "--runInBand", normally it spawns a new process for the test code, which is just what the log shows. That flag loads the test code in the process which is being debugged.

@rswerve
Copy link
Author

rswerve commented Sep 21, 2018

Thanks, I had seen those docs and had tried "--runInBand". Attached is the trace of trying that again just now, which unfortunately didn't make a difference (I can see that the test files are being run one-by-one, so it has an effect, but the breakpoints still aren't hit.)
debugadapter.txt

@roblourens
Copy link
Member

I don't see runInBand being used in that log

From client: launch({
    "type": "node2",
    "request": "launch",
    "name": "Jest Tests",
    "program": "/Users/matighi/mercury/grid-screener-vic/node_modules/platform-vic/lib/index",
    "args": ["test"],
    "runtimeArgs": ["--nolazy"],
    "protocol": "inspector",
    "console": "integratedTerminal",
    "trace": true,
    "cwd": "/Users/matighi/mercury/grid-screener-vic",
    "internalConsoleOptions": "neverOpen",
    "logFilePath": "/Users/matighi/Library/Application Support/Code/logs/20180913T153123/ms-vscode.node-debug_2/debugadapter.txt",
    "__sessionId": "2f4e28ec-9665-46b2-8118-4e4b8e334482"
})

@rswerve
Copy link
Author

rswerve commented Sep 21, 2018

Yeah, it’s passed in by our test runner. I wonder if that test runner is the problem. Breakpoints in that do get hit.

@roblourens
Copy link
Member

Oh, so you're debugging something that then spawns jest? In that case, the debugger is not attached to the process actually running the tests.

@rswerve
Copy link
Author

rswerve commented Sep 21, 2018

Yes, that’s correct.

@Contrapuntist
Copy link

Don't know if this is related, but it's driving me crazy. I'll set breakpoints in my test file and when I launch the debugger, the breakpoints will change. Its been happening to me all week.

I'm new to working with the VSCode debugger. I thought it was something I was doing. But maybe it's something else.

Set before launch.
test_breakpoints_set_before_launch

what happens after launch:
breakpoints after launch

The above happens with and without the Jest extensions enabled. I thought it might be the extension, so I turned it off. It's still occurring.

I've had a couple different configurations, but this is the most current, which is taken from Jest website:
{
"name": "Debug Jest Tests",
"type": "node",
"request": "launch",
"runtimeArgs": [
"--inspect-brk",
"${workspaceRoot}/node_modules/jest/bin/jest.js",
"--runInBand"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"port": 9229
},

@roblourens
Copy link
Member

@Contrapuntist please open a new issue. A repo where I can see the issue would be great.

@rswerve I don't know what your setup is exactly, but you'll have to change it somehow such that the jest process is the thing that's started in debug mode. If you can change it to pass --inspect-brk=<some port> to the jest process, and add that port num to your launch config, that may work.

@rswerve
Copy link
Author

rswerve commented Sep 21, 2018

I’ll try that. Thanks.

@ryan-mars
Copy link

@roblourens @rswerve did this get resolved? I'm having the same problem.

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
debug Debug viewlet, configurations, breakpoints, adapter issues info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

5 participants