@@ -24,6 +24,11 @@ function createFakeThread(response) {
2424 thread . send = function ( ) {
2525 thread . emit ( 'error' , response . error ) ;
2626 } ;
27+ } else if ( response . progress ) {
28+ thread . send = function ( ) {
29+ // Emit multiple progress events
30+ response . progress . forEach ( ( p ) => { thread . emit ( 'progress' , p ) } ) ;
31+ } ;
2732 } else {
2833 thread . send = function ( ) {
2934 thread . emit ( 'message' , ...response . response ) ;
@@ -80,7 +85,8 @@ describe('Job', () => {
8085 const thread = {
8186 once : noop ,
8287 run : noop ,
83- send : noop
88+ send : noop ,
89+ on : noop
8490 } ;
8591 const mock = sinon . mock ( thread ) ;
8692
@@ -92,6 +98,7 @@ describe('Job', () => {
9298
9399 mock . expects ( 'run' ) . once ( ) . withArgs ( runnable , importScripts ) . returnsThis ( ) ;
94100 mock . expects ( 'send' ) . once ( ) . withArgs ( param , transferables ) . returnsThis ( ) ;
101+ mock . expects ( 'on' ) . once ( ) . withArgs ( 'progress' ) . returnsThis ( ) ;
95102
96103 job
97104 . run ( runnable , importScripts )
@@ -101,6 +108,25 @@ describe('Job', () => {
101108 mock . verify ( ) ;
102109 } ) ;
103110
111+ it ( 'triggers multiple progress events' , ( ) => {
112+ const progress1 = { progress : 'progress1' } ;
113+ const progress2 = { progress : 'progress2' } ;
114+ const thread = createFakeThread ( {
115+ progress : [ progress1 , progress2 ]
116+ } ) ;
117+
118+ const job = new Job ( pool ) ;
119+ sinon . spy ( job , 'emit' ) ;
120+
121+ job
122+ . run ( noop )
123+ . send ( )
124+ . executeOn ( thread ) ;
125+
126+ sinon . assert . calledWith ( job . emit , 'progress' , progress1 ) ;
127+ sinon . assert . calledWith ( job . emit , 'progress' , progress2 ) ;
128+ } ) ;
129+
104130 it ( 'triggers done event' , ( ) => {
105131 const thread = createFakeThread ( {
106132 response : [ { foo : 'bar' } , 'more data' ]
0 commit comments