Adding code coverage to async node.js mocha tests in WebStorm - javascript

I am trying to set up code coverage for my node.js unit tests.
What I am trying to do is this:
Use WebStorm for running tests
use Mocha (and co-mocha) as a testing framework
Use yield and generators for making my test code more readable
See the code coverage of my source code via the WebStorm UI (hoping to see my source code files color-coded according to code coverage)
The first two points are going fine, the third one is tripping me up.

Unfortunately WebStorm doesn't provide coverage support for Mocha:( Please follow WEB-10373 for updates

Related

The same file's coverage of entire project not equal to run itself only

I've publish a tool which based on jest to test my code and collect coverage.
I found the same file's coverage in entire coverage report can't match single one file coverage report since I use v8 coverage provider.
This is my coverage of entire project.
It can't match the result that I run jest in single one file.
I think it maybe v8 coverage problem and also try out babel coverage, It seems OK.
So, the problems is that I can't remember why I use v8 instead of babel becuase leave on a warnning in my tool.
Is there any problems if I switch v8 to babel?

Intern is not showing Code Coverage for Browser Tests

I have a sample project that I am using to write Unit Tests for Dojo modules before moving our to my main project. I have tests that are successfully running in node and chrome environments, but the coverage report is only reporting coverage for the tests executed in the node environment.
Below is a link to the sample project. Does anyone have any ideas why the code coverage report is not showing the metrics for TestModule_Dijit.js file specifically?
SampleProject.zip
Thanks in advance
I tried your sample project, and it appears to be working fine. At least, when running Intern I see coverage reports for both the browser and Node.
Note that coverage is only gathered for browser tests that are managed Intern running in Node. In other words, tests run when you call intern from the command line will collect coverage, whether they're run in Node or in a browser. Tests run using the browser client, where you manually browse to http://localhost:9000/__intern/, will not collect coverage.
Unrelated to the original question, I noticed that you're gathering coverage data for your tests rather than the source files. In general, coverage is most meaningful for the source since the point of test coverage data is to show how much of your application code is being exercised by the tests (not how much of the test code itself is running).

too high Code Coverage in KarmaJS with karma-coverage & Jasmine

I'm using Jasmine as the testing framework for my AngularJS application. I run the tests with the help of Grunt & KarmaJS. KarmaJS also generates the code coverage with the help of karma-coverage.
Now I've created a model for configuaration data, which I also have to instantiate for other tests. Because of this instantiation I get a code coverage for this file although I haven't done any tests for it. Only because while the test run all of the lines were used, the coverage is 100%.
Now the question: Is there a way to specify in my tests which files they cover?
In PHP Unit there is an #covers annotation which specifies what code is covered with the test.
Thx
Since karma-coverage uses Istanbul under the hood, all configuration for Istanbul should work for karma-coverage.
In Istanbul, you can specify that a block of code be ignored for coverage purposes. You can try placing something like this at the top of your file:
/* istanbul ignore next */
I haven't tried this myself, but I'd bet that this or something similar would do what you want it to do.

Node.js Code Coverage of Certain Test Files

I just came into a Node.js project that has a ton of unit tests, most of which, unfortunately, are outdated and don't run. There's no test runner or any kind of code coverage tool implemented, and it is certainly not in my scope of work to refactor everything.
That being said, that doesn't stop me from wanting to check the code coverage of my work. I've looked at both Istanbul and Blanket and can't find a way to only have them run certain unit tests. Surely, there is a way so that I can get a report that, obviously, reports a very low percentage of coverage, but that I can dive into certain files and such (those that my tests hit) to ensure my code is throughly tested.
With istanbul.js, you can easily get the coverage information this by for example specifying the following command (Following example uses mocha but it will be similar for any test framework):
istanbul cover node_modules/.bin/_mocha -- -u exports -R spec test/test1.spec.js test/test2.spec.js
You can also specify all the tests in particular sub-directory eg: test/yourfeaturetest/*.spec.js. You also have something like test/myfeature/**/*.spec.js to cover all the tests in the test/myfeature directory including tests that could have been created recursively in sub-directories.
As for me, I use gulp and thus utilize plugins such as gulp-istanbul and run tests and coverage via gulp tasks.

Concurrent/Continuous Testing for nodejs (ncrunch for nodejs)

I'm a big fan of the continuous testing setup offered by NCrunch in Visual Studio, and would love to have a similar setup with nodejs.
When writing JavaScript in node I use Sublime Text 2 as my editor, with tests written using Mocha.
I wondered if there was software (or a ST2 plugin) for achieving similar concurrent testing to that offered by NCrunch when writing .NET code?
After doing some digging around I've decided that the solution for the moment is:
Server-side: Mocha
mocha -w test
Using mocha's built-in watch functionality.
Client-side: Testacular
I'm now using testacular, which is truly awesome. It would be great it if had hooks for running the server-side watch progress in tandem, but not really a problem.
I haven't tried it myself yet but it looks promising: wallaby.js The description from the website has the following description
Wallaby.js is an intelligent test runner for JavaScript that
continuously runs your tests. It reports code coverage and other
results directly to your code editor immediately as you change your
code. Wallaby.js uses various tricks to run your tests as fast as
possible, such as dependency analysis to only execute tests affected
by your code changes and parallel test execution.

Categories