karma-runner / grunt-karma

Grunt plugin for Karma.
MIT License
468 stars 116 forks source link

Respect the Grunt way of defining files #126

Open NicBright opened 10 years ago

NicBright commented 10 years ago

Right now, grunt-karma needs a dedicated "files" property in the options config object, e.g.

{ "karma": {
    "options": {
      "files": ["put-files-here"]
}}}

It is not possible to use the Grunt way of defining files http://gruntjs.com/configuring-tasks#files. But it should, as grunt-karma is a Grunt plugin, after all.

beckyconning commented 10 years ago

Does this way of defining files cause this warning:

Warning: Object false has no method 'indexOf' Use --force to continue.

for anyone else when using the -v option?

beckyconning commented 10 years ago

This definitely causes the issue I mentioned above. This is a bug and should be raised as such.

To workaround place your files in an karma.conf.js file.

deckar01 commented 7 years ago

This is a blocker for me right now. I need all of my child configs to inherit the files definition that tells the server to serve my html fixtures, but currently I only have access to grunt style file definitions in the child sections, so I have to repeat the entry in each one.

An options key name something like gruntFiles would solve my use case.

Using files differently between the options and the child configs was definitely a stumbling block for picking up grunt-karma. It would be nice if the karma style file lists used the files key in the child configs, and a different name was used for this grunt specific functionality.

deckar01 commented 7 years ago

I created a helper that treats all the files properties as karma style files. It uses a separate key called gruntFiles for the grunt style files.

const gruntFiles = config.options.gruntFiles || [];
for(let key in config) {
  if(key === 'options') continue;
  const files = [{src: config[key].files || []}];
  const extraGruntFiles = config[key].gruntFiles || [];
  config[key].files = gruntFiles.concat(extraGruntFiles, files);
}

I think my config makes a little more sense now.

{
  options: {
    files: ['foo.js'],
    gruntFiles: [{src: ['fixtures/*.html'], served: true, included: false}]
  },
  unit1: {
    files: ['blah1.js', 'blah1.spec.js'],
  },
  unit2: {
    files: ['blah2.js'],
    gruntFiles: [{pattern: 'blah2.*.spec.js'}]
  }
}