Skip to content

Preprocessors in unit-coverage break when present in karma.conf too #21

@pulkitsinghal

Description

@pulkitsinghal

My karma-unit.conf.js file which started-off this seed, now looks like:

    files: [
      ...
      'app/views/*.html'
    ],
    preprocessors: {
      'app/views/*.html': ['ng-html2js']
    },
    ngHtml2JsPreprocessor: {
      moduleName: 'views',
      stripPrefix: 'app/'
    }

I was running grunt:karma:unitCoverage and I kept getting errors like:

Chrome 32.0.1700 (Mac OS X 10.9.2) ERROR
    Uncaught SyntaxError: Unexpected token <
    at /Users/myUsername/dev/nyApp/app/views/home.html:1

After much trial and error I figured out the way to fix this was to embellish the Gruntfile.js with the preprocessor that had been sitting in karma-unit.conf.js:

    karma: {
      unitCoverage: {
        configFile: './test/karma-unit.conf.js',
        preprocessors: {
          'app/scripts/*.js': ['coverage'], 
          'app/views/*.html': ['ng-html2js'] // had to be repeated here
        }

Is this because the preprocessor block is getting overridden?

Another suggestion is to alter the seed such that subdirectories would be covered too:

        preprocessors: {
          //'app/scripts/*.js': ['coverage'], // original
          'app/scripts/**/*.js': ['coverage'], // may be a nicer default
          'app/views/*.html': ['ng-html2js']
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions