Skip to content

Commit 6f8ba00

Browse files
test: check typescript hook
1 parent d6f5234 commit 6f8ba00

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

test/es-module/test-typescript.mjs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,3 +324,29 @@ test('execute a JavaScript file importing a cjs TypeScript file', async () => {
324324
match(result.stdout, /Hello, TypeScript!/);
325325
strictEqual(result.code, 0);
326326
});
327+
328+
test('execute a TypeScript loader and a .ts file', async () => {
329+
const result = await spawnPromisified(process.execPath, [
330+
'--experimental-strip-types',
331+
'--no-warnings',
332+
'--import',
333+
fixtures.fileURL('typescript/ts/test-loader.ts'),
334+
fixtures.path('typescript/ts/test-typescript.ts'),
335+
]);
336+
strictEqual(result.stderr, '');
337+
match(result.stdout, /Hello, TypeScript!/);
338+
strictEqual(result.code, 0);
339+
});
340+
341+
test('execute a TypeScript loader and a .js file', async () => {
342+
const result = await spawnPromisified(process.execPath, [
343+
'--experimental-strip-types',
344+
'--no-warnings',
345+
'--import',
346+
fixtures.fileURL('typescript/ts/test-loader.ts'),
347+
fixtures.path('typescript/ts/test-simple.js'),
348+
]);
349+
strictEqual(result.stderr, '');
350+
match(result.stdout, /Hello, TypeScript!/);
351+
strictEqual(result.code, 0);
352+
});

test/fixtures/typescript/ts/hook.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import type { ResolveHook } from 'node:module';
2+
3+
// Pass through
4+
export const resolve: ResolveHook = async function resolve(specifier, context, nextResolve) {
5+
return nextResolve(specifier, context);
6+
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { register } from 'node:module';
2+
import * as fixtures from '../../../common/fixtures.mjs';
3+
4+
register(fixtures.fileURL('typescript/ts/hook.ts'));
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const str = "Hello, TypeScript!";
2+
console.log(str);

0 commit comments

Comments
 (0)