File tree Expand file tree Collapse file tree 4 files changed +45
-3
lines changed Expand file tree Collapse file tree 4 files changed +45
-3
lines changed Original file line number Diff line number Diff line change @@ -241,6 +241,9 @@ var subscribeAllHandler;
241241function processMessage ( obj ) {
242242 switch ( obj . action ) {
243243 case 'building' :
244+ if ( obj . name && options . name && obj . name !== options . name ) {
245+ return ;
246+ }
244247 if ( options . log ) {
245248 console . log (
246249 '[HMR] bundle ' +
@@ -250,6 +253,9 @@ function processMessage(obj) {
250253 }
251254 break ;
252255 case 'built' :
256+ if ( obj . name && options . name && obj . name !== options . name ) {
257+ return ;
258+ }
253259 if ( options . log ) {
254260 console . log (
255261 '[HMR] bundle ' +
Original file line number Diff line number Diff line change 11module . exports = webpackHotMiddleware ;
2+ module . exports . createEventStream = createEventStream ;
23
34var helpers = require ( './helpers' ) ;
45var pathMatch = helpers . pathMatch ;
@@ -12,7 +13,7 @@ function webpackHotMiddleware(compiler, opts) {
1213 opts . statsOptions =
1314 typeof opts . statsOptions == 'undefined' ? { } : opts . statsOptions ;
1415
15- var eventStream = createEventStream ( opts . heartbeat ) ;
16+ var eventStream = opts . eventStream || createEventStream ( opts . heartbeat ) ;
1617 var latestStats = null ;
1718 var closed = false ;
1819
@@ -27,7 +28,7 @@ function webpackHotMiddleware(compiler, opts) {
2728 if ( closed ) return ;
2829 latestStats = null ;
2930 if ( opts . log ) opts . log ( 'webpack building...' ) ;
30- eventStream . publish ( { action : 'building' } ) ;
31+ eventStream . publish ( { action : 'building' , name : compiler . name } ) ;
3132 }
3233 function onDone ( statsResult ) {
3334 if ( closed ) return ;
Original file line number Diff line number Diff line change @@ -377,6 +377,7 @@ describe('client', function () {
377377 close : sinon . spy ( ) ,
378378 } ) ,
379379 } ;
380+ s . stub ( console , 'log' ) ;
380381 } ) ;
381382 beforeEach ( loadClient ) ;
382383 it ( 'should not trigger webpack if event obj name is different' , function ( ) {
@@ -409,6 +410,26 @@ describe('client', function () {
409410 ) ;
410411 sinon . assert . notCalled ( processUpdate ) ;
411412 } ) ;
413+ it ( 'should not log building if obj name is different' , function ( ) {
414+ var eventSource = window . EventSource . lastCall . returnValue ;
415+ eventSource . onmessage (
416+ makeMessage ( {
417+ name : 'bar' ,
418+ action : 'building' ,
419+ } )
420+ ) ;
421+ sinon . assert . notCalled ( console . log ) ;
422+ } ) ;
423+ it ( 'should not log built if obj name is different' , function ( ) {
424+ var eventSource = window . EventSource . lastCall . returnValue ;
425+ eventSource . onmessage (
426+ makeMessage ( {
427+ name : 'bar' ,
428+ action : 'built' ,
429+ } )
430+ ) ;
431+ sinon . assert . notCalled ( console . log ) ;
432+ } ) ;
412433 } ) ;
413434
414435 context ( 'with no browser environment' , function ( ) {
Original file line number Diff line number Diff line change @@ -19,6 +19,19 @@ describe('middleware', function () {
1919 . expect ( 'Content-Type' , / ^ t e x t \/ e v e n t - s t r e a m \b / )
2020 . end ( done ) ;
2121 } ) ;
22+ it ( 'uses provided eventStream' , function ( done ) {
23+ setupServer ( {
24+ eventStream : {
25+ handler : function ( req , res ) {
26+ res . writeHead ( 201 , { 'Content-Type' : 'fake content type' } ) ;
27+ res . write ( '\n' ) ;
28+ } ,
29+ } ,
30+ } ) ( ) ;
31+ request ( '/__webpack_hmr' )
32+ . expect ( 'Content-Type' , 'fake content type' )
33+ . end ( done ) ;
34+ } ) ;
2235 it ( 'should heartbeat every 10 seconds' , function ( done ) {
2336 request ( '/__webpack_hmr' ) . end ( function ( err , res ) {
2437 if ( err ) return done ( err ) ;
@@ -48,13 +61,14 @@ describe('middleware', function () {
4861 if ( err ) return done ( err ) ;
4962
5063 res . on ( 'data' , verify ) ;
51-
64+ compiler . name = 'test name' ;
5265 compiler . emit ( 'invalid' ) ;
5366
5467 function verify ( ) {
5568 assert . equal ( res . events . length , 1 ) ;
5669 var event = JSON . parse ( res . events [ 0 ] . substring ( 5 ) ) ;
5770 assert . equal ( event . action , 'building' ) ;
71+ assert . equal ( event . name , compiler . name ) ;
5872 done ( ) ;
5973 }
6074 } ) ;
You can’t perform that action at this time.
0 commit comments