Pregunta

This is how my project is set up:

project/
  assets/
    js/
      app.js
      services.js
      directives.js
      controllers/
        FooCtrl.js
        BarCtrl.js
    css/
    images/
  test/
    unit/
      controllers/
        controllerSpec.js

I am struggling to add all the files under js/ to karma-coverage's preProcessor directive.

Doing this

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

only generates coverage report for files directly under assets/js/ but not for files under assets/js/controllers/.

Specifying a single controller:

preprocessors: {
   '**/assets/js/controllers/FooCtrl.js': ['coverage'],
},

just says 'No data to display'.

Finally, just doing a wildcard:

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

displays data for all files directly under assets/js/, test/unit/controllers/ test/lib/ etc. but it still refuses to show any coverage data for assets/js/controllers/.

¿Fue útil?

Solución

I swear there is something magical about StackOverflow. I spent an hour getting it to work, gave up, posted this question, and 2min later figured it out.

I made the mistake of moving the files from the files array to the preprocessors directive. To get code coverage on a certain file, it needs to be in both places, files array and the preprocessors.

My final configuration that works looks like this:

files : [
  //3rd Party Code
  'bower_components/angular/angular.js',
  'bower_components/angular-route/angular-route.js',
  'bower_components/angularjs-scope.safeapply/src/Scope.SafeApply.js',

  //App-specific Code
  'assets/js/app.js',
  'assets/js/services.js',
  'assets/js/directives.js',
  'assets/js/resources.js',
  'assets/js/controllers/*.js',

  //Test-Specific Code
  'node_modules/chai/chai.js',
  'test/lib/chai-should.js',
  'test/lib/chai-expect.js'
],

preprocessors: {
  '**/assets/js/*.js': ['coverage'],
  '**/assets/js/controllers/*.js': ['coverage']
},
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top