Skip to content

Commit e83b208

Browse files
test: check typescript loader
1 parent 10addb0 commit e83b208

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

test/es-module/test-typescript.mjs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,3 +414,29 @@ test('expect error when executing a TypeScript file with generics', async () =>
414414
strictEqual(result.stdout, '');
415415
strictEqual(result.code, 1);
416416
});
417+
418+
test('execute a TypeScript loader and a .ts file', async () => {
419+
const result = await spawnPromisified(process.execPath, [
420+
'--experimental-strip-types',
421+
'--no-warnings',
422+
'--import',
423+
fixtures.fileURL('typescript/ts/test-loader.ts'),
424+
fixtures.path('typescript/ts/test-typescript.ts'),
425+
]);
426+
strictEqual(result.stderr, '');
427+
match(result.stdout, /Hello, TypeScript!/);
428+
strictEqual(result.code, 0);
429+
});
430+
431+
test('execute a TypeScript loader and a .js file', async () => {
432+
const result = await spawnPromisified(process.execPath, [
433+
'--experimental-strip-types',
434+
'--no-warnings',
435+
'--import',
436+
fixtures.fileURL('typescript/ts/test-loader.ts'),
437+
fixtures.path('typescript/ts/test-simple.js'),
438+
]);
439+
strictEqual(result.stderr, '');
440+
match(result.stdout, /Hello, TypeScript!/);
441+
strictEqual(result.code, 0);
442+
});

test/fixtures/typescript/ts/hook.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { ResolveHook } from 'node:module';
2+
3+
// Pass through
4+
export const resolve: ResolveHook = async function resolve(specifier, context, nextResolve) {
5+
if(false){
6+
// https://github.com/nodejs/node/issues/54645
7+
// A bug in the typescript parsers swc causes
8+
// the next line to not be parsed correctly
9+
}
10+
return nextResolve(specifier, context);
11+
};
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)