@@ -10,6 +10,8 @@ const cjsLoadingESMError = /Unexpected token 'export'/;
1010const esmLoadingCJSError = / m o d u l e i s n o t d e f i n e d / ;
1111const invalidValueError =
1212 / T h e a r g u m e n t ' o p t i o n s \. t y p e ' m u s t b e e i t h e r " m o d u l e " o r " c l a s s i c " / ;
13+ const invalidValueError2 =
14+ / T h e a r g u m e n t ' o p t i o n s \. t y p e ' m u s t b e s e t t o " m o d u l e " w h e n f i l e n a m e i s a d a t a : U R L / ;
1315
1416function runInWorker ( evalString , options ) {
1517 return new Promise ( ( resolve , reject ) => {
@@ -19,20 +21,42 @@ function runInWorker(evalString, options) {
1921 } ) ;
2022}
2123
22- let options ;
24+ {
25+ const options = { eval : true } ;
26+ assert . rejects ( runInWorker ( moduleString , options ) , cjsLoadingESMError ) ;
27+ runInWorker ( cjsString , options ) ; // does not reject
28+ }
2329
24- options = { eval : true } ;
25- assert . rejects ( runInWorker ( moduleString , options ) , cjsLoadingESMError ) ;
26- runInWorker ( cjsString , options ) ; // does not reject
30+ {
31+ const options = { eval : true , type : 'classic' } ;
32+ assert . rejects ( runInWorker ( moduleString , options ) , cjsLoadingESMError ) ;
33+ runInWorker ( cjsString , options ) ; // does not reject
34+ }
2735
28- options = { eval : true , type : 'classic' } ;
29- assert . rejects ( runInWorker ( moduleString , options ) , cjsLoadingESMError ) ;
30- runInWorker ( cjsString , options ) ; // does not reject
36+ {
37+ const options = { eval : true , type : 'module' } ;
38+ runInWorker ( moduleString , options ) ; // does not reject
39+ assert . rejects ( runInWorker ( cjsString , options ) , esmLoadingCJSError ) ;
40+ }
3141
32- options = { eval : true , type : 'module' } ;
33- runInWorker ( moduleString , options ) ; // does not reject
34- assert . rejects ( runInWorker ( cjsString , options ) , esmLoadingCJSError ) ;
42+ {
43+ const options = { eval : false , type : 'module' } ;
44+ runInWorker ( new URL ( `data:text/javascript,${ moduleString } ` ) ,
45+ options ) ; // does not reject
46+ assert . rejects ( runInWorker ( new URL ( `data:text/javascript,${ cjsString } ` ) ,
47+ options ) , esmLoadingCJSError ) ;
48+ }
3549
36- options = { eval : true , type : 'wasm' } ;
37- assert . rejects ( runInWorker ( moduleString , options ) , invalidValueError ) ;
38- assert . rejects ( runInWorker ( cjsString , options ) , invalidValueError ) ;
50+ {
51+ const options = { eval : true , type : 'wasm' } ;
52+ assert . rejects ( runInWorker ( moduleString , options ) , invalidValueError ) ;
53+ assert . rejects ( runInWorker ( cjsString , options ) , invalidValueError ) ;
54+ }
55+
56+ {
57+ const options = { type : 'classic' } ;
58+ assert . rejects ( runInWorker ( new URL ( `data:text/javascript,${ moduleString } ` ) ,
59+ options ) , invalidValueError2 ) ;
60+ assert . rejects ( runInWorker ( new URL ( `data:text/javascript,${ cjsString } ` ) ,
61+ options ) , invalidValueError2 ) ;
62+ }
0 commit comments