Karma mocha and jscoverage - node.js

We have an application written in coffee-script with node.js and are struggling to set up code coverage tools.
At the moment we have code-coverage up and running for the serverside with
coffeeCoverage
jscoverage
mocha
The front end unit tests are functions with the karma test runner and mocha, and working well. But I just can't seem to find a way to get the same kind of output from karma.
Here is the command being used for the serverside:
mocha --compilers coffee:coffee-script --require chai --reporter html-cov --recursive test/mocha > coverage.html
it would seem that because the front end is also in mocha and coffee-script we should be able to do the same thing there. But karma does not support the html-cov reporter, and that has left me at somewhat of a dead end.
The ideal path is that karma would run like normal in phantomjs and use the mocha html-cov reporter to output an html file. Does anyone know were to go from here?
Here is a portion of my Cake task for the serverside just for reference.

karma-coverage plugin uses Istanbul to instrument the source files and generate the coverage reports.
There's a pending issue to enable the same for coffee script too https://github.com/karma-runner/karma/issues/622

I highly recommend switching from jscoverage to istanbul to calculate your code coverage. istanbul supports mocha (be sure to call _mocha) and is the default code coverage tool for karma. Details here: Code coverage with Mocha

Related

Get combined code coverage for cucumber-js and mochaJS test cases using NYC

In our codebase, we have written acceptance test cases in cucumber-js and unit tests in mocha js. The individual way to run these is by:
Mocha - "test:mocha-coverage": "nyc npm run test"
Cucumber - "test:cucumber-coverage": "nyc npm run test:cucumber"
Now we want to get a combined code coverage by these two. I have tried running both test cases together inside NYC but that did not work. Has someone done this?

Nyan/TAP/List Reporter for Mocha

I am using mocha and chai for testing my NodeJS application. But I am not able to figure out how to use reporting tools like Nyan or others. I could not find any tutorial for this also. Any help will be highly appreciated.
with mocha nyan:
mocha test.js -R nyan

Jasmine tests through bamboo?

I would like to integrate the jasmine tests with bamboo, but I'm not sure is it possible.
The best what I found so far is https://bitbucket.org/atlassian/bamboo-nodejs-plugin which support just mocha tests. I would like to know is there any way to change node-jasmine output to be compatible with bamboo.
Thanks
Resolved:
Using option --junitreport and than use that report in bamboo to show the results,
This is 3 years too late, but hopefully it can help some other people aswell.
For Karma you can use karma-junit-reporter npm package.
install it and add this to your Karma config file
config.set({
reporters: ['progress', 'junit'],
...
Then you can run your test and it will generate a JUnit xml file.
Use the JUNIT parser in bamboo and read this file. It should pick up your tests then.

istanbul code coverage with mocha tests with coffeescript

I'm using mocha to run tests that are purely in coffeescript. I also want to be able to use istanbul to generate code coverage reports.
Note, I'm using mocha with option --compilers coffee:coffee-script/register within the mocha.opts file.
The issue I'm running into is that tests that require other coffeescript source files aren't covered. If instead, I require js files, it's covered fine.
Am I missing something?
My npm test command is: istanbul test --report html -x 'vendor/**' _mocha. I use npm test --coverage to enforce istanbul's coverage utility.
Here is a sample of a mocha test (./test/test.coffee):
# Project
# require ../src/main.coffee
main = require('../src/main')
# Chai
chai = require('chai')
assert = chai.assert
should = chai.should()
expect = chai.expect
describe 'something', (done) ->
describe "when given something", ->
it "should do this", ->
# tests using chai API here
something = new main()
I use coffee-coverage instead with these instructions.
I've been searching around for this as well. It doesn't look like istanbul can cover CoffeeScript files (although there is a pull request open, so hopefully we'll see it soon). There's a project called ibrik which uses istanbul and a CoffeeScript parser to cover your code. However, I can't seem to find how to integrate it with Mocha yet. A problem which a lot of people seem to have.

using Blanket.js for a compoundjs app to generate coverage report

I have compoundjs application in which I have used the scaffold generator to generate controller and its test cases. The test cases are running correctly. But I need to generate the code coverage report for the same. I am trying to use blanket.js for the same.
I have configured blanket.js like this in package.json in scripts :
"blanket": { "pattern": "app" }
app is the folder which contains all my controllers, models etc. And then I am running test cases having reporter as :
mocha test/init.js test/controllers/sample_controller.test.js --require blanket -R html-cov > coverage.html
This is actually properly generating coverage report for it. But the problem I am facing is it is only showing the code coverage for certain files like it is showing code coverage for model/sample but not for controllers/sample_controller.js.
Please help me out ASAP as I am actually stuck with it.
Thanks a lot in advance,
Option 1: Try using _mocha instead of mocha to avoid mocha forking and not covering all of your code in the same process.
Option 2: I highly recommend istanbul as a coverage tool. Try:
npm -g install istanbul
istanbul cover _mocha -- test/init.js test/controllers/sample_controller.test.js --require blanket -R spec
open coverage/lcov-report/index.html
More info here: https://github.com/gotwarlost/istanbul/issues/44
These are eval controllers, right? I'm investigate coverage for eval controllers in the next release of Blanket (v1.1.3). In the meantime Istanbul is an option, as is grunt-blanket.

Resources