@@ -34,6 +34,7 @@ import {formatStackTrace, separateMessageFromStack} from 'jest-message-util';
3434import { createDirectory , deepCyclicCopy } from 'jest-util' ;
3535import { escapePathForRegex } from 'jest-regex-util' ;
3636import {
37+ CallerTransformOptions ,
3738 ScriptTransformer ,
3839 ShouldInstrumentOptions ,
3940 TransformationOptions ,
@@ -75,16 +76,16 @@ type HasteMapOptions = {
7576 watchman : boolean ;
7677} ;
7778
78- type InternalModuleOptions = {
79+ interface InternalModuleOptions extends Required < CallerTransformOptions > {
7980 isInternalModule : boolean ;
80- supportsDynamicImport : boolean ;
81- supportsStaticESM : boolean ;
82- } ;
81+ }
8382
8483const defaultTransformOptions : InternalModuleOptions = {
8584 isInternalModule : false ,
8685 supportsDynamicImport : esmIsAvailable ,
86+ supportsExportNamespaceFrom : false ,
8787 supportsStaticESM : false ,
88+ supportsTopLevelAwait : false ,
8889} ;
8990
9091type InitialModule = Omit < Module , 'require' | 'parent' | 'paths' > ;
@@ -141,6 +142,19 @@ type RunScriptEvalResult = {[EVAL_RESULT_VARIABLE]: ModuleWrapper};
141142
142143const runtimeSupportsVmModules = typeof SyntheticModule === 'function' ;
143144
145+ const supportsTopLevelAwait =
146+ runtimeSupportsVmModules &&
147+ ( ( ) => {
148+ try {
149+ // eslint-disable-next-line no-new
150+ new SourceTextModule ( 'await Promise.resolve()' ) ;
151+
152+ return true ;
153+ } catch {
154+ return false ;
155+ }
156+ } ) ( ) ;
157+
144158class Runtime {
145159 private _cacheFS : StringMap ;
146160 private _config : Config . ProjectConfig ;
@@ -378,7 +392,9 @@ class Runtime {
378392 const transformedCode = this . transformFile ( modulePath , {
379393 isInternalModule : false ,
380394 supportsDynamicImport : true ,
395+ supportsExportNamespaceFrom : true ,
381396 supportsStaticESM : true ,
397+ supportsTopLevelAwait,
382398 } ) ;
383399
384400 const module = new SourceTextModule ( transformedCode , {
@@ -608,7 +624,9 @@ class Runtime {
608624 return this . requireModule < T > ( from , to , {
609625 isInternalModule : true ,
610626 supportsDynamicImport : esmIsAvailable ,
627+ supportsExportNamespaceFrom : false ,
611628 supportsStaticESM : false ,
629+ supportsTopLevelAwait : false ,
612630 } ) ;
613631 }
614632
0 commit comments