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

Find out and document how to debug unit tests from VSCode #2118

Closed
yurishkuro opened this issue Jan 18, 2024 · 14 comments · Fixed by #2297
Closed

Find out and document how to debug unit tests from VSCode #2118

yurishkuro opened this issue Jan 18, 2024 · 14 comments · Fixed by #2297

Comments

@yurishkuro
Copy link
Member

How to run and debug unit tests is rather confusing, we need to document it better.

For example, from the command line it's possible to run a test like this:

$ yarn test packages/jaeger-ui/src/model/transform-trace-data.test.js

However, to run with debugger in VSCode we need a launch configuration, and I had trouble coming up with a generic one.

This one has file name hardcoded:

        {
            "type": "node",
            "request": "launch",
            "name": "Jest: current file",
            "skipFiles": [
                "<node_internals>/**"
            ],
            "program": "${workspaceFolder}/packages/jaeger-ui/node_modules/.bin/jest",
            "args": ["src/model/transform-trace-data.test.js"],
            "console": "integratedTerminal",
            "cwd": "${workspaceFolder}/packages/jaeger-ui",
        }
@RISHIKESHk07
Copy link
Contributor

RISHIKESHk07 commented Jan 19, 2024

@yurishkuro would like to help

@RISHIKESHk07
Copy link
Contributor

@yurishkuro Does this work ?

{
    "type": "node",
    "request": "launch",
    "name": "Jest: current file",
    "skipFiles": [
        "<node_internals>/**"
    ],
    "program": "${workspaceFolder}/node_modules/.bin/jest",
    "args": [
        "${relativeFile}",
        "--config",
        "jest.config.js" // this would run the jest test for current file when we launch on vscode
    ],
    "console": "integratedTerminal",
    "cwd": "${workspaceFolder}"
}

@yurishkuro
Copy link
Member Author

does it work for you?

@RISHIKESHk07
Copy link
Contributor

RISHIKESHk07 commented Jan 22, 2024

i got a dependency conflict on npm i ,

npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: jaeger-ui@1.37.0
npm ERR! Found: react@18.2.0
npm ERR! node_modules/react
npm ERR!   react@"^18.2.0" from jaeger-ui@1.37.0
npm ERR!   packages/jaeger-ui
npm ERR!     jaeger-ui@1.37.0
npm ERR!     node_modules/jaeger-ui
npm ERR!       workspace packages/jaeger-ui from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"15.3.0 - 16.x" from react-vis@1.11.12
npm ERR! node_modules/react-vis
npm ERR!   react-vis@"^1.7.2" from jaeger-ui@1.37.0
npm ERR!   packages/jaeger-ui
npm ERR!     jaeger-ui@1.37.0
npm ERR!     node_modules/jaeger-ui
npm ERR!       workspace packages/jaeger-ui from the root project

@RISHIKESHk07
Copy link
Contributor

@yurishkuro should i resolve it directly , or is there any other solution for this ?

@RISHIKESHk07
Copy link
Contributor

i did --force to fix above issue and tried running the run and debug on the .test.js files ,
image

@yurishkuro
Copy link
Member Author

I was also getting this import error, this is why I opened the ticket.

@RISHIKESHk07
Copy link
Contributor

@yurishkuro I did try various changes but it did not fix it , any suggestion where I should focus , I did see that jest is having a problem with esm modules , but in the docs i found the support for it is experimental,

@RISHIKESHk07
Copy link
Contributor

@yurishkuro does this look fine ?
image

@yurishkuro
Copy link
Member Author

(a) you have test name hardcoded, instead of using the current test file, (b) can you set breakpoints?

@RISHIKESHk07
Copy link
Contributor

RISHIKESHk07 commented May 2, 2024

{
    // 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",
            "request": "launch",
            "name": "Jest: current file",
            "skipFiles": [
                "<node_internals>/**"
            ],
            "program": "${workspaceFolder}/node_modules/.bin/jest",
            "args": [
                "${file}"
            ],
            "console": "integratedTerminal",
            "cwd": "${workspaceFolder}/packages/jaeger-ui",
        }
          
    ]
}

a) Can be solved by replacing the hardcoded part with {file}.
For b) this works fine , we can directly set breakpoints in the file , or you have something else in mind on how this should work like giving the breakpoints as input in the launch.json & jest takes these breakpoints
image

@yurishkuro
Copy link
Member Author

+1 please open a PR

@RISHIKESHk07
Copy link
Contributor

@yurishkuro was wondering where should i keep the launch.json ?

@yurishkuro
Copy link
Member Author

Readme or launch.example.json

yurishkuro added a commit that referenced this issue May 7, 2024
## Which problem is this PR solving?
 Resolve #2118 

## Description of the changes
- Added a launch json in the README.md which explains how to set the
debugger of vscode to test unit tests with jest.

## How was this change tested?
-  Proof of work was present in the comment thread of the issue #2118 

## Checklist
- [x] I have read
https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md
- [x] I have signed all commits
- [] I have added unit tests for the new functionality
- [] I have run lint and test steps successfully
  - for `jaeger`: `make lint test`
  - for `jaeger-ui`: `yarn lint` and `yarn test`

---------

Signed-off-by: RISHIKESHk07 <rishikeshkuppala@gmail.com>
Signed-off-by: Yuri Shkuro <github@ysh.us>
Co-authored-by: Yuri Shkuro <github@ysh.us>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants