Unit Testing in WebStorm 11
I recently wrote a series of post on using Visual Studio to write Node.js. Specifically, I detailed how to write unit tests using Mocha. Here I show the same detail but using WebStorm from Jetbrains. Webstorm was designed for Node.js development. Let’s get started and learn the differences.
Install WebStorm
Clone the NodejsTestingSimple project
WebStorm allows developers to clone projects directly from GitHub. This feature is very nice and hopefully this will come to Visual Studio. You can also open an existing folder.
- Clone (NodejsTestingSimple)[https://github.com/wbsimms/NodejsTestingSimple] from GitHub.
- Open the project
Run the project
- Right click on app.js and select Run.
You can also choose to debug the project.
Open the npm tool window
- View -> Tool Windows -> npm
You should see your run, test, watch tasks. They all work just as in Visual Studio.
However, WebStorm has much stronger support for testing than Visual Studio (right now!). But first, you need to add a configuration for testing.
Add a testing profile
- Select Run -> Edit Configurations
- Press the green plus (+) to add a new configuration
- Choose Mocha
- Name it “Testing”
- Set the testing directory to < Your File Path >\NodejsTestingSimple\TestConsole
- Select Include subdirectories
Run your tests
- Select the Testing configuration
- Press the green run arrow
All the test run but with a much nicer visualization. WebStorm has another nice feature. It will auto-test your code when a change is detected. It doesn’t use the watch flag from Mocha.
Overall take
- WebStorm has a bit tighter support for Node.js
- Code completion is much tighter
- Testing results interface is nicer
- WebStorm is very snappy
- Code formatting is better
Visual Studio is the only IDE you’ll ever need for just about any language. However, if I was ONLY writing Node.js, I would definitely choose WebStorm.