@@ -47,7 +47,7 @@ describe('ReactFreshIntegration', () => {
4747 }
4848 } ) ;
4949
50- function executeCommon ( source , compileDestructuring ) {
50+ function executeJavaScript ( source , compileDestructuring ) {
5151 const compiled = babel . transform ( source , {
5252 babelrc : false ,
5353 presets : [ '@babel/react' ] ,
@@ -60,6 +60,22 @@ describe('ReactFreshIntegration', () => {
6060 return executeCompiled ( compiled ) ;
6161 }
6262
63+ function executeTypescript ( source ) {
64+ const typescriptSource = babel . transform ( source , {
65+ babelrc : false ,
66+ configFile : false ,
67+ presets : [ '@babel/react' ] ,
68+ plugins : [
69+ [ freshPlugin , { skipEnvCheck : true } ] ,
70+ [ '@babel/plugin-syntax-typescript' , { isTSX : true } ] ,
71+ ] ,
72+ } ) . code ;
73+ const compiled = ts . transpileModule ( typescriptSource , {
74+ module : ts . ModuleKind . CommonJS ,
75+ } ) . outputText ;
76+ return executeCompiled ( compiled ) ;
77+ }
78+
6379 function executeCompiled ( compiled ) {
6480 exportsObj = { } ;
6581 // eslint-disable-next-line no-new-func
@@ -86,33 +102,19 @@ describe('ReactFreshIntegration', () => {
86102 return ReactFreshRuntime . createSignatureFunctionForTransform ( ) ;
87103 }
88104
89- describe ( 'with compiled destructuring' , ( ) => {
90- runTests ( executeCommon , testCommon ) ;
91- } ) ;
92-
93- describe ( 'without compiled destructuring' , ( ) => {
94- runTests ( executeCommon , testCommon ) ;
95- } ) ;
96-
97- describe ( 'with typescript syntax' , ( ) => {
98- runTests ( function ( source ) {
99- const typescriptSource = babel . transform ( source , {
100- babelrc : false ,
101- configFile : false ,
102- presets : [ '@babel/react' ] ,
103- plugins : [
104- [ freshPlugin , { skipEnvCheck : true } ] ,
105- [ '@babel/plugin-syntax-typescript' , { isTSX : true } ] ,
106- ] ,
107- } ) . code ;
108- const compiled = ts . transpileModule ( typescriptSource , {
109- module : ts . ModuleKind . CommonJS ,
110- } ) . outputText ;
111- return executeCompiled ( compiled ) ;
112- } , testTypescript ) ;
113- } ) ;
114-
115- function runTests ( execute , test ) {
105+ describe . each ( [
106+ [
107+ 'JavaScript syntax with destructuring enabled' ,
108+ source => executeJavaScript ( source , true ) ,
109+ testJavaScript ,
110+ ] ,
111+ [
112+ 'JavaScript syntax with destructuring disabled' ,
113+ source => executeJavaScript ( source , false ) ,
114+ testJavaScript ,
115+ ] ,
116+ [ 'TypeScript syntax' , executeTypescript , testTypeScript ] ,
117+ ] ) ( '%s' , ( language , execute , test ) => {
116118 function render ( source ) {
117119 const Component = execute ( source ) ;
118120 act ( ( ) => {
@@ -159,9 +161,9 @@ describe('ReactFreshIntegration', () => {
159161 }
160162
161163 test ( render , patch ) ;
162- }
164+ } ) ;
163165
164- function testCommon ( render , patch ) {
166+ function testJavaScript ( render , patch ) {
165167 it ( 'reloads function declarations' , ( ) => {
166168 if ( __DEV__ ) {
167169 render ( `
@@ -1975,7 +1977,7 @@ describe('ReactFreshIntegration', () => {
19751977 } ) ;
19761978 }
19771979
1978- function testTypescript ( render , patch ) {
1980+ function testTypeScript ( render , patch ) {
19791981 it ( 'reloads component exported in typescript namespace' , ( ) => {
19801982 if ( __DEV__ ) {
19811983 render ( `
0 commit comments