NodeJS Coverage Using Karma

I am trying to get lighting from my project. Because of my IDE (IntelliJ), I am using Karma

with mocha

. To make the tests pass in karma, I also added browserify

. But I'm just getting the coverage of the tests not from the actual code:

enter image description here

Here is mine karma.conf.js

:

"use strict";

module.exports = function(config) {
  config.set({
    basePath: "",
    frameworks: ["mocha", "browserify"],
    files: [
      "test/**/*Test.js"
    ],
    exclude: [
        "src/Main.js"
    ],
    preprocessors: {
      "test/**/*Test.js": ["browserify"],
      "src/**/*.js": ['coverage']
    },
    reporters: ["progress", "coverage"],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ["Chrome"],
    singleRun: false,
    browserify: {
      debug: true,
      transform: [ "browserify-shim" ]
    }
  });
};

      

And an excerpt from mine package.json

:

{
  ...

  "dependencies": {
    "nssocket": "^0.5.3",
    "winston": "^1.0.0"
  },
  "devDependencies": {
    "browserify": "^10.2.4",
    "browserify-shim": "^3.8.8",
    "karma": "^0.12.36",
    "karma-browserify": "^4.2.1",
    "karma-coverage": "^0.4.2",
    "karma-mocha": "^0.1.10",
    "mocha": "^2.2.5"
  },
  "browserify-shim": {}
}

      

I tried to add all the code files in the karma.conf.js

files[]

, but then I get different Uncaught TypeError

way scroll:

files: ["src/**/*.js", ...
preprocessors: {"src/**/*.js": ["browserify"], ...

      

UPDATE:

I created two test files, but they have no coverage:

test/TestTest.js

"use strict";

var assert = require("assert");
var test = require('../src/Interface/Test.js');

describe("Test", function () {

    describe("Test test, 5", function () {
        it("Test true 5", function () {
            assert.equal(test.addOneOnTrue(true, 5), 6);
        });

        it("Test false", function () {
            assert.equal(test.addOneOnTrue(false, 5), 5);
        });
    });
});

      

src/Test.js

var Test = function() {
    this.addOneOnTrue = function (boolean, int) {
        if(boolean) {
            ++int;
        }
        return int;
    }
};

module.exports = new Test();

      

+3


source to share


1 answer


Use the following process:



  • Modify the preprocessor template coverage

    to match explicitly src

    :

    "src/**/*.js": ["coverage"]
    
          

  • Restart karma

  • Check report
0


source







All Articles