File tree Expand file tree Collapse file tree 4 files changed +23
-1
lines changed
Expand file tree Collapse file tree 4 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -57,7 +57,8 @@ global.Worker = function Worker(url) {
5757 postMessage ( data ) {
5858 outside . emit ( 'message' , { data } ) ;
5959 } ,
60- fetch : global . fetch
60+ fetch : global . fetch ,
61+ importScripts ( ...urls ) { }
6162 } ,
6263 getScopeVar ;
6364 inside . on ( 'message' , e => { let f = getScopeVar ( 'onmessage' ) ; if ( f ) f . call ( scope , e ) ; } ) ;
Original file line number Diff line number Diff line change 11import 'jsdom-worker' ;
22
3+ import fs from 'fs' ;
4+ import path from 'path' ;
5+
36const sleep = t => new Promise ( r => { setTimeout ( r , t ) ; } ) ;
47
58describe ( 'jsdom-worker' , ( ) => {
@@ -11,4 +14,14 @@ describe('jsdom-worker', () => {
1114 await sleep ( 10 ) ;
1215 expect ( worker . onmessage ) . toHaveBeenCalledWith ( { data : 10 } ) ;
1316 } ) ;
17+
18+ it ( 'should work with importScripts' , async ( ) => {
19+ const mod = fs . readFileSync ( path . join ( __dirname , './module.js' ) ) ;
20+ const code = fs . readFileSync ( path . join ( __dirname , './worker.js' ) ) ;
21+ const worker = new Worker ( URL . createObjectURL ( new Blob ( [ mod + code ] ) ) ) ;
22+ worker . onmessage = jest . fn ( ) ;
23+ worker . postMessage ( ) ;
24+ await sleep ( 10 ) ;
25+ expect ( worker . onmessage ) . toHaveBeenCalledWith ( { data : 'test' } ) ;
26+ } ) ;
1427} ) ;
Original file line number Diff line number Diff line change 1+ /* eslint-disable no-unused-vars */
2+ const importedModule = {
3+ string : 'test'
4+ } ;
Original file line number Diff line number Diff line change 1+ /* eslint-disable no-undef */
2+ importScripts ( 'module.js' ) ;
3+
4+ onmessage = ( ) => { postMessage ( importedModule . string ) ; } ;
You can’t perform that action at this time.
0 commit comments