-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Conversation
There was a problem hiding this 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?
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();
});
});
});
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
lib/Server.js
Outdated
warnings: true, | ||
errors: true, | ||
errorDetails: false, | ||
}; |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this 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
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 |
There was a problem hiding this 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); | |||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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
/cc @hiroppy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
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