Skip to content

Commit f9dab6d

Browse files
test: check typescript loader
1 parent d6f5234 commit f9dab6d

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
@@ -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

+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)