-
Notifications
You must be signed in to change notification settings - Fork 460
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
Unable to use breakpoints to debug TypeScript in Visual Studio Code. #170
Comments
@jcgillespie thanks for creating the repo! Making the following changes got this working for me:
|
@kulshekhar That worked! Thank you so much! I Wouldn't have thought to point the jest tests at the .js files rather than the ts. |
@kulshekhar What's the proper configuration to get this all to work and keep coverage remapping? The debug config above works, but coverage in the TS files is all zeroed out. I feel like the magic is somewhere in the As an interim, I've updated the |
@jcgillespie you could have separate configs for debugging and testing/coverage |
also, iirc, the degug config in the sample repo didn't use the |
Maybe someone could post a working VSCode launch.json config if they have one? You would be such a dear ^-^ |
@netpoetica Here's mine, which I use on this project
tasks.json
Relevant related files are here: |
Thanks @jcgillespie, Edit: I just saw that you are using |
Hi, Does the debug work in Node v6.11.0? Anyone here has been able to do it. I'm on windows10. Thank you. |
Thank you very much @jcgillespie!! That works perfect! 😄 |
@jcgillespie I tested your example with node 7.8, and it works as expected. However using node 8+, it no longer breaks on breakpoints or debugger statements. Any ideas how to fix it? I'm assuming it has something to do with the newer inspector protocol. |
@jordond found a solution to this one: https://www.jstwister.com/post/debugging-jest-with-vscode/ |
Did anyone find a way to get this working without requiring a discrete build step? I really dig the way the preprocessor inside this repo makes it unnecessary to pollute the working directory with build artifacts. |
Same as @cryza , it's a pain to have to generate the js files beforehand to get the debugging working, it's even killing the need for |
@SimenB Please see above comment for supporting my request to have determination over using require to use ts-node with Jest |
Jest has no goal of working with ts-node. I write TS full time at work using Babel as transpiler, and have 0 issues with breakpoints in the IDE when running tests. I know VS Code tries to be clever when it tries to add breakpoints, so I'd look into that side of things. I recommend looking at facebook/create-react-app#5319 (especially trying the But require hooks is just a hack for a symptom, it's not the solution to the problem or something Jest will strive to support. Lastly, this is an old issues - we fixed a lot of incompatibilities with sourcemaps in Jest 23 (released in May) so some of the assumptions and tests done before that may not be valid anymore |
@SimenB I'm happy to drop ts-node but I haven't seen any documentation for running Jest with Typescript with breakpoints. I have heard people like yourself say it works but I haven't been able to find anything conclusive. Should I open an issue on facebook/jest for documentation? |
I'd recommend figuring out how to do it via stack overflow or discord or something, then open up a PR adding any missing documentation. As mentioned, breakpoints with typescript works out of the box, zero config, for me. But I don't use VS Code. I doubt there's an issue with Jest itself (although, happy to tweak Jest if we figure out it somehow makes things harder for IDEs, as long as we don't lose features over it). |
Hours spent on issues like that make me proud to be a software engineer. Bill Burr + Louis C.K. and still can't laugh as loud. I'm also going to like my own comment for the added effects |
Issue
I'm unable to debug Jest test cases written in TypeScript. Possibly just a configuration problem? What am I missing?
Thanks!
Steps to reproduce
npm install
oryarn
SystemUnderTest.spec.ts
. (Just abovedebugger;
statement)SystemUnderTest.ts
. (Insideconstructor
).Expected Behavior
Debugger should stop...
SystemUnderTest.spec.ts
.SystemUnderTest.ts
.SystemUnderTest.spec.ts
.Actual Behavior
Debugger only stops on line 7 of
SystemUnderTest.spec.ts
Additional observations
debugger
statements stop in the proper location in the TS files, not in the transpiled JS, so sourcemaps are being emitted and consumed.Once stopped, VS Code debug controls (e.g. F10 to step over) work fine.
VS Code reports that the breakpoints are loaded. They are not greyed out.
However, as the debugger reaches each expected breakpoint but doesn't it it, it will begin reporting a source map problem.
The "future" breakpoint (line 8 of
SystemUnderTest.spec.ts
) does not report any sourcemap problem.The text was updated successfully, but these errors were encountered: