karma-runner / grunt-karma

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

Unable to set `client.captureConsole` from `karma.conf.js` #166

Closed kirschre closed 6 years ago

kirschre commented 9 years ago

I'm working on a project that defines its karma options in a karma.conf.js file. When client.captureConsole is defined in the karma config, it gets ignored when I run grunt karma. However, if the option is defined in the Gruntfile instead, it works. I know that client.captureConsole is valid in the config file because I can run karma directly with that config property set, and it works as expected.

It looks like grunt-karma is setting defaults for the client options (here) if they are not set in the Gruntfile options object. My suspicion is that these defaults eventually override the settings from karma.conf.js, causing the behavior I'm seeing.

Is there a reason why the client options are directly being set by grunt-karma? If these are really karma defaults, shouldn't karma take care of setting them?

kirschre commented 9 years ago

Looks like this is related to issues #165 and #128. Happy to contribute when I have some time if I can get some guidance on the issue.

dignifiedquire commented 9 years ago

Yes this is a bug, which is two fold, one part is in grunt-karma, which shouldn't overwrite anything or change the defaults unless it actually needs to, the other is that there seems to be a bug in passing the client options via the api atm, which is probably happening somewhere in lib/config.js.

I'm happy to help you if you want to try and fix this, just let me know if you have any questions.

amiramw commented 8 years ago

I have similar problem with client configs overridden by grunt. It works if I change locally config.js set method from:

  this.set = function (newConfig) {
    Object.keys(newConfig).forEach(function (key) {
      config[key] = newConfig[key]
    })
  }

to:

this.set = function (newConfig) {
    _.merge(config, newConfig);
  }

Is such fix any good?

Krinkle commented 6 years ago

Fixed by https://github.com/karma-runner/grunt-karma/pull/194.