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

fix(Server): cascade stats options #1665

Merged
merged 7 commits into from Mar 21, 2019
Merged

Conversation

yoannmoinet
Copy link
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
Copy link

jsf-clabot commented Feb 14, 2019

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@alexander-akait alexander-akait left a comment

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
Member

Also please accept CLA

@yoannmoinet
Copy link
Contributor Author

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

@codecov
Copy link

codecov bot commented Feb 14, 2019

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
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
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();
      });
    });
  });
});

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

@yoannmoinet
Copy link
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.

lib/Server.js Outdated
warnings: true,
errors: true,
errorDetails: false,
};
Copy link
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)

Copy link
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
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
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

@alexander-akait alexander-akait left a comment

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
Copy link
Member

hiroppy commented Mar 5, 2019

The snapshot test is currently failing.

@yoannmoinet
Copy link
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
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
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
Contributor Author

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

@yoannmoinet
Copy link
Contributor Author

I'm not sure I understand Travis' errors.

@yoannmoinet
Copy link
Contributor Author

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

@alexander-akait
Copy link
Member

alexander-akait commented Mar 12, 2019

@yoannmoinet try to do rebase (master)

@yoannmoinet
Copy link
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

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

Good job, one note

@@ -668,6 +674,10 @@ class Server {
}, this);
}

getStats(statsObj) {
return statsObj.toJson(this.stats);
}
Copy link
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
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.

Copy link
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
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
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
Member

/cc @hiroppy

Copy link
Member

@hiroppy hiroppy left a comment

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