Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: check typescript loader #54657

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions test/es-module/test-typescript.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -323,3 +323,29 @@ test('expect error when executing a TypeScript file with generics', async () =>
strictEqual(result.stdout, '');
strictEqual(result.code, 1);
});

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);
});
11 changes: 11 additions & 0 deletions test/fixtures/typescript/ts/hook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { ResolveHook } from 'node:module';

// Pass through
export const resolve: ResolveHook = async function resolve(specifier, context, nextResolve) {
if(false){
// https://github.com/nodejs/node/issues/54645
marco-ippolito marked this conversation as resolved.
Show resolved Hide resolved
// A bug in the typescript parsers swc causes
// the next line to not be parsed correctly
}
return nextResolve(specifier, context);
};
4 changes: 4 additions & 0 deletions test/fixtures/typescript/ts/test-loader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { register } from 'node:module';
import * as fixtures from '../../../common/fixtures.mjs';

register(fixtures.fileURL('typescript/ts/hook.ts'));
2 changes: 2 additions & 0 deletions test/fixtures/typescript/ts/test-simple.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const str = "Hello, TypeScript!";
console.log(str);
Loading