@@ -552,7 +552,14 @@ async function runCodeInHarness(yaml, code, importDir) {
552
552
let module = moduleCache . get ( modulePath )
553
553
if ( ! module ) {
554
554
const code = fs . readFileSync ( modulePath , 'utf8' )
555
- module = new vm . SourceTextModule ( code + unique ( ) , { context, importModuleDynamically } )
555
+ if ( modulePath . endsWith ( 'json' ) ) {
556
+ const evaluate = function ( ) {
557
+ this . setExport ( 'default' , vm . runInContext ( 'JSON.parse' , context ) ( code ) )
558
+ }
559
+ module = new vm . SyntheticModule ( [ 'default' ] , evaluate , { context } )
560
+ } else {
561
+ module = new vm . SourceTextModule ( code + unique ( ) , { context, importModuleDynamically } )
562
+ }
556
563
moduleCache . set ( modulePath , module )
557
564
}
558
565
return module
@@ -567,9 +574,13 @@ async function runCodeInHarness(yaml, code, importDir) {
567
574
let promise = dynamicImportCache . get ( where )
568
575
if ( ! promise ) {
569
576
const module = findModule ( where , context )
570
- promise = module . link ( linker )
571
- . then ( ( ) => module . evaluate ( ) )
572
- . then ( ( ) => module )
577
+ if ( module . status === 'unlinked' ) {
578
+ promise = module . link ( linker )
579
+ . then ( ( ) => module . evaluate ( ) )
580
+ . then ( ( ) => module )
581
+ } else {
582
+ promise = Promise . resolve ( module )
583
+ }
573
584
dynamicImportCache . set ( where , promise )
574
585
}
575
586
return promise
0 commit comments