| 634 | |
| 635 | const createImportModuleDynamically = |
| 636 | (context, testFile, moduleCache) => async (specifier, referencing) => { |
| 637 | const identifier = referencing.identifier |
| 638 | ? path.resolve(path.dirname(referencing.identifier), specifier) |
| 639 | : path.resolve(path.dirname(testFile), specifier); |
| 640 | |
| 641 | if (moduleCache.has(identifier)) { |
| 642 | return moduleCache.get(identifier); |
| 643 | } |
| 644 | |
| 645 | const code = await outputFileSystem.promises.readFile(identifier, "utf8"); |
| 646 | const module = new vm.SourceTextModule(code, { |
| 647 | context, |
| 648 | identifier, |
| 649 | importModuleDynamically: createImportModuleDynamically( |
| 650 | context, |
| 651 | testFile, |
| 652 | moduleCache |
| 653 | ) |
| 654 | }); |
| 655 | |
| 656 | moduleCache.set(identifier, module); |
| 657 | |
| 658 | await module.link( |
| 659 | createImportModuleDynamically(context, testFile, moduleCache) |
| 660 | ); |
| 661 | |
| 662 | return module; |
| 663 | }; |
| 664 | |
| 665 | const runModule = async (context, code, identifier, testFile, moduleCache) => { |
| 666 | const module = new vm.SourceTextModule(code, { |