Let’s see how typical integration test looks like for the controller method self.approveUser mentioned above. Integration Tests DebuggingĪssuming we have our web API running on localhost:3333, we might want to test it with integration tests. But actually, you don’t event need to understand anything of that magic, unless you need some custom configuration. Most of the parameters passed here are basically mocha params. Under the hood IntellijIdea uses ts-node, so that typescript code is transpiled on the fly. Here’s the command IntellijIdea uses to execute debugging session with mocha passing -require ts-node/register: "C:\Program Files\nodejs\node.exe" -inspect-brk=58345 C:\Git\debug-ts\node_modules\mocha\bin\_mocha -require ts-node/register -timeout 0 -ui bdd -reporter C:\Users\me\.IntelliJIdea2017.2\config\plugins\NodeJS\js\mocha-intellij\lib\mochaIntellijReporter.js C:\Git\debug-ts\server\test\unit\users\ -grep "UNIT\: users\.ctrl approveUser approve customer passing current user$" If you are using ECMAScript Modules in your project, IntelliJ IDEA detects them and adds the experimental-vm-modules flag to the Node options field automatically. ![]() Otherwise, by default the debug process will use V8 Debugging Protocol. ![]() Clicking on debug will execute the test and IDE will instantly stop on the first breakpoint.įirst of all, we can see that typescript code wasn’t transpiled, which is great as we want to see original code while debugging. Use -inspect or -inspect-brk parameter when you are using Node.js v7 for Chrome Debugging Protocol support. Like this:Īs you’ve probably noticed on the second image, IntellijIdea have recognized the test and placed special icons that can be used to execute either single test or the whole spec at once. Clicking on any of the icons will display menu where you can select what do you want to do: Run or Debug. Lets say we want to set one breakpoint in the test and one in the method itself. Here’s the typical controller logic you might want to unit-test: self.approveUser = async (req, res, next) => , To create a new Run/Debug configuration, click Edit configurations in the top right corner of the IDE window, or in the main menu Run. Now we can get started! Unit Tests Debuggingįirst and easiest thing to debug is unit tests. WebStorm allows you to run Node.js application locally on your machine: you should create a Node.js Run/Debug configuration for the file you need to execute and click Run. Of course, you might even go without any IDE-based debuggers and build cool things with NodeJs and Typescript, however sometimes it’s very useful if you can put some breakpoints and dig into your running code in your IDE. There’re a lot of tutorials over the internet showing how to do that. We’ll just look at small part of this process, and namely debugging, which is usually not really covered in tutorials mentioned above. ![]() Note, that in this material you won’t find any steps to bootstrap your application with Express/Typescript. Write a catching NodeJS Developer resume using SweetCV – an amazing online CV builder. □️ Hey! Want to be a rock star NodeJS Developer?
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |