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

Coverage Report Dumps .js.html files into same directory as covered files when karma conf file in separate directory #65

Closed
opnsrce opened this issue Mar 4, 2014 · 34 comments · May be fixed by saurabharch/TerraWatts#1, saurabharch/byodb#3, saurabharch/ImVue#1, saurabharch/EBB#1 or saurabharch/HireDot2#4

Comments

@opnsrce
Copy link

opnsrce commented Mar 4, 2014

I've noticed the following possible bug:

When the karma conf file is in a separate directory from the files being tested, the coverage report files don't get placed in the coverage directory. Instead, the files get placed in the same directory as the files being covered.

Here's my karma conf file for reference:

module.exports = function(config) {
    config.set({
        basePath: './',
        autoWatch: true,
        frameworks: ['jasmine'],
        files: [
            '../public_html/libs/jquery/*.js',
            '../public_html/libs/mylib/lib.js',
            '../public_html/libs/mylib/utility.js',
            '../public_html/libs/mylib/config/*.js',
            '../public_html/libs/mylib/enumerations.js',
            '../public_html/libs/mylib/apiComm.js',
            '../public_html/libs/mylib/baseObject.js',
            '../public_html/libs/mylib/book.js',
            '../public_html/libs/mylib/file.js',
            '../public_html/libs/mylib/library.js',
            '../public_html/libs/mylib/publishing.js',
            '../public_html/libs/mylib/topic.js',
            '../test/*Spec.js'
        ],
        reporters: ['progress', 'coverage'],
        preprocessors: {
            '../public_html/libs/mylib/*.js': ['coverage']
        },
        port: 9876,
        colors: true,
        browsers: ['Chrome'],
        captureTimeout: 60000,
        singleRun: false
    });
};
@Antonio-Laguna
Copy link

You have the ability to customise the way the coverage works by adding the coverageReporter object.

Have you tried something like this?

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

@opnsrce
Copy link
Author

opnsrce commented Mar 10, 2014

I did use the coverageReporter param and still ran into the same issue. However, I was able to find a workaround. In order to make the files appear in the correct directory, you need to set the basePath param to the directory where all the files being tested live. My config file now looks something like this:

module.exports = function(config) {
    config.set({
        basePath: '../public_html/libs/mylib/',
        autoWatch: true,
        frameworks: ['jasmine'],
        files: [
            '../jquery/*.js',
            'mylib.js',
            'utility.js',
            'config/*.js',
            'enumerations.js',
            'apiComm.js',
            'baseObject.js',
            'book.js',
            'file.js',
            'library.js',
            'publishing.js',
            'topic.js',
            'thirdPartyApi.js',
            '../../../test/sharedSpec.js',
            '../../../test/*Spec.js'
        ],
        reporters: ['progress', 'coverage'],
        preprocessors: {
            'mylib.js': ['coverage'],
            'utility.js': ['coverage'],
            'enumerations.js': ['coverage'],
            'apiComm.js': ['coverage'],
            'baseObject.js': ['coverage'],
            'book.js': ['coverage'],
            'file.js': ['coverage'],
            'library.js': ['coverage'],
            'publishing.js': ['coverage'],
            'topic.js': ['coverage'],
            'thirdPartyApi.js': ['coverage']
        },
        coverageReporter: {
          type : 'html',
          dir : '../../../coverage/'
        },
        port: 9876,
        colors: true,
        browsers: ['Chrome'],
        captureTimeout: 60000,
        singleRun: false
    });
};

@acostaf
Copy link

acostaf commented Mar 28, 2014

Thanks opnsrce for that work around but this it is a bug so I think it is better to be fixed

@dwmkerr
Copy link

dwmkerr commented Apr 19, 2014

@opnsrce are you running on windows? I'm having the same issue too, just checking to see if it's platform dependent

@dwmkerr
Copy link

dwmkerr commented Apr 19, 2014

Just to add a little bit to help with this issue - I was able to solve this issue by making sure that none of the files listed start with ../ - again a bit like @opnsrce by setting the basepath. It seems like this is related to the bug.

@finleysg
Copy link

I run on windows and saw the same behavior. I modified my karma config file so the base path was the root of my src, lib, and tests sibling directories, and that solved the problem.

  config.set({
    basePath: '../',
    frameworks: ['jasmine'],
    plugins: [
        'karma-jasmine',
        'karma-coverage',
        'karma-chrome-launcher',
        'karma-phantomjs-launcher'
    ],
    preprocessors: {
        'src/**/*.js': ['coverage']
    },
    files: [
        'lib/jquery/dist/jquery.js',
        'lib/angular/angular.js',
        'lib/angular-mocks/angular-mocks.js',
        'src/app.js',
        'src/templates.js',
        'src/**/*.js',
        'tests/*.js',
        'tests/**/*.js'
    ],
    exclude: [
        'tests/manual/*.*'
    ],
    reporters: ['dots', 'coverage'],
    coverageReporter: {
        reporters: [
            { type: 'lcov', dir: 'tests/coverage/' },
            { type: 'cobertura', dir: 'tests/coverage/' }
        ]
    },
    and so on...

@anthonyvialleton
Copy link

Solved exactly as finleysg : by setting a basePath value (!= '')..

@M0nter0
Copy link

M0nter0 commented Oct 7, 2014

I was having the same behaviour. The problem is not related strictly to basepath, but any path should start with '../' as suggested by @dwmkerr

@lukeapage
Copy link

confirmed also, same problem, ../ in basePath solved it. windows 7.

@dignifiedquire
Copy link
Member

This is not a bug, but rather how karmas basePath works, and how it consequently is used by this plugin.

@lukeapage
Copy link

@dignifiedquire are you sure? It looks like a bug or at the very least unexpected behaviour.. Setting a particular type of basepath on windows causes coverage to ignore a particular option.. Where is that documented? Or is it a bug in karma? If so do you have a link?

@dignifiedquire
Copy link
Member

Sorry, looks like it's not as simple as that..

@memark
Copy link

memark commented Jun 10, 2015

+1 for this problem. Really glad I found this issue describing work-arounds.

@Writtscher
Copy link

Same issue for me on windows. The coverage reports are not generated in the configured folder.

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

module.exports = function(config) {
    config.set({
        basePath: '../../../',
        frameworks: ['browserify', 'mocha', 'sinon-chai'],
        preprocessors: { 'src/main/web/js/**/*.js': ['browserify', 'coverage'] },
        browsers: ['Chrome'],
        reporters: ['progress', 'coverage'],

        autoWatch: true,

        browserify: {
            debug: true,
            transform: [
                istanbul({ ignore: ['**/node_modules/**', '**/test/**'] })
            ]
        },

        coverageReporter: {
            dir : 'build/reports/web/unit/'
        },

        files: [
            'node_modules/angular/angular.min.js',
            'node_modules/angular-mocks/angular-mocks.js',

            'src/main/web/js/main.js',

            'src/test/web/unit/**/*.js'
        ]
    });
};

But as soon as is remove the coverage from the preprocessor it works. All files will be generated in the specified folder. This means

preprocessors: { 'src/main/web/js/**/*.js': ['browserify'] },

@stevehipwell
Copy link

+1 Same issue here on windows using basePath: ''.

@Ajithsou
Copy link

Ajithsou commented Aug 9, 2015

I am facing the same problem, in my case Absolute path is used as base path. Following is my config file
module.exports = function(config) {
config.set({
basePath: 'c:/svn/trunk/myproject/',
frameworks: ['jasmine', 'requirejs'],
files: [
'test-main.js',
{pattern: 'js/.js', included: true},
{pattern: 'test/
.js', included: true}
],
exclude: [
],
preprocessors: {
'js/*.js': ['coverage']
},
reporters: ['progress','coverage'],
coverageReporter: {
type : 'html',
dir : 'coverage/'
},
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
plugins:[
'karma-jasmine',
'karma-coverage',
'karma-chrome-launcher',
'karma-requirejs'
],
singleRun: false
})
}

Karma modules and its configuration file are in a different folder structure, maintained common for different projects (c:/dev/tools/karma). Each project will have individual karma config.
Now the coverage report (html) for individual js source files are getting generated in source location itself instead of coverage folder, only the summary coverage reports are in coverage folder.

@mprentic-harris
Copy link

👍 we're seeing this issue as well on Windows 7. This wasn't happening a couple weeks ago with "karma-coverage": "0.4.2",, but it is happening now using "karma-coverage": "0.5.0",

We'll stick with 0.4.2 for now until this is resolved in an 0.5.x release.

Thank you.

@codeacula
Copy link

Confirm that 0.4.2 works as expected, but 0.5.x doesn't on Windows 10.

@thitemple
Copy link

Same problem here on Windows 8, with 0.5.0

@lebolo
Copy link

lebolo commented Aug 14, 2015

I also started having this problem with 0.5.0 (27e0b09). Was using 0.4.2 before.

@mbcooper
Copy link

+1 backed down from 0.5.x to 0.4.2

Problems go away!

stefcameron added a commit to stefcameron/yllr that referenced this issue Aug 19, 2015
- yllr.check() 'condition' parameter can now be a function
- add a few more unit tests
- updated a few devDependencies, but kept karma-coverage at ^0.4.2'
  because of [1]

[1] karma-runner/karma-coverage#65
@deleonio
Copy link

Diff 0.5.x and 0.4.2

@Ajithsou
Copy link

Uninstall 0.5.x and installed 0.4.2
It worked

@bricss
Copy link

bricss commented Aug 25, 2015

+1, does anybody started out planning to fix it?

@mramato
Copy link

mramato commented Aug 25, 2015

Looking at the diff it looks to me like the modifications to lib/preprocessor.js are the problem. It's no longer modifying filepaths to be relative to the output base path and instead is just using the original path of each JS file. However, I'm not sure what these modifications were intended to fix so I'm not sure if they are the source of the problem or exposing a problem somewhere else.

@Zenith-One
Copy link

I can verify that reverting to 0.4.2 fixes the issue.

@deleonio
Copy link

Thank you, that does we already know. The problem is that a newer version is not working properly. We need a better documentation or a fix.

@bricss
Copy link

bricss commented Aug 27, 2015

Definitely it's a bug, it should resolve paths as all modular systems do.

@Havunen
Copy link

Havunen commented Aug 28, 2015

Reverting to 0.4.2 fixes issue 👍

@dignifiedquire
Copy link
Member

Should be fixed in 0.5.1

@gp-slick-coder
Copy link

Still not working on 0.5.1 and 0.5.3

@dignifiedquire
Copy link
Member

@GBreeze please file a new issues with repro

@jannhama
Copy link

jannhama commented Mar 8, 2016

For me this was fixed after all to make small change in the istanbul html reporter (lib/report/html.js). My fork is here not sure if it is universal fix. Worked for me.

@summanerd
Copy link

I was able to fix this by updating the basepath to use its real path vs the symlink.

Ex:
basePath: __dirname changed to basePath: fs.realpathSync(__dirname)

the former returned something like 'K:' vs the real path 'C:\dev'. It seems that when the other files are pulled in its real path is used. So when istanbul attempts to resolve 'K:\FOLDER_FOR_COVERAGE' & 'C:\dev\FILE_BEING_COVERED' nothing overlaps so it uses 'C:\dev'.

the goal is to have the absolute path to the coverage as 'C:\dev\FOLDER_FOR_COVERAGE' vs 'K:\FOLDER_FOR_COVERAGE'.

Hope this help!

FYI I'm using Node 6.1.0 - Karma 1.1.2 - Karma Coverage 1.1.1 - Istanbul 0.4.4 on Windows 7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment