Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9222599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:52:14+00:00 2026-06-18T03:52:14+00:00

I am trying to get what lines of code my unit tests do not

  • 0

I am trying to get what lines of code my unit tests do not cover.

I do my unit tests with mocha, which offers a reporter “json-cov” which should report how many lines I didn’t execute.

I have two files, the first one (foo.js):

module.exports = function () {
    for (var result = 0, i = 0; i < arguments.length; i++) {
        result += arguments[i];
    }
    return result;
}

and the second one (test.js):

var expect = require('expect.js'),
    jsc = require('jscoverage'),
    //foo = require('./foo.js');
    foo = jsc.require(module, './foo.js');

describe('foo', function () {
    it('should add all arguments', function () {
        expect(foo(1,1)).to.be(2);
    });
});

When I run mocha -R json-cov test.js I get the following result:

{
  "instrumentation": "node-jscoverage",
  "sloc": 0,
  "hits": 0,
  "misses": 0,
  "coverage": 0,
  "files": [],
  "stats": {
    "suites": 1,
    "tests": 1,
    "passes": 1,
    "pending": 0,
    "failures": 0,
    "start": "2013-01-30T18:00:15.785Z",
    "end": "2013-01-30T18:00:15.787Z",
    "duration": 2
  },
  "tests": [
    {
      "title": "should add all arguments",
      "fullTitle": "foo should add all arguments",
      "duration": 1
    }
  ],
  "failures": [],
  "passes": [
    {
      "title": "should add all arguments",
      "fullTitle": "foo should add all arguments",
      "duration": 1
    }
  ]
}

What am I doing wrong, so that sloc, hits, misses and coverage are 0?

I also tried to use nodes require instead of jscs, without success.

EDIT: I just tried mocha -R json-cov test.js --coverage which results in an error if I use jscs require. When I use nodes require the result is the same as above.

EDIT: I can’t even run jscoverage from console. I created a folder foo and foo-cov and copied my foo.js in the folder foo. Then I ran jscoverage foo foo-cov which gave me an error abs source path or abs dest path needed!. I also tried absolute paths and a few other ways to arrange the arguments. No success. How can I prepare the files for jscoverage?

EDIT: If it is of any relevance, I am using Windows.

EDIT: Just realized that there isn’t only a single ‘jscoverage’ package available via npm, but also a ‘visionmedia-jscoverage’. Trying to install that one fails. Probably because of Windows vs. Linux.

EDIT: Got it to work. Instead of using a node package to prepare the code, I now just run jscoverage.exe (downloaded from here) from the console, and then go with mocha -R html-cov test.js > coverage.html. Now I have the problem that some code gets escaped. So I get

<span class="k">var</span> foo <span class="k">=</span> <span class="k">{</span>

instead of

var foo = {

with highlighting.

EDIT: The tags got escaped because they were rendered via a jade template with this code: td.source= line.source

Changing this to td.source!= line.source fixes this last issue I had.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:52:16+00:00Added an answer on June 18, 2026 at 3:52 am

    Follow my EDITs to see what I did to solve this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to code-coverage, and I am trying to get my unit tests
I'm currently trying to get one of my unit tests to work, but there
I'm trying to get the exact equivalent (not functional) of this vb.net code in
I have a unit test which contains the following line of code Site.objects.get(name=UnitTest).delete() and
I'm trying to get from Line #1 to Line #2 in the below code:
I'm trying to figure out how to get the visible lines in a IWpfTextView
I'm trying to parse words which can be broken up over multiple lines with
Is NSInvocation class not meant to be called via unit tests (for iPhone)? My
I'm using Emacs and trying to get my unit testing work flow as automated
Folks, I've a large legacy .Net code base, and I'm trying to introduce Unit

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.