user1995781
user1995781

Reputation: 19463

Karma Invalid config file

In order to make karma config file easier to configure path, I am using variable to store certain part of the path.

var publicfolder = "public"
var mypath = "packages/vendor/package/";

files: [
  publicfolder+'/assets/libs/jquery/dist/jquery.js',
  publicfolder+'/assets/libs/angular/angular.js',
  publicfolder+'/assets/libs/**/*.js',
  publicfolder+'/app/**/*.js',
  mypath +'/public/app/**/*.test.js',
  mypath +'/public/app/**/*.html'
],

preprocessors: {
    mypath +'/public/app/**/*.html':['ng-html2js']
},

However, when I run the test, it come into the error saying

E:\www\project\karma.conf.js:83
    mypath +'/public/app/**/*.html':['ng-html2js']
           ^
ERROR [config]: Invalid config file!
  SyntaxError: Unexpected token +
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)

My question is WHY? Why I can't put variable there? Why is that it is fine to put it in the files array but not in the preprocessors?

Upvotes: 0

Views: 4011

Answers (1)

sheilak
sheilak

Reputation: 5873

preprocessors is an object and you can't put expressions in an object key using initializer notation. You can use expressions if you are setting the key using square bracket notation.

So in this case you could do something like this:

var mypath = "packages/vendor/package/";
var preprocessors = {};
preprocessors[mypath +'/public/app/**/*.html'] = ['ng-html2js'];

It's fine to use expressions in the files array because there you are just creating regular strings, not object keys.

Upvotes: 1

Related Questions