codymikol / karma-webpack

Karma webpack Middleware
MIT License
830 stars 222 forks source link

[4.0.0-rc4] Regression after removing lodash (when using multi-compiler mode) #390

Closed jakub-g closed 3 years ago

jakub-g commented 5 years ago

In #364 _.clone was replaced with Object.assign.

This change assumed that webpackOptions is always an object, but in fact, it can be an array (multi-compiler mode, see https://github.com/webpack/webpack/tree/master/examples/multi-compiler).

So after this change, an array [ objA, objB ] becomes an object { 0: objA, 1: objB } and then some subsequent logic gets changed, but also the subsequent webpack(...) call checks the passed config and throws an error:

WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration has an unknown property '1'. These properties are valid:
...

I propose to rollback this change then. But instead of using lodash we could use lodash.clone: https://www.npmjs.com/package/lodash.clone as it's the only lodash method used.

matthieu-foucault commented 5 years ago

Good catch! Feel free to make a pull request if you have time!

jakub-g commented 5 years ago

Yep I'm working on it :)

georgeholt commented 5 years ago

Unsure if this is related, however I'm getting the same error when using a multi-compiler config, but I'm on webpack-karma version 3.0.5. The error I get is:

WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.

  • configuration has an unknown property '9'.

My Karma configuration is as follows:

{
  frameworks: ['mocha'],
  reporters: ['mocha'],
  files: [
    { pattern: './tests/index.js' }
  ],
  preprocessors: {
    'tests/**/*.js': ['webpack', 'sourcemap']
  },
  webpack: webpackMerge(webpackConfig({ development: true }), {
    entry: null,
    output: null,
    devtool: 'inline-source-map',
    resolve: {}
  })
}

My webpack config is a little large (first time using it), but it builds fine.

On a side note, feel free to ignore this but I haven't found anything on the subject, but is there a way to disable security policies on browsers that Karma tests on? I need to run tests that use the Audio element, but of course the browser makers thought it "wise" to block playback until user interaction.

codymikol commented 3 years ago

Closing as this seems to have been fixed with https://github.com/ryanclark/karma-webpack/commit/63cfd78c4f3d850b94b3703bcf5b4571a7f0b513