@@ -47,7 +47,7 @@ describe('ReactFreshIntegration', () => {
47
47
}
48
48
} ) ;
49
49
50
- function executeCommon ( source , compileDestructuring ) {
50
+ function executeJavaScript ( source , compileDestructuring ) {
51
51
const compiled = babel . transform ( source , {
52
52
babelrc : false ,
53
53
presets : [ '@babel/react' ] ,
@@ -60,6 +60,22 @@ describe('ReactFreshIntegration', () => {
60
60
return executeCompiled ( compiled ) ;
61
61
}
62
62
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
+
63
79
function executeCompiled ( compiled ) {
64
80
exportsObj = { } ;
65
81
// eslint-disable-next-line no-new-func
@@ -86,33 +102,19 @@ describe('ReactFreshIntegration', () => {
86
102
return ReactFreshRuntime . createSignatureFunctionForTransform ( ) ;
87
103
}
88
104
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 ) => {
116
118
function render ( source ) {
117
119
const Component = execute ( source ) ;
118
120
act ( ( ) => {
@@ -159,9 +161,9 @@ describe('ReactFreshIntegration', () => {
159
161
}
160
162
161
163
test ( render , patch ) ;
162
- }
164
+ } ) ;
163
165
164
- function testCommon ( render , patch ) {
166
+ function testJavaScript ( render , patch ) {
165
167
it ( 'reloads function declarations' , ( ) => {
166
168
if ( __DEV__ ) {
167
169
render ( `
@@ -1975,7 +1977,7 @@ describe('ReactFreshIntegration', () => {
1975
1977
} ) ;
1976
1978
}
1977
1979
1978
- function testTypescript ( render , patch ) {
1980
+ function testTypeScript ( render , patch ) {
1979
1981
it ( 'reloads component exported in typescript namespace' , ( ) => {
1980
1982
if ( __DEV__ ) {
1981
1983
render ( `
0 commit comments