MCPcopy
hub / github.com/TypeStrong/ts-node / execute

Function execute

src/test/resolver.spec.ts:746–795  ·  view source on GitHub ↗

* Assertions happen here

(t: T, p: FsProject, entrypoints: Entrypoint[])

Source from the content-addressed store, hash-verified

744 * Assertions happen here
745 */
746async function execute(t: T, p: FsProject, entrypoints: Entrypoint[]) {
747 //
748 // Install ts-node and try to import all the index-* files
749 //
750
751 const service = t.context.tsNodeUnderTest.register({
752 projectSearchDir: p.cwd,
753 });
754 process.__test_setloader__(t.context.tsNodeUnderTest.createEsmHooks(service));
755
756 for (const entrypoint of entrypoints) {
757 t.log(`Importing ${join(p.cwd, entrypoint)}`);
758 try {
759 const { result } = await dynamicImport(
760 pathToFileURL(join(p.cwd, entrypoint))
761 );
762 expect(result).toBeInstanceOf(Promise);
763 expect(result.mark).toBe('marked');
764 const testsRun = await result;
765 t.log(`Entrypoint ran ${testsRun} tests.`);
766 } catch (e) {
767 try {
768 const launchJsonPath = Path.resolve(
769 __dirname,
770 '../../.vscode/launch.json'
771 );
772 const launchJson = JSON.parse(fs.readFileSync(launchJsonPath, 'utf8'));
773 const config = launchJson.configurations.find(
774 (c: any) => c.name === 'Debug resolver test'
775 );
776 config.cwd = Path.join(
777 '${workspaceFolder}',
778 Path.relative(Path.resolve(__dirname, '../..'), p.cwd)
779 );
780 config.program = `./${entrypoint}`;
781 fs.writeFileSync(launchJsonPath, JSON.stringify(launchJson, null, 2));
782 } catch {}
783 throw new Error(
784 [
785 (e as Error).message,
786 (e as Error).stack,
787 '',
788 'This is an error in a resolver test. It might be easier to investigate by running outside of the test suite.',
789 'To do that, try pasting this into your bash shell (windows invocation will be similar but maybe not identical):',
790 ` ( cd ${p.cwd} ; node --loader ../../../esm.mjs ./${entrypoint} )`,
791 ].join('\n')
792 );
793 }
794 }
795}
796
797function fileInfo(filename: string, typeModule: boolean, allowJs: boolean) {
798 const ext = filename.match(/\.(.*)$/)?.[1] ?? filename;

Callers 1

declareProjectFunction · 0.85

Calls 1

__test_setloader__Method · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…