Skip to content

fix(Server): cascade stats options - #1665

Merged
alexander-akait merged 7 commits into
webpack:masterfrom
yoannmoinet:master
Mar 21, 2019
Merged

fix(Server): cascade stats options#1665
alexander-akait merged 7 commits into
webpack:masterfrom
yoannmoinet:master

Conversation

@yoannmoinet

Copy link
Copy Markdown
Contributor
  • This is a bugfix
  • This is a feature
  • This is a code refactor
  • This is a test update
  • This is a docs update
  • This is a metadata update

For Bugs and Features; did you add new tests?

Will work on it if really needed.

Motivation / Use-Case

We get flooded by warnings in the console.

Additional Info

Fixes #1557

@jsf-clabot

jsf-clabot commented Feb 14, 2019

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@alexander-akait alexander-akait left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Great work, can you add tests?

@alexander-akait

Copy link
Copy Markdown
Member

Also please accept CLA

@yoannmoinet

Copy link
Copy Markdown
Contributor Author

Actually this won't work if we use a string for options.stats like errors-only.
Will update and add tests.

@codecov

codecov Bot commented Feb 14, 2019

Copy link
Copy Markdown

Codecov Report

Merging #1665 into master will increase coverage by 0.05%.
The diff coverage is 83.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1665      +/-   ##
==========================================
+ Coverage   86.08%   86.13%   +0.05%     
==========================================
  Files           8        8              
  Lines         539      541       +2     
  Branches      162      162              
==========================================
+ Hits          464      466       +2     
  Misses         62       62              
  Partials       13       13
Impacted Files Coverage Δ
lib/utils/createConfig.js 95.5% <100%> (ø) ⬆️
lib/Server.js 82.29% <80%> (+0.09%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7ea9ab9...049ca87. Read the comment docs.

@yoannmoinet

Copy link
Copy Markdown
Contributor Author

@evilebottnawi I've refactored the code to also accepts strings.
I tried to write tests, but I'm not sure where to begin.

I tried creating a new test/Server.test.js but I can't make any test pass, I think I'm going in the wrong direction.
Would you help please?

@yoannmoinet

Copy link
Copy Markdown
Contributor Author

Can someone help with the tests (cc @evilebottnawi) ?

Here's what I tried with Server.test.js but I've been unsuccessful.

'use strict';

const webpack = require('webpack');
const Server = require('../lib/Server');
const config = require('./fixtures/simple-config/webpack.config');

const allStats = [
  {},
  // eslint-disable-next-line
  undefined,
  'errors-only',
  {
    assetsSort: "size"
  }
];

describe('Server', () => {
  allStats.forEach((s) => {
    it('should cascade stats options', (done) => {
      const compiler = webpack(Object.assign({}, config, s && { stats: s }));
      const server = new Server(compiler, {});
      const next = () => {
        const localStats = server.getStats(server._stats);

        if(!s || !Object.keys(s).length) {
          expect(localStats).toBe(server.DEFAULT_STATS);
        } else {
          expect(localStats).not.toBe(server.DEFAULT_STATS);
        }

        server.close(() => {
          done();
        });
      };
      server.listen(8080, 'localhost', (err) => {
        if (err) return next(err);
        next();
      });
    });
  });
});

@alexander-akait alexander-akait left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@yoannmoinet

Copy link
Copy Markdown
Contributor Author

@evilebottnawi from what I understand, what you pointed to is if we want to use webpack's stats config if none is given to devServer's config, as a fallback.
I've added a commit that does just that, but on its own, it won't fix the bug, we still need the change in Server.js for it to cascade into the browser's console.

@yoannmoinet
yoannmoinet requested a review from hiroppy as a code owner February 28, 2019 14:06
Comment thread lib/Server.js Outdated
warnings: true,
errors: true,
errorDetails: false,
};

@alexander-akait alexander-akait Mar 4, 2019

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's avoid this.DEFAULT_STATS (because it should be as static private property)

@yoannmoinet yoannmoinet Mar 6, 2019

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I needed it for the tests I'm trying to write for Server.js.
Should I add this as a public static of the Server class?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you provide link where you need it for test? You already have getStats method

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@alexander-akait alexander-akait left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Loooks good, need add tests for warningsFilter

@hiroppy

hiroppy commented Mar 5, 2019

Copy link
Copy Markdown
Contributor

The snapshot test is currently failing.

@yoannmoinet

Copy link
Copy Markdown
Contributor Author

Loooks good, need add tests for warningsFilter

@evilebottnawi I'm not sure what you're asking for.

The snapshot test is currently failing.

@hiroppy indeed, I cannot reproduce locally though, so I don't know what to look for.

@alexander-akait

Copy link
Copy Markdown
Member

@yoannmoinet we need add tests for stats https://webpack.js.org/configuration/stats/ (warningsFilter option) to ensure we fix problem (what is written in issue)

@yoannmoinet

Copy link
Copy Markdown
Contributor Author

@evilebottnawi oh yes, I'm working on this right now 😉
I wasn't sure we were talking about the same thing 👍

@yoannmoinet

Copy link
Copy Markdown
Contributor Author

@evilebottnawi here you go, I've added test for the Server.

@yoannmoinet

Copy link
Copy Markdown
Contributor Author

I'm not sure I understand Travis' errors.

@yoannmoinet

Copy link
Copy Markdown
Contributor Author

can you help with the failing task in Travis @evilebottnawi please?

@alexander-akait

alexander-akait commented Mar 12, 2019

Copy link
Copy Markdown
Member

@yoannmoinet try to do rebase (master)

@yoannmoinet

Copy link
Copy Markdown
Contributor Author

I'm not sure what kind of test I'm supposed to add following the codecov/patch task failing.
I felt like I added all the tests needed.
cc @evilebottnawi

@alexander-akait alexander-akait left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good job, one note

Comment thread lib/Server.js

getStats(statsObj) {
return statsObj.toJson(this.stats);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's move

this.stats =
      options.stats && Object.keys(options.stats).length
        ? options.stats
        : Server.DEFAULT_STATS;

logic here, we don't need new property like stats

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh, good point, will update.

@yoannmoinet yoannmoinet Mar 18, 2019

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I still need to keep the property this.stats to have access to options.stats.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not sure it would be useful to move the logic since I still need to keep that this.stats so I can use options.stats in getStats().
What do you think @evilebottnawi ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yep, you are right, we should rewrite this in next major release

@alexander-akait

Copy link
Copy Markdown
Member

/cc @hiroppy

@hiroppy hiroppy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

thanks!

@alexander-akait
alexander-akait merged commit efaa740 into webpack:master Mar 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No respect, no respect at all! (for stats.warningsFilter 😉)

5 participants