Unit Testing in WebStorm

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

  1. Webstorm Download

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.

  1. Clone (NodejsTestingSimple)[https://github.com/wbsimms/NodejsTestingSimple] from GitHub.
  2. Open the project

Run the project

  1. Right click on app.js and select Run.

You can also choose to debug the project.

Open the npm tool window

  1. View -> Tool Windows -> npm

You should see your run, test, watch tasks. They all work just as in Visual Studio.

npmRunner

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

  1. Select Run -> Edit Configurations
  2. Press the green plus (+) to add a new configuration
  3. Choose Mocha
  4. Name it “Testing”
  5. Set the testing directory to < Your File Path >\NodejsTestingSimple\TestConsole
  6. Select Include subdirectories

TestConfiguration

Run your tests

  1. Select the Testing configuration
  2. Press the green run arrow

Test Results

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.

Share this Post