Karma coverage always shows 100%

My karma.conf.js files look like this:

// Karma configuration // Generated on Tue Jun 11 2013 14:14:12 GMT+0100 (GMT Daylight Time) // base path, that will be used to resolve files and exclude basePath = ''; // list of files / patterns to load in the browser files = [ JASMINE, JASMINE_ADAPTER, '../Scripts/angular/angular.js', '../Scripts/angular/restangular/underscore-min.js', '../Scripts/angular/restangular/restangular-min.js', '../Scripts/angular/angular-*.js', '../Scripts/angular/angular-test/angular-*.js', '../Scripts/angular/angular-ui/*.js', '../Scripts/angular/angular-strap/*.js', '../Scripts/angular/angular-http-auth/*.js', '../uifw/scripts/ui-framework-angular.js', '../app/app.js', '../app/**/*.js', 'unit/**/*.js' ]; // list of files to exclude exclude = [ '../Scripts/angular/angular-test/angular-scenario.js' ]; preprocessors = { '**/../app/**/*.js': 'coverage' }; coverageReporter = { type: 'html', dir: 'coverage/' }; // test results reporter to use // possible values: 'dots', 'progress', 'junit' reporters = ['progress', 'coverage']; // web server port port = 9876; // cli runner port runnerPort = 9100; // enable / disable colors in the output (reporters and logs) colors = true; // level of logging // possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG logLevel = LOG_DEBUG; // enable / disable watching file and executing tests whenever any file changes autoWatch = true; // Start these browsers, currently available: // - Chrome // - ChromeCanary // - Firefox // - Opera // - Safari (only Mac) // - PhantomJS // - IE (only Windows) browsers = ['Chrome']; // If browser does not capture in given timeout [ms], kill it captureTimeout = 60000; // Continuous Integration mode // if true, it capture browsers, run tests and exit singleRun = false; 

My folder structure is as follows:

 Root |__ App |__ Scripts |__ Tests |__ .... other folders 

Karma.conf.js is located inside the test folder. Karma start karma.conf.j launched from the tests folder.

My tests run and the coverage folder is created, but coverage always shows 100%.

Coverage

What am I doing wrong?

EDIT:

This was actually a simple answer. preprocessors = { '**/../app/**/*.js': 'coverage' }; no longer need to have a prefix **

See details

+4
source share
3 answers

You need to set ANGULAR_SCENARIO_ADAPTER . Karma does not use JASMINE_ADAPTER .

0
source

It seems to me that your problem is that you cannot find the files for which you want to create coverage. Your report says that lines 0/0 are running, operators are 0/0, etc.

I had a similar problem that I caused using lowercase letters instead of uppercase, and it looks like you might have the same problem as you have a folder named "Application", but you link to it with "application" in configuration. See if you can make it work by writing **/../App/**/*.js': 'coverage'

Also I'm not sure, but I think you should write ../App/**/*.js': 'coverage' instead of **/../App/**/*.js': 'coverage'

0
source

Configuring webpack with istanbul-tooler-loader got me on the right track. { test: /\.ts/, include: helpers.root('src', 'app'), loader: 'istanbul-instrumenter-loader', enforce: 'post' }

0
source

Source: https://habr.com/ru/post/1496528/


All Articles