Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

karma coverage does not show any data #87

Closed
priyabrat1801 opened this issue Jul 10, 2014 · 53 comments
Closed

karma coverage does not show any data #87

priyabrat1801 opened this issue Jul 10, 2014 · 53 comments
Labels

Comments

@priyabrat1801
Copy link

I have included the source files in the files & preprocessors section of my karma conf file. The tests run fine and the junit xml report shows the data. The html coverage just show 100% without any data. I have the similar structure for another project which is working fine but not this one. Not sure if i am missing something. Might be a very minor or silly thing i have missed.

karma.conf.js:

    module.exports = function (config) {
    config.set({
    basePath: '../../',

    frameworks: [
        'jasmine'
    ],

    // list of files / patterns to load in the browser
    files: [
        'app/js/**/*.js',
        'test/spec/**/*.js'
    ],

    preprocessors: {
        'app/js/**/*.js': ['coverage']
    },

    exclude: [],

    reporters: [ 'progress', 'junit', 'coverage' ],

    coverageReporter: {
        type: 'html',
        dir: 'test/reports/unit/coverage'
    },

    junitReporter: {
        outputFile: 'test/reports/unit/junit/junit.xml',
        suite: 'unit'
    },

    port: 9876,

    runnerPort: 9100,

    colors: true,

    logLevel: config.LOG_DEBUG,

    autoWatch: false,

    browsers: [ 'Chrome' ],

    captureTimeout: 60000,

    singleRun: true
});
};

my karma conf file is in test -> spec -> conf
and source files are in app -> js -> controllers/directives/services

the debug log shows its loading all the files in preprocessors but the report does not show any data "No data to display".

@priyabrat1801
Copy link
Author

An update to the above:
I just misspelled preprocessors to preprocessor intentionally in the karma conf file and ran the test. Sure enough it ran without the preprocessor being loaded. Then corrected it back and ran the test again. This time the data is shown in the coverage.

However, next run of the tests did not update the data as the old data was still showing.(Checked the timestamp of the run). Now i deleted the reports directory and ran the tests again. No data is displayed in the report. Not sure where i am doing wrong.

@kmackinnon
Copy link

Same issue as @priyabrat1801. I'm wondering if it has something to do with basePath.

@dsuckau
Copy link

dsuckau commented Aug 27, 2014

I have the same behavior. Tests run fine, even browserified, but coverage is 100% with "no data to display".

My tests are in test/unit/, my source coude is located in lib/. The tests require() the source code per file.

From my package.json:

"grunt-karma": "^0.8.3",
"karma-bro": "^0.6.2",
"karma-coverage": "^0.2.6",
"karma-junit-reporter": "^0.2.2",
"karma-mocha": "^0.1.8",
"karma-phantomjs-launcher": "^0.1.4",
"karma-webdriver-launcher": "^0.2.0",

From my Gruntfile:

...

karma: {

    options: {
        files: [
            'test/unit/**/*.js'
        ],
        singleRun: true,
        hostname: getIpAddress(), // Network IP, for WebDriver connection
        customLaunchers: getCustomLaunchers(), // WebDriver (FF, Chrome, IE)
        frameworks: [
            'mocha',
            'browserify'
        ],
        reporters: [
            'progress',
            'junit',
            'coverage'
        ],
        preprocessors: {
            'test/unit/**/*.js': [
                'browserify'
            ],
            'lib/**/*.js': [
                'coverage'
            ]
        },
        coverageReporter: {
            type: 'html',
            dir: 'test/coverage/'
        },
        logLevel: 'DEBUG'
    },

    local: {
        browsers: [
            'PhantomJS'
        ],
        junitReporter: {
            outputFile: 'test/junit/unit-local.xml'
        }
    },

    remote: {
        browsers: [
            'firefox',
            'chrome',
            'ie9',
            'ie10',
            'ie11'
        ],
        junitReporter: {
            outputFile: 'test/junit/unit-remote.xml'
        }
    }

}

...

grunt.registerTask('unit-test-local', 'Run unit tests locally', [
    'karma:local'
]);

grunt.registerTask('unit-test-remote', 'Run unit tests remotely', [
    'karma:remote'
]);

grunt.registerTask('unit-test', 'Run unit tests', [
    'unit-test-local',
    'unit-test-remote'
]);

When I run grunt unit-test-local, I get the following output. There is no coverage preprocessor in the log:

Running "karma:local" (karma) task
DEBUG [config]: No config file specified.
DEBUG [config]: autoWatch set to false, because of singleRun
DEBUG [plugin]: Loading karma-* from /Users/dsuckau/Sites/browserify/caramba-type/node_modules
DEBUG [plugin]: Loading plugin /Users/dsuckau/Sites/browserify/caramba-type/node_modules/karma-bro.
DEBUG [plugin]: Loading plugin /Users/dsuckau/Sites/browserify/caramba-type/node_modules/karma-coverage.
DEBUG [plugin]: Loading plugin /Users/dsuckau/Sites/browserify/caramba-type/node_modules/karma-junit-reporter.
DEBUG [plugin]: Loading plugin /Users/dsuckau/Sites/browserify/caramba-type/node_modules/karma-mocha.
DEBUG [plugin]: Loading plugin /Users/dsuckau/Sites/browserify/caramba-type/node_modules/karma-phantomjs-launcher.
DEBUG [plugin]: Loading plugin /Users/dsuckau/Sites/browserify/caramba-type/node_modules/karma-webdriver-launcher.
DEBUG [plugin]: Loading inlined plugin (defining launcher:firefox, launcher:chrome, launcher:ie7, launcher:ie8, launcher:ie9, launcher:ie10, launcher:ie11).
DEBUG [framework.browserify]: bundle file used: /var/folders/vs/4c27pwr579l4y0xqxx3bc0d80000gn/T/48225fe42f3fee3e3a1439e57cbb2a673d22ea4a.browserify
DEBUG [framework.browserify]: insert browserified bundle in config.files at position 2
INFO [karma]: Karma v0.12.22 server started at http://192.168.2.154:9876/
INFO [launcher]: Starting browser PhantomJS
DEBUG [temp-dir]: Creating temp dir at /var/folders/vs/4c27pwr579l4y0xqxx3bc0d80000gn/T/karma-80525436
DEBUG [launcher]: /Users/dsuckau/Sites/browserify/caramba-type/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/bin/phantomjs /var/folders/vs/4c27pwr579l4y0xqxx3bc0d80000gn/T/karma-80525436/capture.js
DEBUG [framework.browserify]: creating initial bundle
DEBUG [framework.browserify]: added file to bundle: test/unit/Array.js
DEBUG [framework.browserify]: added file to bundle: test/unit/Util.js
DEBUG [web-server]: serving: /Users/dsuckau/Sites/browserify/caramba-type/node_modules/karma/static/client.html
DEBUG [framework.browserify]: building bundle
DEBUG [web-server]: serving: /Users/dsuckau/Sites/browserify/caramba-type/node_modules/karma/static/karma.js
DEBUG [web-server]: upgrade /socket.io/1/websocket/G54tOomOfQiWy-Ls75hf
DEBUG [karma]: A browser has connected on socket G54tOomOfQiWy-Ls75hf
INFO [PhantomJS 1.9.7 (Mac OS X)]: Connected on socket G54tOomOfQiWy-Ls75hf with id 80525436
DEBUG [launcher]: PhantomJS (id 80525436) captured in 1.565 secs
INFO [framework.browserify]: bundle built (810ms, 320kB)
DEBUG [framework.browserify]: built initial bundle
DEBUG [framework.browserify]: created stub for file: test/unit/Array.js
DEBUG [framework.browserify]: created stub for file: test/unit/Util.js
DEBUG [watcher]: Resolved files:
    /Users/dsuckau/Sites/browserify/caramba-type/node_modules/mocha/mocha.js
    /Users/dsuckau/Sites/browserify/caramba-type/node_modules/karma-mocha/lib/adapter.js
    /var/folders/vs/4c27pwr579l4y0xqxx3bc0d80000gn/T/48225fe42f3fee3e3a1439e57cbb2a673d22ea4a.browserify
    /Users/dsuckau/Sites/browserify/caramba-type/test/unit/Array.js
    /Users/dsuckau/Sites/browserify/caramba-type/test/unit/Util.js
DEBUG [web-server]: serving: /Users/dsuckau/Sites/browserify/caramba-type/node_modules/karma/static/context.html
DEBUG [web-server]: serving (cached): /Users/dsuckau/Sites/browserify/caramba-type/node_modules/mocha/mocha.js
DEBUG [web-server]: serving (cached): /Users/dsuckau/Sites/browserify/caramba-type/node_modules/karma-mocha/lib/adapter.js
DEBUG [web-server]: serving (cached): /var/folders/vs/4c27pwr579l4y0xqxx3bc0d80000gn/T/48225fe42f3fee3e3a1439e57cbb2a673d22ea4a.browserify
DEBUG [web-server]: serving (cached): /Users/dsuckau/Sites/browserify/caramba-type/test/unit/Array.js
DEBUG [web-server]: serving (cached): /Users/dsuckau/Sites/browserify/caramba-type/test/unit/Util.js
PhantomJS 1.9.7 (Mac OS X): Executed 37 of 37 SUCCESS (0.023 secs / 0.007 secs)
DEBUG [karma]: Run complete, exitting.
DEBUG [launcher]: Disconnecting all browsers
DEBUG [framework.browserify]: bundle file cleaned up
DEBUG [coverage]: Writing coverage to /Users/dsuckau/Sites/browserify/caramba-type/test/coverage/PhantomJS 1.9.7 (Mac OS X)
DEBUG [launcher]: Process PhantomJS exited with code 0
DEBUG [temp-dir]: Cleaning temp dir /var/folders/vs/4c27pwr579l4y0xqxx3bc0d80000gn/T/karma-80525436
DEBUG [reporter.junit]: JUnit results written to "/Users/dsuckau/Sites/browserify/caramba-type/test/junit/unit-local.xml".

But when I change the preprocessors config to:

preprocessors: {
    'test/unit/**/*.js': [
        'browserify'
    ],
    '**/lib/**/*.js': [
        'coverage'
    ]
}

...I get:

DEBUG [preprocessor.coverage]: Processing "/Users/dsuckau/Sites/browserify/caramba-type/node_modules/karma-mocha/lib/adapter.js".

And I have coverage reports for adapter.js of karma-mocha :D

@michahell
Copy link

Same problem, previous solutions did not work. tests run fine, 100% pass, html report is also being created. in the debug information i can see

DEBUG [preprocessor.coverage]: Processing "<somefile>.js"

messages pass by and also later on:

DEBUG [coverage]: Writing coverage to /coverage

Below my karma.conf.js:


// temp set environment variable for node-webkit
process.env.NODEWEBKIT_BIN = '/Applications/node-webkit.app/Contents/MacOS/node-webkit';

module.exports = function(config){
  config.set({

    basePath : './',

    files : [
      'App/bower_components/jquery/dist/jquery.js',
      'App/bower_components/angular/angular.js',
      'App/bower_components/bootstrap/dist/js/bootstrap.js',
      'App/bower_components/angular-bootstrap/ui-bootstrap.js',
      'App/bower_components/angular-animate/angular-animate.js',
      ...
      'App/scripts/controllers/**/*.js',
      'App/scripts/directives/**/*.js',
      'App/scripts/filters/**/*.js',
      'App/scripts/services/**/*.js',
      'App/scripts/modules/**/*.js',
      'App/scripts/tests/**/*.js'
    ],

    frameworks: ['jasmine'],

    browsers : ['NodeWebkit'],

    singleRun: true,

    reporters: ['progress', 'coverage', 'html'], 

    preprocessors: {
      // source files, that you wanna generate coverage for
      // do not include tests or libraries
      // (these files will be instrumented by Istanbul)

      // 'App/scripts/node-webkit-config.js' : ['coverage'],
      // 'App/scripts/app.js' : ['coverage'],
      'App/scripts/controllers/**/*.js' : ['coverage']
      // 'App/scripts/directives/**/*.js' : ['coverage'],
      // 'App/scripts/filters/**/*.js' : ['coverage'],
      // 'App/scripts/services/**/*.js' : ['coverage'],
      // 'App/scripts/modules/**/*.js' : ['coverage']
    },

    // optionally, configure the reporter
    coverageReporter: {
      type : 'lcovonly',
      dir : 'coverage',
      subdir: '.'
    },

    htmlReporter: {
      outputFile: 'karma.report.html'
    }

  });
};

Any idea what could be causing it ?

@deepsweet
Copy link

the same problem here. any ideas?

@michahell
Copy link

So, somehow, without me touching anything related to karma-coverage, it started to generate lcov.info a few commits later. I have no idea what caused this, kind of stochastic behaviour if you ask me. Might it be related to one of my jasmine tests failing? but that should not matter right? weird.

@andrewconnell
Copy link

+1... my samples would show the same thing others are reporting. Using any of the formatters I see 100% coverage & no files reported when I add a single function that has no tests applied.

@kerbyfc
Copy link

kerbyfc commented Sep 30, 2014

+1
I have the same problem for safari and opera

@jacalata
Copy link

jacalata commented Oct 2, 2014

I was having this problem today and eventually narrowed it down to one of my jasmine tests which was calling $(window).trigger('beforeunload'). This caused Phantom to throw an error (" some of your tests did a full page reload!") and in turn also caused the coverage pass to stop, it seems. When I removed that line from the test I got full coverage results once more. (Oddly enough that test was listed as passing in the results, but not all tests were being executed).

@ymc-sise
Copy link

Same problem here. Using any of the formatters I see 100% coverage & no files reported. The tests are successfull.

@azaslavsky
Copy link

Exact same problem here for PhantomJS 1.9.8

@azaslavsky
Copy link

Hmm, not sure how much this will help other people, but this worked for me. I reverted my jasmine-core to version 2.0.4, and things seem to be working ok. The newer version seems to have caused some small problems over at karma-jasmine, so maybe this is related? The process still "hangs" on completion and doesn't close PhantomJS properly, but the coverage and HTML reports are all there, which was not the case before.

@johnpapa
Copy link

johnpapa commented Jan 9, 2015

+1 as I am also seeing 100% coverage with no files though I have 52 passing tests.

I'm pretty sure its my preprocessors. It's not using a standard glob pattern (or at least that's not working for me). I need to include some files and exclude others.

Any new news on this?

INFO [karma]: Karma v0.12.28 server started at http://localhost:9876/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.7 (Mac OS X)]: Connected on socket ovcuUFjTOjYXDhS4x036 with id 33832217
PhantomJS 1.9.7 (Mac OS X): Executed 52 of 52 SUCCESS (0.088 secs / 0.026 secs)
----------|-----------|-----------|-----------|-----------|
File      |   % Stmts |% Branches |   % Funcs |   % Lines |
----------|-----------|-----------|-----------|-----------|
----------|-----------|-----------|-----------|-----------|
All files |       100 |       100 |       100 |       100 |
----------|-----------|-----------|-----------|-----------|


=============================== Coverage summary ===============================
Statements   : 100% ( 0/0 )
Branches     : 100% ( 0/0 )
Functions    : 100% ( 0/0 )
Lines        : 100% ( 0/0 )

@johnpapa
Copy link

johnpapa commented Jan 9, 2015

Turns out it was the minimatch and the file exclusions, which is what I thought (and feared). Glob patterns or even regex (gasp) would be more straightforward.

this ended up solving my problem, to exclude .spec.js files

./src/client/app/**/!(*.spec)+(.js)': ['coverage']

@dhrubach
Copy link

dhrubach commented Feb 4, 2015

+1 same issue here. Empty coverage report generated for both chrome 40.0.2214 and PhantomJS 1.9.8.

karma.conf.js

module.exports = function(config) { config.set({
  basePath: '',

  frameworks: ['requirejs', 'mocha', 'chai-sinon'],

  plugins: [
     'karma-mocha',
     'karma-requirejs',
     'karma-chrome-launcher',
     'karma-phantomjs-launcher',
     'karma-chai-sinon',
     'karma-mocha-reporter',
     'karma-clear-screen-reporter',
     'karma-coverage'
  ],

  // list of files / patterns to load in the browser
  files: [
      'test/test-odyssey-main.js',
       all source and spec files
  ],

  // list of files to exclude
  exclude: [
      'lib/**/*.json',
      'config.js',
      'main.js'
  ],

  // preprocess matching files before serving them to the browser
  preprocessors: {
      'app/**/*.js': ['coverage']
  },

  // test results reporter to use
  reporters: ['mocha', 'clear-screen', 'coverage'],

  // reporter options 
  mochaReporter: {
    output: 'full'
  },    

  coverageReporter: {
      type: 'html',
      dir: 'coverage/'
  },

  // web server port
  port: 9876,

  // enable / disable colors in the output (reporters and logs)
  colors: true,

  // level of logging
  logLevel: config.LOG_DEBUG,

  // enable / disable watching file and executing tests whenever any file changes
  autoWatch: true,

  // start these browsers
  browsers: ['PhantomJS', 'Chrome'],

  singleRun: false

});
};

node v0.10.35
npm v1.4.28
karma v0.12.31
karma-coverage 0.2.7

In debug.html, I do see that the source code under test is instrumented. However the generated report is blank with 'No data to display'. I have tried all possible suggestions so far, still no luck.

Is there a way i can debug reporter ?

@dhrubach
Copy link

dhrubach commented Feb 5, 2015

The issue was resolved after altering the order of loading files as explained at http://stackoverflow.com/questions/26850684/karma-coverage-requirejs-misleading-coverage-reports. Keeping the above configuration as is, I changed test-main.js to the following -

var allTestFiles = [];
var allSourceFiles = [];
var testRegexp = /(Spec.mocha)\.js$/im;
var srcRegexp = /app\/[a-zA-Z]+\/[a-zA-Z]+.js$/im;

var normalizePathToSpecFiles = function (path) {
    return path.replace(/^\/base\//, '../').replace(/\.js$/, '');
};

var normalizePathToSourceFiles = function (path) {
    return path.replace(/^\/base\/app\//, '').replace(/\.js$/, '');
};

var loadSourceModulesAndStartTest = function() {
    require(allSourceFiles, function () {
        require(allTestFiles, function () {
            window.__karma__.start();
        });
    });
};

Object.keys(window.__karma__.files).forEach(function (file) {
    if (testRegexp.test(file)) {
        allTestFiles.push(normalizePathToSpecFiles(file));
    } else if (srcRegexp.test(file)) {
        allSourceFiles.push(normalizePathToSourceFiles(file));
    }
});

require.config({

    baseUrl: '/base/lib',

    paths: {
       all file paths
    },

    shim: {
        angular: {
            exports: 'angular'
        },
        angularui: ['angular'],
        "bootstrap.min": ['jquery']
    },

    deps: ['angular', 'jquery', 'bootstrap.min'],

    callback: loadSourceModulesAndStartTest
});

@shystruk
Copy link

Hello everyone!
The same problem (

Did example on top helps for anybody ?

@mhelvens
Copy link

mhelvens commented May 4, 2015

I'm not sure if I'm experiencing exactly the same thing. Using karma-coverage ~0.3, my lcov.info ends up empty, though the 'text-summary' reporter works properly. When I downgrade to karma-coverage ~0.2, everything works properly again. I thought it might be a regression of karma-runner/karma#892?

@jodytate
Copy link

i can confirm @mhelvens report: running karma-coverage ~0.3 produces the 100% ( 0/0 ) reports, but downgrading to ~0.2 returns a coverage report as expected.

@dignifiedquire
Copy link
Member

Does anyone have a repo that reproduces this issue consistently?

@anshbansal
Copy link

My repo has this issue
https://github.com/anshbansal/linksharing2

Run this using the command
karma start grails-app/conf/karma.conf.js --no-auto-watch --single-run --browsers PhantomJS

@dignifiedquire

@anshbansal
Copy link

bump

@dignifiedquire
Copy link
Member

thanks @anshbansal I will try to take a look as soon as I can

@andy-dorman
Copy link

I'm not totally sure how related this is but after running into the same issues as others on this thread I looked back into a project I worked on that had this working.

The vital config for me was to require browserify-istanbul in my karma.config.js:

var istanbul = require("browserify-istanbul");

and set this config:

browserify: {
  transform: [
    [
      istanbul({
      ignore: ["node_modules/**", "**/*.spec.js"],
      includeUntested: false,
      defaultIgnore: true
      }),
      { global: true }
    ]
  ]
}

Not totally sure what this points to other than a possible issue with karma-browserify perhaps, but maybe it can help someone...

@qiu8310
Copy link

qiu8310 commented Jun 22, 2015

+1 some issue in my repo

@jperry
Copy link

jperry commented Jul 10, 2015

It's been 18 days an no update on this issue. Any resolution to this as it seems a lot of people including myself get zero results for code coverage.

@dignifiedquire
Copy link
Member

@anshbansal the repro, was not a real repro I'm afraid, the issue was that the coverage preprocessor was not properly matching any files: anshbansal/linksharing2#1

@jperry I'm sorry, that it's not working for you, but I'm working alone on all of karma, mostly at nights, and the coverage reporter is not something I use at all, so while I do understand that you are frustrated about it not working, please be a bit more constructive and maybe try figuring out yourself where the issue lies.

@dignifiedquire
Copy link
Member

@qiu8310 posted in your repo, not seeing an issue there

@jperry
Copy link

jperry commented Jul 10, 2015

@dignifiedquire -sorry about that. I have been looking at it all morning and haven't found how to fix it. Here is my karma.conf.js

// Karma configuration
// Generated on Thu Jul 09 2015 16:02:40 GMT-0400 (EDT)

module.exports = function(config) {
  config.set({

    // base path that will be used to resolve all patterns (eg. files, exclude)
    basePath: '',


    // frameworks to use
    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
    frameworks: ['jasmine'],


    // list of files / patterns to load in the browser
    files: [
      'spec/**/*.spec.js'
    ],


    // list of files to exclude
    exclude: [
    ],


    // preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
      // source files, that you wanna generate coverage for
      // do not include tests or libraries
      // (these files will be instrumented by Istanbul)
      './routes/**/*.js': ['coverage'],
      './app.js': ['coverage']
    },


    // test results reporter to use
    // possible values: 'dots', 'progress'
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
    reporters: ['progress', 'coverage'],

    // optionally, configure the reporter
    coverageReporter: {
      dir: 'build/reports/coverage',
      reporters: [
        // reporters not supporting the `file` property
        { type: 'html', subdir: 'report-html' },
        { type: 'lcov', subdir: 'report-lcov' }
      ]
    },

    // web server port
    port: 9876,


    // enable / disable colors in the output (reporters and logs)
    colors: true,


    // level of logging
    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
    logLevel: config.LOG_INFO,


    // enable / disable watching file and executing tests whenever any file changes
    autoWatch: true,


    // start these browsers
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
    browsers: ['PhantomJS'],


    // Continuous Integration mode
    // if true, Karma captures browsers, runs the tests and exits
    singleRun: false
  })
}

My devDependencies are like so:

  "devDependencies": {
    "gulp": "^3.9.0",
    "karma": "^0.12.37",
    "karma-coverage": "^0.4.2",
    "karma-jasmine": "^0.2.2",
    "karma-phantomjs-launcher": "^0.2.0",
    "phantomjs": "^1.9.17"
  }

My project is pretty small

node_modules/
routes/
spec/
app.js
karma.conf.js
package.json

Maybe I'm missing something obvious in my file patterns.

@dignifiedquire
Copy link
Member

I think the issues is that you are missing the source files, in the files array, try something like this:

files: [
  'app.js',
  'routes/**/*.js',
  'spec/**/*.spec.js'
],

@jperry
Copy link

jperry commented Jul 10, 2015

@dignifiedquire - I did try that before and I got this:

PhantomJS 1.9.8 (Mac OS X 0.0.0) ERROR
  ReferenceError: Can't find variable: require
  at /Users/jayperry/workspace/myapp/app.js:9


[13:21:36] 'test' errored after 1.65 s
[13:21:36] Error: 1
    at formatError (/Users/jayperry/.nvm/v0.10.33/lib/node_modules/gulp/bin/gulp.js:169:10)
    at Gulp.<anonymous> (/Users/jayperry/.nvm/v0.10.33/lib/node_modules/gulp/bin/gulp.js:195:15)

@dignifiedquire
Copy link
Member

Hmm, strange, any chance you could give me temporary access to the code?

@jperry
Copy link

jperry commented Jul 10, 2015

@dignifiedquire - sorry I can't. I could try stripping a bunch out and leave some boilerplate code in there.

@jperry
Copy link

jperry commented Jul 13, 2015

@dignifiedquire - I created a simple repository to show one that doesn't generate results.

@dignifiedquire
Copy link
Member

@jperry thanks, I think I know what the issue is. So the setup you have is an express app, that serves up some routes, and then you want to test those routes through karma. But this will not work with karma-coverage, as it is only able to handle and instrument the browser side part, as karma itself only runs in the browser. From the looks of the repo you should try something like using istanbul on its own, together with a library like https://github.com/visionmedia/supertest to test the routes and get test coverage.

@jperry
Copy link

jperry commented Jul 13, 2015

@dignifiedquire - thank you. We actually did as you suggested and used jasmine and istanbul directly. We are now getting code coverage reports. Thanks for the tip.

@dignifiedquire
Copy link
Member

@jperry glad to hear.

Closing, as this issue has been resolved, and the remaining issues seem to be configuration problems.

@urbaitel
Copy link

I found an issue with order of reporters. Try this and it will work!

coverageReporter: {
      dir: 'reports/coverage/',
      reporters: [
        { type: 'lcov', subdir: '.' },
        { type: 'text-summary' },
        { type: 'text' },
        { type: 'cobertura', subdir: '.', file: 'coverage.xml' }
      ],
      instrumenters: {isparta: require('isparta')},
      instrumenter: {
        'src/**/!(spec)*.js': 'isparta'
      }
    },

@BrainSlugs83
Copy link

I have this issue with latest -- I'm only using one reporter -- it doesn't seem to be a configuration problem -- I can resolve the issue with the hack to test-main.js that was posted by @dhrubach. -- Seems like the issue is real.

@Healforgreen
Copy link

Is there a problem with karma-coverage itself, or with using it in conjunction with other npm modules? Wasn't @dhrubach 's fix for compatibility with RequireJS?

@j-funk
Copy link

j-funk commented Mar 2, 2016

@andy-dorman thank you, was using Browserify (with Grunt & Karma) - your note got me up and running!

@joeSaad
Copy link

joeSaad commented Aug 30, 2016

I've been having the same issue. tried all solutions in here. I'm using webpack, karma, jasmine and been trying to generate coverage report to no avail. It's been coming out empty.

@surfjedi
Copy link

+1

@dannycallaghan
Copy link

+1

Same for me. Using webpack, karma, jasmine. If I choose to show the coverage output in the console, it works fine. If I choose to output as html, the html is generated, but it shows 100% (0/0) for everything, and doesn't display any data in the table below.

@stsvilik
Copy link

stsvilik commented Oct 20, 2016

I've had similar issue with browserify + babel + karma. Take a look here.

Key to my setup was to add ["istanbul"] into babel plugins.

@surfjedi
Copy link

surfjedi commented Nov 1, 2016

that worked! thanks @stsvilik thanks!

@CATIGERN
Copy link

CATIGERN commented Nov 8, 2016

I was facing the same issue. My Debug Log showed that files were being processed, however a coverage report was not being generated.
I solved this by setting the includeAllSources flag to true in my coverageReporter. Hope that helps!

coverageReporter: { dir: 'report/', includeAllSources: true },

@ghost
Copy link

ghost commented Jun 12, 2017

For some reason all these tutorial are missing the part about the entirely separate webpack plugin: istanbul-instrumenter-loader. So I am dropping it here for consistency. Setting up webpack with istanbul-instrumenter-loader set me on the right track.

@yancwa
Copy link

yancwa commented Oct 30, 2017

@CATIGERN , thanks very much, it helps a lot, finally it works,hahahah

@maksnester
Copy link

Hello there from 2018.

Sorry for archeology, but I have just migrated from phantomjs to puppeteer and faced with that issue. I work with webstorm and usualy it happens when I run single test suite. WS then show me this message as below and doesn't show coverage info to me. Absolutely random thing. Sometimes I get coverage, sometimes - not.

Cannot find karma test coverage report - lcov.info
Cannot find karma test coverage report - lcov.info

    "grunt-karma": "^2.0.0",
    "jasmine-core": "^2.8.0",
    "karma": "^1.7.1",
    "karma-chrome-launcher": "^2.2.0",
    "karma-cli": "^1.0.1",
    "karma-coverage": "^1.1.1",
    "karma-jasmine": "^1.1.1",
    "puppeteer": "^0.13.0"

@ThomasR
Copy link

ThomasR commented Feb 28, 2018

I ran into this issue when using rollup + babel + karma.

I fixed it by using "istanbul" as a babel plugin, as suggested above.

Then, use babel as a karma plugin, and do not include rollup-plugin-istanbul.

config.set({
  preprocessors: {
    'test/**/*.js': ['rollup']
  },
  plugins: [
    …
    babel({
      plugins: [
        [
          'transform-react-jsx',
          {
            pragma: 'createElement'
          }
        ],
        'istanbul'
      ]
    })
    …]
  ]
  …
}

@djlxiaoshi
Copy link

djlxiaoshi commented May 24, 2018

if you use webpack or other utils to transform your sourcecode you should use istanbul before

@abizebel
Copy link

abizebel commented Jun 20, 2018

hi friend this problem already solved
in the karma config just change preprocessor to

preprocessors: {
'**/*.js': 'coverage'
},

100% will solve your problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests