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

[BUG] Debugger doesn't hit breakpoints when running a Jest test using ` #1160

Closed
rochejul opened this issue Jul 11, 2024 · 10 comments
Closed

Comments

@rochejul
Copy link

Describe the bug
No break point could hit when we run a specify test using as naming the es6 template string however the describe debug action will be able to enable the breakpoint

To Reproduce
Steps to reproduce the behavior:

  1. Go on a jest test file where naming use template string
  2. Click on 'Debug'
  3. The test will be run but without executing the breakpoints
  4. Rename the test and use double quotes
  5. Click on 'Debug'
  6. The test will be run and execute the breakpoints

Note: A sample repo will help us identify the bug much faster. 🙏

Expected behavior
We should be able to execute breakpoints regardless if we name the test with single quote, double quote, string template

Environment (please complete the following information):

  • vscode-jest version:[e.g., v6.2.5]
  • node -v: 10.7.0
  • npm -v:
  • jest version: 29.7.0
  • your vscode-jest settings:
    • jest.jestCommandLine? "NODE_OPTIONS="$NODE_OPTIONS --enable-source-maps --experimental-vm-modules" npx jest --no-cache"
    • jest.runMode? on-save
    • jest.outputConfig: none
  • Operating system: Ubuntu 24

Prerequisite

  • are you able to run jest from the command line? yes
  • where do you run jest CLI from? sub-package
  • how do you run your tests from the command line? "npm test"

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

@connectdotz
Copy link
Collaborator

connectdotz commented Aug 2, 2024

@rochejul

[updated]
A template string is considered dynamic because its content might not match the "resolved" string that Jest compares against. Therefore, you need to first "resolve" the dynamic names by running the parent block (a non-dynamic named describe block that encloses it, or the test file itself) at least once. After that, you can run or debug the test directly by its resolved name.

We can assist you further if you can provide more details about your specific issue.

@rochejul
Copy link
Author

rochejul commented Aug 3, 2024

Hi @connectdotz

I found the generated commands

This works fine:

/usr/bin/env 'NODE_OPTIONS= --require /snap/code/163/usr/share/code/resources/app/extensions/ms-vscode.js-debug/src/bootloader.js  --experimental-vm-modules  --inspect-publish-uid=http' 'VSCODE_INSPECTOR_OPTIONS=:::{"inspectorIpc":"/tmp/node-cdp.3597-9a5327ae-43.sock","deferredMode":false,"waitForDebugger":"","execPath":"/home/julien-roche/.volta/bin/node","onlyEntrypoint":false,"autoAttachMode":"always","fileCallback":"/tmp/node-debug-callback-c97c24f06ada6010"}' /home/julien-roche/.volta/bin/node node_modules/.bin/jest --runInBand --no-cache --coverage=false --colors --verbose --watchAll=false /home/julien-roche/dev/github/web-component-attribute-polyfill/packages/core/test/engine.test.js -c /home/julien-roche/dev/github/web-component-attribute-polyfill/packages/core/jest.config.json -t Core\ -\ engine\ observeCustomAttribute --no-cache --coverage=false --runInBand 

This fails (when we use the `):

/usr/bin/env 'NODE_OPTIONS= --require /snap/code/163/usr/share/code/resources/app/extensions/ms-vscode.js-debug/src/bootloader.js  --experimental-vm-modules  --inspect-publish-uid=http' 'VSCODE_INSPECTOR_OPTIONS=:::{"inspectorIpc":"/tmp/node-cdp.3597-98324501-46.sock","deferredMode":false,"waitForDebugger":"","execPath":"/home/julien-roche/.volta/bin/node","onlyEntrypoint":false,"autoAttachMode":"always","fileCallback":"/tmp/node-debug-callback-5efc8ec4de10473c"}' /home/julien-roche/.volta/bin/node node_modules/.bin/jest --runInBand --no-cache --coverage=false --colors --verbose --watchAll=false /home/julien-roche/dev/github/web-component-attribute-polyfill/packages/core/test/engine.test.js -c /home/julien-roche/dev/github/web-component-attribute-polyfill/packages/core/jest.config.json -t Core\ -\ engine\ observeCustomAttribute\ it\ calls\ the\ attribute\ changed\ callback\ when\ the\ attribute\'\\\'\'s\ value\ has\ changed --no-cache --coverage=false --runInBand

The title of the test:

test(`it calls the attribute changed callback when the attribute's value has changed`, async () => {

I wonder if there is not an issue on escaping in this case

Regards

@connectdotz
Copy link
Collaborator

@rochejul, I tested the exact test name in a vanilla project, and it ran/debugged fine.

However, I need to correct my previous comment that some template-string-named tests can be run at any time. It turns out that all template string test names are considered dynamic, so they need to be resolved prior to debugging/running directly.

I am guessing this issue might be related to your specific project settings. Do you have a sample repo we can dig further?

@rochejul
Copy link
Author

rochejul commented Aug 4, 2024

Hi @connectdotz

I have a repository where I work on

I created this branch for you: https://github.com/rochejul/web-component-attribute-polyfill/tree/invest/1160-vscode-debugger-and-back-quote

You could modify the following test: https://github.com/rochejul/web-component-attribute-polyfill/blob/invest/1160-vscode-debugger-and-back-quote/packages/core/test/engine/observe.test.js#L235 and set the title:

test(`it calls the attribute changed callback when the attribute's value has changed`, async () => {

I hope it could help

Let me know if you find some clues and I could help you

Regards

@connectdotz
Copy link
Collaborator

@rochejul, I tested your sample repo on macOS, and everything works as expected.

I did need to make a few changes in your repo to get it running. One is creating a custom debug config with NODE_ENV. You probably have done that too; otherwise, it wouldn't run at all.

This is the command line regarding --testNamePattern correctly generated by the VSCode debugger:

--testNamePattern core\ -\ engine\ -\ observe\ observeCustomAttribute\ it\ calls\ the\ attribute\ changed\ callback\ when\ the\ attribute\'s\ value\ has\ changed\$  

I assume you can "run" this individual test, which means the extension has correctly spawned the shell and escaped the test name for the Jest run.

During debugging, it is the VSCode debugger that is responsible for spawning the shell and preparing the arguments. It worked correctly on my machine (macOS 14.6). This leads me to consider two possibilities:

  1. I noticed you are using Node version 10.7. This is quite old. Both Jest and the extension have stopped officially supporting Node < 18.x. Try upgrading your Node and test again if you can.
  2. It could also be a VSCode issue. Which version of VSCode are you running? If you are already running the latest version, then try running it on a different platform to see if the issue is platform-specific.

@rochejul
Copy link
Author

rochejul commented Aug 5, 2024 via email

@rochejul
Copy link
Author

rochejul commented Aug 5, 2024

From my laptop I have the following configuration:

  • Node: 20.15.0
  • NPM: 10.7.0
  • Jest: 29.7.0
  • Vscode: 1.92.0
  • Jest plugin: 6.2.5
  • Jest runner plugin: 0.4.73
  • OS: Ubuntu 24.04 LTS

@rochejul
Copy link
Author

rochejul commented Aug 5, 2024

@connectdotz I will be away from keyboard for the next days

Please let me know if you have further details

If needed, please close the issue and I will have a deeper and if needed I will provide a PR

Thanks a lot

@connectdotz
Copy link
Collaborator

Ok, It looks like your original issue post might have listed the wrong node version.

I also noticed another difference: you have both the vscode-jest and vscode-jest-runner extensions installed. Since they offer similar functionality, there could be some interference between them. You can try temporarily disabling the vscode-jest-runner extension to see if that makes any difference.

@rochejul
Copy link
Author

Hi @connectdotz
I still have the issue

I will close the ticket and I will try to debug it furthermore

Many thanks for your help

Regards

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

No branches or pull requests

2 participants