-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
05ca937
fix(Server): cascade stats options
yoannmoinet cea1eb8
fix(config): use webpack's stats if none is submitted via config
yoannmoinet 18231ba
fix(Server): use DEFAULT_STATS as static
yoannmoinet f3f590a
test(Server): add tests for the stats cascading
yoannmoinet 01ba5f4
test(config): update snapshots
yoannmoinet 819ed21
Merge branch 'master' into master
evilebottnawi 049ca87
Merge branch 'master' into master
evilebottnawi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
'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 no-undefined | ||
undefined, | ||
false, | ||
'errors-only', | ||
{ | ||
assets: false, | ||
}, | ||
]; | ||
|
||
describe('Server', () => { | ||
it(`should cascade stats options`, () => { | ||
return new Promise((resolve, reject) => { | ||
(function iterate(stats, i) { | ||
if (i === allStats.length) { | ||
return resolve(); | ||
} | ||
|
||
const prom = new Promise((res, rej) => { | ||
const compiler = webpack(config); | ||
const server = new Server(compiler, { stats }); | ||
|
||
compiler.hooks.done.tap('webpack-dev-server', (s) => { | ||
const finalStats = JSON.stringify(server.getStats(s)); | ||
const defaultStats = JSON.stringify( | ||
server._stats.toJson(Server.DEFAULT_STATS) | ||
); | ||
|
||
// If we're not over-riding stats configuration, | ||
// we get the same result as the DEFAULT_STATS | ||
if (!stats || !Object.keys(stats).length) { | ||
try { | ||
expect(finalStats).toBe(defaultStats); | ||
} catch (e) { | ||
rej(e); | ||
} | ||
} else { | ||
try { | ||
expect(finalStats).not.toBe(defaultStats); | ||
} catch (e) { | ||
rej(e); | ||
} | ||
} | ||
|
||
server.close(() => { | ||
res(); | ||
}); | ||
}); | ||
|
||
compiler.run(() => {}); | ||
server.listen(8080, 'localhost'); | ||
}); | ||
|
||
// Iterate to cover each case. | ||
prom | ||
.then(() => { | ||
i += 1; | ||
iterate(allStats[i], i); | ||
}) | ||
.catch((e) => { | ||
reject(e); | ||
}); | ||
})(allStats[0], 0); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
entry: './app.js', | ||
stats: { | ||
assetsSort: 'size', | ||
}, | ||
devServer: { | ||
host: '_foo', | ||
public: '_public', | ||
socket: '_socket', | ||
progress: '_progress', | ||
publicPath: '_publicPath', | ||
filename: '_filename', | ||
hot: '_hot', | ||
hotOnly: '_hotOnly', | ||
clientLogLevel: '_clientLogLevel', | ||
contentBase: '_contentBase', | ||
watchContentBase: '_watchContentBase', | ||
lazy: '_lazy', | ||
noInfo: '_noInfo', | ||
quiet: '_quiet', | ||
https: '_https', | ||
pfxPassphrase: '_pfxPassphrase', | ||
inline: '_inline', | ||
historyApiFallback: '_historyApiFallback', | ||
compress: '_compress', | ||
disableHostCheck: '_disableHostCheck', | ||
open: '_open', | ||
openPage: '_openPage', | ||
useLocalIp: '_useLocalIp', | ||
port: '_port', | ||
}, | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
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 tooptions.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 useoptions.stats
ingetStats()
.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