简体   繁体   中英

Run/debug node.js testcases with jasmine in Webstorm 11

I install Webstorm 11 and want to run my tests (for node.js app) implemented with Jasmine. However it's not easy to do that. I could just type in command line 'jasmine' command and test will be runned, but in this case I'm not able to debug code. So is there a way to configure Webstorm to deal with jasmine specs as it should?

Ok, so while no one answer at the moment I will try to provide my version: This flow will allow to run jasmine testsute from Webstrom and debug testcases

  1. install jasmine (ither locally or globally)
  2. in project folder create folder 'spec/support' In this folder place jasmine.json

    tests configuration example:

     { "spec_dir": "tests", "spec_files": [ "**/*[sS]pec.js" ], "helpers": [ "helpers/**/*.js" ] } 
  3. Create node.js configuration in Webstorm

  4. In this configuration select source file - jasmine executable file (for localy installed jasmine it will be 'node_modules\\jasmine\\bin\\jasmine.js' )

So you are ready. However at the current moment when trying to debug this configuration - it fails with error:

Cannot stop on breakpoint due to internal error org.jetbrains.v8.V8CommandProcessor$1:

If you faced with it - you need to change Webstom configuration and set this settings:

-Dnodejs.debugger.use.jb.support=false For more details check there:

So this allow you to run jasmine tests and debug them. However there is still some things which this solution not able to do:

  1. Run individual testcases
  2. Run individual testcases with right click button and Run command from menu

Jetbrains, if you reading this - please fix this already. I started play with node in Webstorm 3 years ago and since that moment and dozens of version there is still no nice way to run tests. It's ridiculous.

Jasmine works with the JSTestDriver which you get out-of-the-box with WebStorm 11: https://www.jetbrains.com/webstorm/help/enabling-javascript-unit-testing-support.html

This page also details how to add Jasmine within JSTestDriver: https://www.jetbrains.com/webstorm/help/preparing-to-use-jstestdriver-test-runner.html

At a high level you're going to:

  1. Install JSTestDriver from JetBrains plugin repo
  2. Configure it as a WebStorm JavaScript library ( https://www.jetbrains.com/webstorm/help/configuring-javascript-libraries.html#configure )
  3. Open jsTestDriver.conf and type the following code in it:

load:

lib/jasmine/jasmine.js

lib/jasmine-jstd-adapter/JasmineAdapter.js

WebStorm doesn't manage test running directly. This job is done by a test runner. WebStorm supports several test runners - Mocha, Karma, JsTestDriver, nodeunit. Most of them can execute Jasmine tests

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM