Fix ReactFreshIntegration-test not running all tests as assumed (#28033)
Fix ReactFreshIntegration-test not running all tests as assumed `testCommon` was executed twice without setting `compileDestructuring` ever to true. This fixes this and removes one layer of abstraction in this test by using `describe.each`.
Jan Kassens committed
Jan 23, 2024 at 09:59 UTC
cb9899955b3d2c6e1e4477585f06068c2007efec
1 file changed
+33
-31
packages/react-refresh/src/__tests__/ReactFreshIntegration-test.js
+33
-31
@@ -47,7 +47,7 @@ describe('ReactFreshIntegration', () => {
47
}
48
});
49
50
- function executeCommon(source, compileDestructuring) {
50
+ function executeJavaScript(source, compileDestructuring) {
51
const compiled = babel.transform(source, {
52
babelrc: false,
53
presets: ['@babel/react'],
@@ -60,6 +60,22 @@ describe('ReactFreshIntegration', () => {
60
return executeCompiled(compiled);
61
}
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
+
79
function executeCompiled(compiled) {
80
exportsObj = {};
81
// eslint-disable-next-line no-new-func
@@ -86,33 +102,19 @@ describe('ReactFreshIntegration', () => {
102
return ReactFreshRuntime.createSignatureFunctionForTransform();
103
}
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) => {
118
function render(source) {
119
const Component = execute(source);
120
act(() => {
@@ -159,9 +161,9 @@ describe('ReactFreshIntegration', () => {
161
}
162
163
test(render, patch);
162
- }
164
+ });
165
164
- function testCommon(render, patch) {
166
+ function testJavaScript(render, patch) {
167
it('reloads function declarations', () => {
168
if (__DEV__) {
169
render(`
@@ -1975,7 +1977,7 @@ describe('ReactFreshIntegration', () => {
1977
});
1978
}
1979
1978
- function testTypescript(render, patch) {
1980
+ function testTypeScript(render, patch) {
1981
it('reloads component exported in typescript namespace', () => {
1982
if (__DEV__) {
1983
render(`