Once again, I went back from
WebStorm because some annoying bugs which I can’t evaluate variables at runtime. But configuration in Visual Studio code could be a little bit tricky sometime. Thanks to my time spent before, I grabbed an old configuration, after modification, it works flawlessly in the current release of Visual Studio Code. Let’s see how to debug Jest test cases in VSC.
.vscode folder inside your project, create a
launch.json if you don’t have one, if you already have one, just grab the part you need.
The configuration is as the following:
Now put a break point somewhere in your test file.
Press that green play button in debug panel.
argsis where you put extra command line parameters for
- If you want to point to a specific config file, you can use the above example, the
configfolder I use is a direct sub-folder in the
Add the following line to the settings:
It will show variable values inline in editor while debugging. Which is pretty useful, must more clear than hovering your mouse there, it’s
false by default, so, turn it on if you haven’t.
If you run test via NPM command and always saw that verbose NPM warnings when the test fails, you might not be that happy. Th reason is an old convention, if the program return 1 when exit which means something wrong happens. But here we just don’t want to see that.
So hope the following tips could satisfy you. Just add a
|| true to the end of the script.
Or, you can do it when you run the command by adding an extra parameter
npm run test --silent
Hope it helps. :)
Thanks for reading!
Follow me (albertgao) on twitter, if you want to hear more about my interesting ideas.