Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(karma-webpack): unify webpack and karma color config #356

Merged
merged 2 commits into from
Nov 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/karma-webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function Plugin(
/* config.files */ files,
/* config.frameworks */ frameworks,
/* config.singleRun */ singleRun,
/* config.colors */ colors,
customFileHandlers,
emitter
) {
Expand Down Expand Up @@ -226,6 +227,11 @@ function Plugin(
compiler.hooks.invalid.tap(this.plugin, invalid.bind(this));

webpackMiddlewareOptions.publicPath = '/_karma_webpack_/';

// Set webpack's color config to value specified in Karma's config for consistency
webpackMiddlewareOptions.stats = webpackMiddlewareOptions.stats || {};
webpackMiddlewareOptions.stats.colors = colors;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this always override the default webpack colors config ? This would be a breaking change then... Could this eventually be made an option intead ? e.g

if (config.colors) {
  webpackDevMiddlewareOptions.stats.colors = colors
}

⚠️ Not sure if this works correctly, but to illustrate the idea :)

Copy link
Contributor Author

@spicalous spicalous Sep 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@michael-ciniawsky Thanks for the response :) What do you mean by a breaking change?

It should work in a similar way that webpack's watch config is being overridden by Karma's singleRun config https://github.com/webpack-contrib/karma-webpack/blob/master/src/karma-webpack.js#L56

If you specify colors: false on Karma, you probably don't want colors on webpack's output either

Copy link
Contributor

@michael-ciniawsky michael-ciniawsky Sep 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm honstely not too familiar with in this particular area, so I might misunderstand the changes made here... My current understanding is that webpackDevMiddlewareOptions.stats.colors = colors always 'overrides' the webpack defaults (?) What are the webpack defaults? No colors at all (then everthing should be fine as-is)? Could you maybe post a screenshot before/after to clearify?

Copy link
Contributor Author

@spicalous spicalous Sep 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Below are some images to illustrate the changes

I have a simple project setup you can play around with https://github.com/spicalous/color-example

First image: No configs (Karma and webpack output color)
default-no-color-opt

Second image: Karma color:false (Karma outputs no color, webpack outpus color)
karma-color-false

Third image: Karma color:false after changes (Karma and webpack both output no color)
karma-color-false-after

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

webpackMiddlewareOptions.stats could be string. This breaks configuration i.e.:

  //...
  stats: 'errors-only'

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in rc.5


const middleware = new WebpackDevMiddleware(
compiler,
webpackMiddlewareOptions
Expand Down
1 change: 1 addition & 0 deletions test/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('Plugin', () => {
[],
[],
true,
true,
[],
emitterMock
);
Expand Down