Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdf3aced

Browse files
committed
chore: test(tsx): add compile-only TSX tests; remove runtime-dependent resolver TSX test
- transformer: add TSX tests (props + fragments, children + spread props) and assert compiled output exists- resolver: drop TSX require-based test to avoid react/jsx-runtime dependency at runtime
1 parent9fb576e commitdf3aced

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

‎test/transformer.test.ts‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,49 @@ test("TSX support should be available", (t) => {
2525
t.truthy(result.length>0);
2626
});
2727

28+
test("TSX should compile component with props and fragments",(t)=>{
29+
constcode=`
30+
import React from 'react';
31+
type Props = { title: string; items: string[] };
32+
export function List({ title, items }: Props) {
33+
return (
34+
<>
35+
<h1>{title}</h1>
36+
{items.map((it, i) => <div key={i}>{it}</div>)}
37+
</>
38+
);
39+
}
40+
`;
41+
constmt=newModuleTransformer();
42+
constout=mt
43+
.transformSync(Buffer.from(code),"list.tsx",{
44+
target:"es2022",
45+
module:"commonjs",
46+
})
47+
.code.toString();
48+
t.is(typeofout,"string");
49+
t.truthy(out.length>0);
50+
});
51+
52+
test("TSX should compile component with children and spread props",(t)=>{
53+
constcode=`
54+
import React, { type PropsWithChildren } from 'react';
55+
type ButtonProps = PropsWithChildren<{ onClick?: () => void; [k: string]: any }>;
56+
export const Button = ({ children, ...rest }: ButtonProps) => (
57+
<button {...rest}>{children}</button>
58+
);
59+
`;
60+
constmt=newModuleTransformer();
61+
constout=mt
62+
.transformSync(Buffer.from(code),"button.tsx",{
63+
target:"es2022",
64+
module:"commonjs",
65+
})
66+
.code.toString();
67+
t.is(typeofout,"string");
68+
t.truthy(out.length>0);
69+
});
70+
2871
test("TSHook should transform TypeScript code",(t)=>{
2972
consttypescriptCode=`
3073
interface User {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp