jest-community / vscode-jest

The optimal flow for Jest based testing in VS Code
MIT License
2.83k stars 291 forks source link

Cannot hit breakpoint inside a test with VS Code IDE #400

Open stherrienaspnet opened 5 years ago

stherrienaspnet commented 5 years ago

Environment

  1. node -v: [v10.12.0]

  2. npm -v: [6.4.1]

  3. npm ls jest or npm ls react-scripts (if you haven’t ejected): [jest@23.6.0]

  4. your vscode-jest settings if customized:

    • jest.pathToJest? [not set]
    • jest.pathToConfig? [not set]
    • anything else that you think might be relevant? []
  5. Operating system: [Ubuntu 18.04]

Prerequisite

Steps to Reproduce

Here is a really simple repository that show it is not possible to hit breakpoint into the file user.repository.spec.ts on line 12 const users = await userRepository.getAll(); https://github.com/stherrienaspnet/vscode-jest-debug.git

Relevant Debug Info

[Did not found any resolution yet]

Expected Behavior

[Should break on line 12 when there is a breakpoint and press play vscode-jest-test in launch menu ]

Actual Behavior

[Break on line 12 is not hit]

Thanks you very much!


The fastest (and the most fun) way to resolve the issue is to submit a pull-request yourself. If you are interested, feel free to check out the contribution guide, we look forward to seeing your PR...

TheAlmightyBob commented 5 years ago

@stherrienaspnet Have you tried the debugger keyword? Breakpoints are generally unreliable with async functions in my experience, unrelated to jest.

dgreene1 commented 5 years ago

Possible solution: For me, the reason why I couldn't hit the correct line was due to sourcemaps being incorrect/absent due to an issue with ts-jest when Jest's collectCoverage option was set to true. https://github.com/kulshekhar/ts-jest/issues/917

Setting that to false allowed the green CodeLens [debug] button to properly hit my code at the desired lines.

wasker commented 5 years ago

Possibly useful development

blikblum commented 5 years ago

When launching jest as a debug task, adding the option disableOptimisticBPs fix this issue

Full context at https://github.com/Microsoft/vscode/issues/60187

Not sure if or how this can be used to fix this issue

Below is a config that works

    {
      "type": "node",
      "request": "launch",
      "name": "Jest All",
      "program": "${workspaceFolder}/node_modules/jest/bin/jest",
      "args": ["unit", "--runInBand"],
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen",
      "disableOptimisticBPs": true
    }
connectdotz commented 5 years ago

hi, while there might be many reasons the debugger can't find the right breakpoint, you can try 3.0.0-preRelease to see if it resolve your issue...

rageycomma commented 5 years ago

For me, with the same version you have, it's --collectCoverage in any form - as soon as this is applied, breakpoints on any code except your unit tests are a goner.

stherrienaspnet commented 5 years ago

Thanks you very much!

Le jeu. 12 sept. 2019 à 14:12, Jordan Ashley Craw notifications@github.com a écrit :

For me, with the same version you have, it's --collectCoverage in any form - as soon as this is applied, breakpoints on any code except your unit tests are a goner.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/jest-community/vscode-jest/issues/400?email_source=notifications&email_token=ABOX24IISVX7D5EVW2HG3YTQJKBCNA5CNFSM4GAA55A2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6SYUQY#issuecomment-530942531, or mute the thread https://github.com/notifications/unsubscribe-auth/ABOX24NE2N5A2ZHQKTVDPGLQJKBCNANCNFSM4GAA55AQ .

nuKs commented 5 years ago

Same problem, collectCoverage as well. Weird because jest has deprecated the mapCoverage option because it's now set to true by default so it shouldn't cause any issue.

FaBrand commented 1 month ago

With one adaption /<name>/Your workspace folder basename/ according to the docs this config also worked for me.

Used @blikblum's config as well, but added the --collectCoverage=false to overridy any configured values

(I had "env": {"NODE_OPTIONS":"--experimental-vm-modules"} set, but might be different for you)

With this i could start debugging via a click in the VSCode Test Runner UI and it stopped at break points as well

Strangely enough when using the ${workspaceFolderBasename} variable, it didn't work.

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "name": "vscode-jest-tests.v2.<name>", 
            "request": "launch",
            "args": [
              "--collectCoverage=false",
              "--runInBand",
              "--watchAll=false",
              "--testNamePattern",
              "${jest.testNamePattern}",
              "--runTestsByPath",
              "${jest.testFile}"
            ],
            "cwd": "${workspaceFolder}",
            "program": "${workspaceFolder}/node_modules/jest/bin/jest",
            "console": "integratedTerminal",
            "internalConsoleOptions": "neverOpen",
            "disableOptimisticBPs": true,
            "env": {"NODE_OPTIONS":"--experimental-vm-modules"}
        } 
    ]
}