When debugging Jest tests in VS-Code my breakpoints move a few lines as soon as I start the debugger.
I use the officially recommended configuration with plain JavaScript (not Babel).
I think it has something to do with source maps.
Setting "sourceMaps": false
in the configuration makes my breakpoints not move anymore but shift the 'real' source code a few lines.
Minimal Example:
// hello_world.test.js
funTest = require('./hello_world.js')
const x = 15
test('this is a test', () => {
expect(funTest(5)).toBe(9)
})
// hello_world.js
const funTest = () => {
return 9
}
module.exports= funTest
Now if you set a breakpoint at const x = 15
you will see that it is shifted to expect(funTest(5)).toBe(9)
during the debugging session.
Used Software VS Code: 1.27.0, no extensions ; Jest: 23.5.0 ; Node: 8.10.0 ; Ubuntu Linux 16.04
To set a breakpoint in source code: Click in the far left margin next to a line of code. You can also select the line and press F9, select Debug > Toggle Breakpoint, or right-click and select Breakpoint > Insert breakpoint. The breakpoint appears as a red dot in the left margin.
Debugging in VS CodeThere are multiple ways to debug Jest tests with Visual Studio Code's built-in debugger. More information on Node debugging can be found here.
I found out the 'solution' myself. Add a .babelrc file into your root folder with the following content:
{
"sourceMap": "inline",
"retainLines": true
}
Then the problems are gone.
Even though I do not use Babel specifically, VS Code somewhat does.
Add the following to your vscode-jest-tests
config in launch.json
:
{
"disableOptimisticBPs": true
}
This worked for me and several other people.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With