Re: Code coverage report empty

3,815 views
Skip to first unread message

Michael Bielski

unread,
Mar 18, 2013, 12:38:57 PM3/18/13
to testa...@googlegroups.com
Put **/ in front of all of your files that you want included in the coverage like this:

preprocessors = {
    '**/web-app/js/app/SapphireConfig.js' : 'coverage',
    '**/web-app/js/app/SapphireApp.js' : 'coverage',
    '**/web-app/js/app/**/*.js' : 'coverage'
};

Vojta Jína

unread,
Mar 20, 2013, 5:44:42 PM3/20/13
to karma...@googlegroups.com
-testacular
+karma-users

Thanks Michael, this should be fixed in the next release.

V.


--
You received this message because you are subscribed to the Google Groups "testacular" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testacular+...@googlegroups.com.
To post to this group, send email to testa...@googlegroups.com.
Visit this group at http://groups.google.com/group/testacular?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Michael Bielski

unread,
Mar 20, 2013, 6:05:42 PM3/20/13
to karma...@googlegroups.com
Good to hear. Looking forward to it.

Vojta Jína

unread,
Mar 29, 2013, 5:27:15 PM3/29/13
to karma...@googlegroups.com
Can you go to http://localhost:9876/debug.html and check the actual content of js source files ? Are they instrumented ?

V.


On Thu, Mar 21, 2013 at 7:32 PM, <m...@carlosrodriguez.us> wrote:
I'm having the same issue. I get a blank coverage report with 100% and no files. My config looks like this:


// base path, that will be used to resolve files and exclude
basePath = '';

// list of files / patterns to load in the browser
files = [
  'source/modules/**/*.js',
];

// set pre-processor files needed
preprocessors = {
  '**/source/modules/**/*.js': 'coverage'
};


// test results reporter to use
// possible values: 'dots', 'progress', 'junit'
reporters = ['coverage'];


On Wednesday, March 20, 2013 6:05:42 PM UTC-4, Michael Bielski wrote:
Good to hear. Looking forward to it.

--
You received this message because you are subscribed to the Google Groups "karma-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to karma-users...@googlegroups.com.
To post to this group, send email to karma...@googlegroups.com.
Visit this group at http://groups.google.com/group/karma-users?hl=en.

Michael Bielski

unread,
Mar 29, 2013, 6:05:14 PM3/29/13
to karma...@googlegroups.com, m...@carlosrodriguez.us
Without some other kind of reporter, how can you tell if your tests are even running? Also, with your basePath set as it is, I think Karma will expect your files to be at c:\source\modules\**\*.js. If they are not at the location, that may be your trouble.

Vojta Jína

unread,
Apr 2, 2013, 9:23:35 PM4/2/13
to karma...@googlegroups.com
every pattern (files, excludes, ...) if relative path, it's resolved to basePath
basePath, if relative is resolved to the directory where the config file is

So if you set basePath path to an absolute path, it's not gonna be prefixed.

V.


On Mon, Apr 1, 2013 at 6:33 AM, <m...@carlosrodriguez.us> wrote:
I have another config file that runs the test using junit and progress as reporters and the test run fine. The reason for this is that I have the coverage as part of a grunt documentation task I ran every now and then while the test run whenever any of the files being tested change.

I tried changing the basePath, giving it the absolute folder path but it is already adding it. For example, I get an error saying that: /Users/carlosrodriguez/project/Users/carlosrodrigues/projects/source/modules/**/*.js doesn't match any files. If I leave the baseBath blank, I don't get this warning.



On Friday, March 29, 2013 6:05:14 PM UTC-4, Michael Bielski wrote:
Without some other kind of reporter, how can you tell if your tests are even running? Also, with your basePath set as it is, I think Karma will expect your files to be at c:\source\modules\**\*.js. If they are not at the location, that may be your trouble.

--
You received this message because you are subscribed to the Google Groups "karma-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to karma-users...@googlegroups.com.
To post to this group, send email to karma...@googlegroups.com.
Visit this group at http://groups.google.com/group/karma-users?hl=en.

Carlos Rodriguez

unread,
Apr 3, 2013, 11:33:20 PM4/3/13
to karma...@googlegroups.com
I see. So looking at my config, it would seem that it should work:

// base path, that will be used to resolve files and exclude
basePath = '';

// list of files / patterns to load in the browser
files = [
'source/modules/**/*.js',
];

// set pre-processor files needed
preprocessors = {
'**/source/modules/**/*.js': 'coverage'
};


// test results reporter to use
// possible values: 'dots', 'progress', 'junit'
reporters = ['coverage'];

The config is on the same folder which is why basePath is blank and my files are in the source/modules folder.

When I tried with the absolute path I did get the error saying nothing matched my pattern. When I ran it like this, I don't get the error which leads me to believe that I'm missing something?

Vojta Jína

unread,
Apr 7, 2013, 4:19:06 PM4/7/13
to karma...@googlegroups.com
I don't think adding progress reporter would fix anything.

If you are on 0.8.1 or newer, remove the '**/' prefix from the preprocessor pattern, it's not required anymore and it might actually fix your issue.

V.


On Wed, Apr 3, 2013 at 8:46 PM, <m...@carlosrodriguez.us> wrote:
Of course. Coverage can't run on its own, it needs something to run the tests so it can generate the coverage report. 

I got it to work by simply adding progress reporter.

Thanks a lot


On Friday, March 29, 2013 6:05:14 PM UTC-4, Michael Bielski wrote:
Without some other kind of reporter, how can you tell if your tests are even running? Also, with your basePath set as it is, I think Karma will expect your files to be at c:\source\modules\**\*.js. If they are not at the location, that may be your trouble.

--
You received this message because you are subscribed to the Google Groups "karma-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to karma-users...@googlegroups.com.
To post to this group, send email to karma...@googlegroups.com.
Visit this group at http://groups.google.com/group/karma-users?hl=en.

Vojta Jína

unread,
Apr 11, 2013, 2:30:43 AM4/11/13
to karma...@googlegroups.com
Unless there's something really weird going on, this is not possible.

Reporter has no effect on running or not running tests (without reporter you don't see anything, but the tests are actually running in the browser).

Note, that you don't need the "**/" prefix in preprocessor patterns anymore.

V.


On Wed, Apr 10, 2013 at 9:55 AM, <m...@carlosrodriguez.us> wrote:
The progress reporter actually fix it. The issue was that I was trying to un coverage on its own with no other reporter so there were no tests running.

My config file went from:

// base path, that will be used to resolve files and exclude
basePath = '';

// list of files / patterns to load in the browser
files = [
  'source/modules/**/*.js',
];

// set pre-processor files needed
preprocessors = {
  '**/source/modules/**/*.js': 'coverage'
};


// test results reporter to use
// possible values: 'dots', 'progress', 'junit'
reporters = ['coverage'];

to


basePath = '';

// list of files / patterns to load in the browser
files = [
  JASMINE,
  JASMINE_ADAPTER,
  './source/ui/lib/jquery/jquery.min.js',
  './source/ui/lib/lodash/lodash.min.js',
  './source/ui/lib/handlebars/handlebars.min.js',
  './source/ui/lib/jyoutube/jyoutube.js',
  './source/ui/lib/jgfeed/jgfeed.js',
  //'./source/modules/partials/partials.shtml',
  './source/modules/**/*.js',
  './source/test/**/*.js'
];

// set pre-processor files needed
preprocessors = {
  '**/source/modules/**/*.js': 'coverage'
};


// test results reporter to use
// possible values: 'dots', 'progress', 'junit'
reporters = ['progress','coverage'];

Aside from adding the progress reporter I also added the files needed for testing. Note that I had tried this before when using just the coverage reporter and was getting the same empty results.

Tomás Corral Casas

unread,
Nov 4, 2013, 3:29:32 AM11/4/13
to karma...@googlegroups.com
I've the same issue, but only running tests in Jenkins, when I run the tests in Windows I get the complete report without any problem.

I'm using Karma 0.10.4 with karma-coverage 0.1.0

When I run the tests I see how each file that should be pre-processed is preceded by [pre-processor coverage]  (aaaaa,bbbbb.cccc are not the real folder names)

[preprocessor.coverage]:  [39mProcessing "/var/lib/jenkins/jobs/HarnessJS/workspace/source/aaaaa/bbbbb/cccc/public/js/internal/init.js" 

This is as my karma.conf.js looks: I use swig to replace variables.

module.exports = function(config)
{
    config.set({
        basePath: '',
        frameworks: ['jasmine'],
        files: [
            '{{ jstdadapter }}'
            {% for file in load %}
                , "{{ file }}"
            {% endfor %}
            {% for file in test %}
                , "{{ file }}"
            {% endfor %}
        ],
        exclude: [],
        preprocessors: {
            '{{ preprocessorPath }}': ['coverage']
        },
        coverageReporter: {
            type: 'cobertura',
            dir : '{{ coveragePath }}',
            file : '{{ coverageFile }}'
        },
        reporters: [ 'progress', 'junit', 'coverage' ],
        junitReporter: {
            outputFile: '{{ output }}'
        },
        port: '{{ browser_port }}',
        runnerPort: '{{ cli_port }}',
        colors: true,
        logLevel: '{{ log_level }}',
        autoWatch: false,
        browsers: ['PhantomJS'],
        captureTimeout: '{{ timeout }}',
        singleRun: true,
        reportSlowerThan: '{{ slow_test }}',
        plugins: [
            'karma-jasmine',
            'karma-chrome-launcher',
            'karma-firefox-launcher',
            'karma-junit-reporter',
            'karma-coverage',
            'karma-phantomjs-launcher'
        ]
    });
}

I get the xml report for tests output, because it runs all the tests but I get an empty xml for coverage report: (aaaa is not the real folder name)

<?xml version="1.0" ?>
<coverage lines-valid="0"  lines-covered="0"  line-rate="1"  branches-valid="0"  branches-covered="0"  branch-rate="1"  timestamp="1383519736664" complexity="0" version="0.1">
<sources>
        <source>/var/lib/jenkins/jobs/HarnessJS/workspace/source/libs/admin_tools/ci/aaaa</source>
</sources>
<packages>
</packages>
</coverage>

Anyone could help me?

Vojta Jína

unread,
Nov 4, 2013, 12:44:52 PM11/4/13
to karma...@googlegroups.com
Tomas, I think there's something wrong with the paths.

V.


Reply all
Reply to author
Forward
0 new messages