-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: respect stats option from webpack config (#1665)
- Loading branch information
1 parent
7ea9ab9
commit efaa740
Showing
6 changed files
with
209 additions
and
13 deletions.
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', | ||
}, | ||
}; |