@@ -16,108 +16,124 @@ const pluginOptions = {
1616 prettierPath,
1717}
1818
19- it ( 'babelPluginReactLive' , async ( ) => {
20- const babelFileResult = await transformFileAsync ( targetFile , {
21- code : true ,
22- presets : [
23- [
24- '@babel/preset-env' ,
25- {
26- modules : false ,
27- targets : { firefox : '100' } ,
28- } ,
19+ describe ( 'transformFileAsync' , ( ) => {
20+ it ( 'should convert Examples.tsx with all exported examples' , async ( ) => {
21+ const babelFileResult = await transformFileAsync ( targetFile , {
22+ code : true ,
23+ presets : [
24+ [
25+ '@babel/preset-env' ,
26+ {
27+ modules : false ,
28+ targets : { firefox : '100' } ,
29+ } ,
30+ ] ,
2931 ] ,
30- ] ,
31- plugins : [ [ babelPluginReactLive , pluginOptions ] ] ,
32- } )
32+ plugins : [ [ babelPluginReactLive , pluginOptions ] ] ,
33+ } )
3334
34- const code = removeConsoleNinja ( String ( babelFileResult ?. code ) )
35+ const code = removeConsoleNinja ( String ( babelFileResult ?. code ) )
3536
36- const formattedCode = prettier . format ( code , {
37- filepath : 'file.tsx' ,
38- semi : false ,
39- } )
37+ const formattedCode = prettier . format ( code , {
38+ filepath : 'file.tsx' ,
39+ semi : false ,
40+ } )
4041
41- expect ( formattedCode ) . toMatchInlineSnapshot ( `
42- "const ComponentBox = ({ children }) => children
43- export const MockNoInlineWithComponent = () => {
44- return (
45- <ComponentBox data-test="id" noInline>{\`const DemoComponent = () => {
46- return <>content</>
47- }
48- render(
49- <div>
50- <DemoComponent />
51- </div>
52- )
53- \`}</ComponentBox>
42+ expect ( formattedCode ) . toMatchInlineSnapshot ( `
43+ "const ComponentBox = ({ children }) => children
44+ export const MockNoInlineWithComponent = () => {
45+ return (
46+ <ComponentBox data-test="id" noInline>{\`const DemoComponent = () => {
47+ return <>content</>
48+ }
49+ render(
50+ <div>
51+ <DemoComponent />
52+ </div>
5453 )
55- }
56- export const MockNoInlineWithText = () => {
57- return (
58- <ComponentBox data-test="id" noInline>{\`render(<>content</>)
59- \`}</ComponentBox>
54+ \`}</ComponentBox>
55+ )
56+ }
57+ export const MockNoInlineWithBackticks = () => {
58+ return (
59+ <ComponentBox data-test="id" noInline>{\`const DemoComponent = () => {
60+ const more = '456'
61+ return \\\`123\\\${more}\\\` + \\\`789\\\`
62+ }
63+ render(
64+ <div>
65+ <DemoComponent />
66+ </div>
6067 )
61- }
62- export const MockOneChilds = () => {
63- return (
64- <ComponentBox data-test="id">{\`<div>content</div>
65- \`}</ComponentBox>
66- )
67- }
68- export const MockManyChilds = () => {
69- return (
70- <ComponentBox data-test="id">{\`
71- <div>content 1</div>
72- <div>content 2</div>
73- <div>content 3</div>
68+ \`}</ComponentBox>
69+ )
70+ }
71+ export const MockNoInlineWithText = () => {
72+ return (
73+ <ComponentBox data-test="id" noInline>{\`render(<>content</>)
74+ \`}</ComponentBox>
75+ )
76+ }
77+ export const MockOneChilds = () => {
78+ return (
79+ <ComponentBox data-test="id">{\`<div>content</div>
80+ \`}</ComponentBox>
81+ )
82+ }
83+ export const MockManyChilds = () => {
84+ return (
85+ <ComponentBox data-test="id">{\`
86+ <div>content 1</div>
87+ <div>content 2</div>
88+ <div>content 3</div>
7489
75- \`}</ComponentBox>
76- )
77- }
78- export const MockFragment = () => {
79- return (
80- <ComponentBox data-test="id">{\`<>
81- <span>content 1</span>
82- <span>content 2</span>
83- <span>content 3</span>
84- </>
85- \`}</ComponentBox>
86- )
87- }
88- export const MockText = () => {
89- return (
90- <ComponentBox data-test="id">{\`
91- text
92- {'text'}
93- <span>content</span>
94- text
95- {'text'}
90+ \`}</ComponentBox>
91+ )
92+ }
93+ export const MockFragment = () => {
94+ return (
95+ <ComponentBox data-test="id">{\`<>
96+ <span>content 1</span>
97+ <span>content 2</span>
98+ <span>content 3</span>
99+ </>
100+ \`}</ComponentBox>
101+ )
102+ }
103+ export const MockText = () => {
104+ return (
105+ <ComponentBox data-test="id">{\`
106+ text
107+ {'text'}
108+ <span>content</span>
109+ text
110+ {'text'}
96111
97- \`}</ComponentBox>
98- )
99- }
100- export const MockEvents = () => {
101- return (
102- <ComponentBox data-test="id">{\`<DemoComponent
103- onChange={(e) => {
104- // comment
105- console.log(e)
106- }}
107- onOpen={(e) => 'console.log(e)'}
108- onFocus={(e) => {
109- const cleaned = 'console.log(e)'
110- }}
111- />
112- \`}</ComponentBox>
113- )
114- }
115- "
116- ` )
112+ \`}</ComponentBox>
113+ )
114+ }
115+ export const MockEvents = () => {
116+ return (
117+ <ComponentBox data-test="id">{\`<DemoComponent
118+ onChange={(e) => {
119+ // comment
120+ console.log(e)
121+ }}
122+ onOpen={(e) => 'console.log(e)'}
123+ onFocus={(e) => {
124+ const cleaned = 'console.log(e)'
125+ }}
126+ />
127+ \`}</ComponentBox>
128+ )
129+ }
130+ "
131+ ` )
117132
118- expect ( formattedCode . match ( / n o I n l i n e / g) ) . toHaveLength ( 2 )
119- expect ( formattedCode . match ( / \{ ` / g) ) . toHaveLength ( 7 )
120- expect ( formattedCode . match ( / ` \} / g) ) . toHaveLength ( 7 )
133+ expect ( formattedCode . match ( / n o I n l i n e / g) ) . toHaveLength ( 3 )
134+ expect ( formattedCode . match ( / \{ ` / g) ) . toHaveLength ( 8 )
135+ expect ( formattedCode . match ( / ` \} / g) ) . toHaveLength ( 8 )
136+ } )
121137} )
122138
123139function removeConsoleNinja ( code ) {
0 commit comments