diff --git a/test/es-module/test-typescript.mjs b/test/es-module/test-typescript.mjs index 3fc753e56c8c8d..235562d2e3dc1c 100644 --- a/test/es-module/test-typescript.mjs +++ b/test/es-module/test-typescript.mjs @@ -324,3 +324,29 @@ test('execute a JavaScript file importing a cjs TypeScript file', async () => { match(result.stdout, /Hello, TypeScript!/); strictEqual(result.code, 0); }); + +test('execute a TypeScript loader and a .ts file', async () => { + const result = await spawnPromisified(process.execPath, [ + '--experimental-strip-types', + '--no-warnings', + '--import', + fixtures.fileURL('typescript/ts/test-loader.ts'), + fixtures.path('typescript/ts/test-typescript.ts'), + ]); + strictEqual(result.stderr, ''); + match(result.stdout, /Hello, TypeScript!/); + strictEqual(result.code, 0); +}); + +test('execute a TypeScript loader and a .js file', async () => { + const result = await spawnPromisified(process.execPath, [ + '--experimental-strip-types', + '--no-warnings', + '--import', + fixtures.fileURL('typescript/ts/test-loader.ts'), + fixtures.path('typescript/ts/test-simple.js'), + ]); + strictEqual(result.stderr, ''); + match(result.stdout, /Hello, TypeScript!/); + strictEqual(result.code, 0); +}); diff --git a/test/fixtures/typescript/ts/hook.ts b/test/fixtures/typescript/ts/hook.ts new file mode 100644 index 00000000000000..7f35f61abc04a7 --- /dev/null +++ b/test/fixtures/typescript/ts/hook.ts @@ -0,0 +1,6 @@ +import type { ResolveHook } from 'node:module'; + +// Pass through +export const resolve: ResolveHook = async function resolve(specifier, context, nextResolve) { + return nextResolve(specifier, context); +}; diff --git a/test/fixtures/typescript/ts/test-loader.ts b/test/fixtures/typescript/ts/test-loader.ts new file mode 100644 index 00000000000000..8b957bf72f0aa0 --- /dev/null +++ b/test/fixtures/typescript/ts/test-loader.ts @@ -0,0 +1,4 @@ +import { register } from 'node:module'; +import * as fixtures from '../../../common/fixtures.mjs'; + +register(fixtures.fileURL('typescript/ts/hook.ts')); diff --git a/test/fixtures/typescript/ts/test-simple.js b/test/fixtures/typescript/ts/test-simple.js new file mode 100644 index 00000000000000..f738e60f7d61db --- /dev/null +++ b/test/fixtures/typescript/ts/test-simple.js @@ -0,0 +1,2 @@ +const str = "Hello, TypeScript!"; +console.log(str);