Skip to content

Commit 9369942

Browse files
marco-ippolitoaduh95
authored andcommitted
test: check typescript loader
PR-URL: #54657 Refs: #54645 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent a4f336f commit 9369942

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

test/es-module/test-typescript.mjs

+26
Original file line numberDiff line numberDiff line change
@@ -323,3 +323,29 @@ test('expect error when executing a TypeScript file with generics', async () =>
323323
strictEqual(result.stdout, '');
324324
strictEqual(result.code, 1);
325325
});
326+
327+
test('execute a TypeScript loader and a .ts file', async () => {
328+
const result = await spawnPromisified(process.execPath, [
329+
'--experimental-strip-types',
330+
'--no-warnings',
331+
'--import',
332+
fixtures.fileURL('typescript/ts/test-loader.ts'),
333+
fixtures.path('typescript/ts/test-typescript.ts'),
334+
]);
335+
strictEqual(result.stderr, '');
336+
match(result.stdout, /Hello, TypeScript!/);
337+
strictEqual(result.code, 0);
338+
});
339+
340+
test('execute a TypeScript loader and a .js file', async () => {
341+
const result = await spawnPromisified(process.execPath, [
342+
'--experimental-strip-types',
343+
'--no-warnings',
344+
'--import',
345+
fixtures.fileURL('typescript/ts/test-loader.ts'),
346+
fixtures.path('typescript/ts/test-simple.js'),
347+
]);
348+
strictEqual(result.stderr, '');
349+
match(result.stdout, /Hello, TypeScript!/);
350+
strictEqual(result.code, 0);
351+
});

test/fixtures/typescript/ts/hook.ts

+11
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+
};
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'));
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)