fix(Server): cascade stats options - #1665
Conversation
alexander-akait
left a comment
There was a problem hiding this comment.
Great work, can you add tests?
|
Also please accept CLA |
|
Actually this won't work if we use a string for |
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
|
@evilebottnawi I've refactored the code to also accepts strings. I tried creating a new |
|
Can someone help with the tests (cc @evilebottnawi) ? Here's what I tried with '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
left a comment
There was a problem hiding this comment.
Invalid place for solution, see https://github.com/webpack/webpack-dev-server/blob/master/lib/utils/createConfig.js#L107 and https://github.com/webpack/webpack-dev-server/blob/master/lib/utils/createConfig.js#L118, we should get firstWpOpt.stats (if define)
|
@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. |
| warnings: true, | ||
| errors: true, | ||
| errorDetails: false, | ||
| }; |
There was a problem hiding this comment.
Let's avoid this.DEFAULT_STATS (because it should be as static private property)
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Can you provide link where you need it for test? You already have getStats method
There was a problem hiding this comment.
alexander-akait
left a comment
There was a problem hiding this comment.
Loooks good, need add tests for warningsFilter
|
The snapshot test is currently failing. |
@evilebottnawi I'm not sure what you're asking for.
@hiroppy indeed, I cannot reproduce locally though, so I don't know what to look for. |
|
@yoannmoinet we need add tests for |
|
@evilebottnawi oh yes, I'm working on this right now 😉 |
|
@evilebottnawi here you go, I've added test for the Server. |
|
I'm not sure I understand Travis' errors. |
|
can you help with the failing task in Travis @evilebottnawi please? |
|
@yoannmoinet try to do rebase (master) |
|
I'm not sure what kind of test I'm supposed to add following the |
|
|
||
| getStats(statsObj) { | ||
| return statsObj.toJson(this.stats); | ||
| } |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Oh, good point, will update.
There was a problem hiding this comment.
I still need to keep the property this.stats to have access to options.stats.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
Yep, you are right, we should rewrite this in next major release
|
/cc @hiroppy |
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