I got an angular application that I need to unit test/debug.
Running the app works.
Running the tests with Karma & Jasmine from console works.
Running the tests with Karma & Jasmine from Intellij "run Configuration" works.
Putting a breakpoint in my tests and launching tests in debug fails.
I configured the latest Chrome as my test browser, installed JetBrains IDE Support extension, configured ok.
The karma server starts, Starts a new Chrome, which gets detected by the output of the Karma server but nothing else happens. Breakpoints are not hit.
Repeating the same process sometimes (!!) work, without changing anything.
Does someone managed to debug a unit test in karma using Jasmine (Mocha runner would work since it is provided in the default configurations of Intellij, but we use Jasmine here.)
Thanks !
Related
I am having a small issue with WebStorm that I am hoping someone has experienced and solved before.
I am using WebStorm to build a angular.js app and I have it set up to use Karma to run my tests. This is fine for the most part: I have a Karma configuration setup and I can get to to run the tests or debug them with no issue.
My problem is that when I try to run a test individually by clicking on one of the test in the "Test Run" tree it goes off to a node configuration, tries to run it and fails (because its looking for js dependencies). After that I just go back to my 'karma config' and it runs through the whole of the test no problem.
Does anyone know how I can get the IDE hooked up so that I can trigger my tests from the UI?
Running tests from file right-click menu is only supported for those runners that allow executing individual tests (JSTestDriver, for example). There is currently no such possibility for Karma (WEB-13173). See the discussion at https://github.com/karma-runner/karma/issues/1235.
to run individual test files, you can have several karma configuration files with different sets of tests included. Plus you can rename individual tests/suits in the way mentioned in https://github.com/karma-runner/karma/issues/553
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
install jasmine (ither locally or globally)
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"
]
}
Create node.js configuration in Webstorm
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:
Run individual testcases
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:
Install JSTestDriver from JetBrains plugin repo
Configure it as a WebStorm JavaScript library (https://www.jetbrains.com/webstorm/help/configuring-javascript-libraries.html#configure)
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
My general problem is how to run unit tests with karma in IE or other browser installed on a Windows machine, while karma is run on a Linux machine, though in the question below I might ask more specific question based on what I've already tried.
Also it may be worth to mention, that I have Windows installed on a Virtual box machine.
I started karma from a terminal, then opened in IE this url: http://10.0.2.2:9876 and saw the karma page in the browser window (though I spotted some quick blink with a red background, I suppose it is related to an error I'll mention further).
After that I tried to run tests with the command: node_modules/karma/bin/karma run config.js in another terminal tab. When I did this I got this error (I get it even when I use Chrome on my Linux host-machine instead IE on the Virtual box guest, so I suppose the error has nothing to do with networking):
You need to include some adapter that implements __karma__.start method!
I googled for this error and found another question: Error: You need to include some adapter that implements __karma__.start method
Supposing that I need to run tests from the same place I started karma-server I tried to redirect the output to another tab:
$node_modules/karma/bin/karma start &> /dev/pts/17 &
$node_modules/karma/bin/karma run config.js
But this did not help. If I try to start server and run tests in a single command, then I do not have time to register IE.
So could anyone please answer any of the next questions:
how to run unit tests with karma in a browser on other machine?
how to get rid of this error You need to include some adapter that implements __karma__.start method!, if the karma server was started in one terminal tab and the run command was issued in another?
how to start the karma server and run tests in separate steps, i.e. issue the karma start and karma run config.js commands instead of karma start config.js?
My regards and sincerest appreciation in advance for any help.
Currently I've found a workaround for this. I start karma with the config file:
karma start config.js
in the config I have singleRun: false.
Then I manually connect my IE instance, and after this I run the tests from another terminal tab. Why this happens I have no idea. The only inconvenience is that I always have browsers' windows open.
I have got javascript tests running in visual studio using Resharper and Jasmine. It all works fine. Now however I want to run an integration test. After looking into this I just can't work out whether I should be using Karma or PhantomJs or both? And whether they link to resharper?
I then have to run all my tests on the continuous integration server using Team City. Doesn't seem like there is a clear logical way to architect front end testing from dev right through to the CI server.
For example do I really need to use Karma locally and on the CI server? I don't want to because it is not baked into visual studio and I will have to keep opening the command line and running my tests manually. This will annoy other developers and they won't bother running them I imagine. Help!
We are using Team City by the way....
Neither of these test runners are connected to Resharper in any form. I don't think there is a one and only "correct" way of running Jasmine tests in TeamCity currently - for all approaches I am aware of there is a bit of assembly required.
Personally I am using a combination of PhantomJS and the Jasmine TeamCity Reporter which works like this:
Get a list of unique test URLs from server - each of these test suites will use the Jasmine TeamCity Reporter to log results
for each test URL dynamically generate a test JS file to be used for phantom and write it to disk
use PhantomJS to run the JS file which now will load the test suite page and its test result will be written to console where they are picked up by TeamCity.
I suppose I'm asking about what the proper procedure is.
I'm running Webstorm 7.0.3. I do not have node setup. I'm using the in place hosting on my local machine.
I have written unit tests, and can put a debug breakpoint in the test.js file. When I right-click and 'debug' my karma.conf.js file, it hits these breakpoints fine. Which is great for for basic stuff, but sometimes I need to go line by line inside a service.
Any breakpoints I place inside the service get skipped and ignored.
I have to assume this is is because karma is wrapping my actual script into some proxy file for execution.
How do I step through the service line by line? I feel like I missed something very obvious.
[Update]
#Eitan's comment was what i needed.
I assumed the karma task runner automatically wrapped all source up into the indecipherable un-debuggable non-sense. I never stopped to assume that putting the coverage pre-processor was responsible for it. Commenting the coverage reporter and pre-processor for karma-coverage now allows me to debug my unit tests from the karma chrome instance and from webstorm.
Are using the coverage reporter? It uses instrumented code so I guess you won't be able to debug your original file
You could launch chrome in your karma config and step through your service with dev-tools. I don't know if you can actually do it from within WebStorm because of the exact reason you mentioned (karma server). Just click the big DEBUG button on the upper right of the karma controlled chrome instance and open the scripts in dev-tools