|
7 | 7 | * @flow |
8 | 8 | */ |
9 | 9 |
|
| 10 | +import {getVersionedRenderImplementation} from './utils'; |
| 11 | + |
10 | 12 | describe('Fast Refresh', () => { |
11 | 13 | let React; |
12 | 14 | let ReactFreshRuntime; |
13 | 15 | let act; |
14 | 16 | let babel; |
15 | | - let container; |
16 | 17 | let exportsObj; |
17 | 18 | let freshPlugin; |
18 | | - let legacyRender; |
19 | 19 | let store; |
20 | 20 | let withErrorsOrWarningsIgnored; |
21 | 21 |
|
22 | | - afterEach(() => { |
23 | | - jest.resetModules(); |
24 | | - }); |
25 | | - |
26 | 22 | beforeEach(() => { |
27 | 23 | exportsObj = undefined; |
28 | | - container = document.createElement('div'); |
29 | 24 |
|
30 | 25 | babel = require('@babel/core'); |
31 | 26 | freshPlugin = require('react-refresh/babel'); |
@@ -39,10 +34,12 @@ describe('Fast Refresh', () => { |
39 | 34 |
|
40 | 35 | const utils = require('./utils'); |
41 | 36 | act = utils.act; |
42 | | - legacyRender = utils.legacyRender; |
43 | 37 | withErrorsOrWarningsIgnored = utils.withErrorsOrWarningsIgnored; |
44 | 38 | }); |
45 | 39 |
|
| 40 | + const {render: renderImplementation, getContainer} = |
| 41 | + getVersionedRenderImplementation(); |
| 42 | + |
46 | 43 | function execute(source) { |
47 | 44 | const compiled = babel.transform(source, { |
48 | 45 | babelrc: false, |
@@ -73,7 +70,7 @@ describe('Fast Refresh', () => { |
73 | 70 | function render(source) { |
74 | 71 | const Component = execute(source); |
75 | 72 | act(() => { |
76 | | - legacyRender(<Component />, container); |
| 73 | + renderImplementation(<Component />); |
77 | 74 | }); |
78 | 75 | // Module initialization shouldn't be counted as a hot update. |
79 | 76 | expect(ReactFreshRuntime.performReactRefresh()).toBe(null); |
@@ -98,7 +95,7 @@ describe('Fast Refresh', () => { |
98 | 95 | // Here, we'll just force a re-render using the newer type to emulate this. |
99 | 96 | const NextComponent = nextExports.default; |
100 | 97 | act(() => { |
101 | | - legacyRender(<NextComponent />, container); |
| 98 | + renderImplementation(<NextComponent />); |
102 | 99 | }); |
103 | 100 | } |
104 | 101 | act(() => { |
@@ -142,8 +139,8 @@ describe('Fast Refresh', () => { |
142 | 139 | <Child key="A"> |
143 | 140 | `); |
144 | 141 |
|
145 | | - let element = container.firstChild; |
146 | | - expect(container.firstChild).not.toBe(null); |
| 142 | + let element = getContainer().firstChild; |
| 143 | + expect(getContainer().firstChild).not.toBe(null); |
147 | 144 |
|
148 | 145 | patch(` |
149 | 146 | function Parent() { |
@@ -163,8 +160,8 @@ describe('Fast Refresh', () => { |
163 | 160 | `); |
164 | 161 |
|
165 | 162 | // State is preserved; this verifies that Fast Refresh is wired up. |
166 | | - expect(container.firstChild).toBe(element); |
167 | | - element = container.firstChild; |
| 163 | + expect(getContainer().firstChild).toBe(element); |
| 164 | + element = getContainer().firstChild; |
168 | 165 |
|
169 | 166 | patch(` |
170 | 167 | function Parent() { |
@@ -184,7 +181,7 @@ describe('Fast Refresh', () => { |
184 | 181 | `); |
185 | 182 |
|
186 | 183 | // State is reset because hooks changed. |
187 | | - expect(container.firstChild).not.toBe(element); |
| 184 | + expect(getContainer().firstChild).not.toBe(element); |
188 | 185 | }); |
189 | 186 |
|
190 | 187 | // @reactVersion >= 16.9 |
|