@@ -6,17 +6,6 @@ const Server = require('../lib/Server');
66const config = require ( './fixtures/simple-config/webpack.config' ) ;
77const helper = require ( './helper' ) ;
88
9- const allStats = [
10- { } ,
11- // eslint-disable-next-line no-undefined
12- undefined ,
13- false ,
14- 'errors-only' ,
15- {
16- assets : false ,
17- } ,
18- ] ;
19-
209describe ( 'Server' , ( ) => {
2110 // issue: https://github.com/webpack/webpack-dev-server/issues/1724
2211 describe ( 'express.static.mine.types' , ( ) => {
@@ -67,81 +56,79 @@ describe('Server', () => {
6756 } ) ;
6857 } ) ;
6958
70- it ( 'should cascade warningsFilter' , ( ) => {
71- const stats = { warningsFilter : 'test' } ;
72- return new Promise ( ( res ) => {
73- const compiler = webpack ( config ) ;
74- const server = new Server ( compiler , { stats } ) ;
59+ describe ( 'stats' , ( ) => {
60+ it ( `should works with difference stats values (contains 'hash', 'assets', 'warnings' and 'errors')` , ( ) => {
61+ const allStats = [
62+ { } ,
63+ // eslint-disable-next-line no-undefined
64+ undefined ,
65+ false ,
66+ 'errors-only' ,
67+ {
68+ assets : false ,
69+ } ,
70+ ] ;
71+
72+ return new Promise ( ( resolve , reject ) => {
73+ ( function iterate ( stats , i ) {
74+ if ( i === allStats . length ) {
75+ return resolve ( ) ;
76+ }
77+
78+ // Iterate to cover each case.
79+ Promise . resolve ( )
80+ . then (
81+ ( ) =>
82+ new Promise ( ( res ) => {
83+ const compiler = webpack ( config ) ;
84+ const server = new Server ( compiler , { stats } ) ;
85+
86+ compiler . hooks . done . tap ( 'webpack-dev-server' , ( s ) => {
87+ expect ( Object . keys ( server . getStats ( s ) ) ) . toMatchSnapshot ( ) ;
88+
89+ server . close ( ( ) => {
90+ res ( ) ;
91+ } ) ;
92+ } ) ;
93+
94+ compiler . run ( ( ) => { } ) ;
95+ server . listen ( 8080 , 'localhost' ) ;
96+ } )
97+ )
98+ . then ( ( ) => {
99+ i += 1 ;
100+ iterate ( allStats [ i ] , i ) ;
101+ } )
102+ . catch ( ( e ) => {
103+ reject ( e ) ;
104+ } ) ;
105+ } ) ( allStats [ 0 ] , 0 ) ;
106+ } ) ;
107+ } ) ;
75108
76- compiler . hooks . done . tap ( 'webpack-dev-server' , ( s ) => {
77- s . compilation . warnings = [ 'test' , 'another warning' ] ;
109+ it ( 'should respect warningsFilter' , ( ) => {
110+ return new Promise ( ( res ) => {
111+ const compiler = webpack ( config ) ;
112+ const server = new Server ( compiler , {
113+ stats : { warningsFilter : 'test' } ,
114+ } ) ;
78115
79- const output = server . getStats ( s ) ;
80- expect ( output . warnings . length ) . toBe ( 1 ) ;
81- expect ( output . warnings [ 0 ] ) . toBe ( 'another warning' ) ;
116+ compiler . hooks . done . tap ( 'webpack-dev-server' , ( s ) => {
117+ s . compilation . warnings = [ 'test' , 'another warning' ] ;
82118
83- server . close ( ( ) => {
84- res ( ) ;
85- } ) ;
86- } ) ;
119+ const output = server . getStats ( s ) ;
87120
88- compiler . run ( ( ) => { } ) ;
89- server . listen ( 8080 , 'localhost' ) ;
90- } ) ;
91- } ) ;
121+ expect ( output . warnings . length ) . toBe ( 1 ) ;
122+ expect ( output . warnings [ 0 ] ) . toBe ( 'another warning' ) ;
92123
93- it ( `should cascade stats options` , ( ) => {
94- return new Promise ( ( resolve , reject ) => {
95- ( function iterate ( stats , i ) {
96- if ( i === allStats . length ) {
97- return resolve ( ) ;
98- }
99-
100- const prom = new Promise ( ( res , rej ) => {
101- const compiler = webpack ( config ) ;
102- const server = new Server ( compiler , { stats } ) ;
103-
104- compiler . hooks . done . tap ( 'webpack-dev-server' , ( s ) => {
105- const finalStats = JSON . stringify ( server . getStats ( s ) ) ;
106- const defaultStats = JSON . stringify (
107- server . _stats . toJson ( Server . DEFAULT_STATS )
108- ) ;
109-
110- // If we're not over-riding stats configuration,
111- // we get the same result as the DEFAULT_STATS
112- if ( ! stats || ! Object . keys ( stats ) . length ) {
113- try {
114- expect ( finalStats ) . toBe ( defaultStats ) ;
115- } catch ( e ) {
116- rej ( e ) ;
117- }
118- } else {
119- try {
120- expect ( finalStats ) . not . toBe ( defaultStats ) ;
121- } catch ( e ) {
122- rej ( e ) ;
123- }
124- }
125-
126- server . close ( ( ) => {
127- res ( ) ;
128- } ) ;
124+ server . close ( ( ) => {
125+ res ( ) ;
129126 } ) ;
130-
131- compiler . run ( ( ) => { } ) ;
132- server . listen ( 8080 , 'localhost' ) ;
133127 } ) ;
134128
135- // Iterate to cover each case.
136- prom
137- . then ( ( ) => {
138- i += 1 ;
139- iterate ( allStats [ i ] , i ) ;
140- } )
141- . catch ( ( e ) => {
142- reject ( e ) ;
143- } ) ;
144- } ) ( allStats [ 0 ] , 0 ) ;
129+ compiler . run ( ( ) => { } ) ;
130+ server . listen ( 8080 , 'localhost' ) ;
131+ } ) ;
145132 } ) ;
146133 } ) ;
147134
0 commit comments