Skip to content

Commit 5f4d560

Browse files
committed
Move rollupCache to test helper/utils file
1 parent a4662cb commit 5f4d560

File tree

3 files changed

+9
-29
lines changed

3 files changed

+9
-29
lines changed

packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js

+2-8
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ let buffer = '';
3232
let hasErrored = false;
3333
let fatalError = undefined;
3434
const renderOptions = {};
35-
const rollupCache: Map<string, string | null> = new Map();
3635

3736
describe('ReactDOMFizzServer', () => {
3837
beforeEach(() => {
@@ -137,7 +136,7 @@ describe('ReactDOMFizzServer', () => {
137136
container.nodeName === '#document' ? container.body : container;
138137
while (fakeBody.firstChild) {
139138
const node = fakeBody.firstChild;
140-
await replaceScriptsAndMove(window, rollupCache, CSPnonce, node, parent);
139+
await replaceScriptsAndMove(window, CSPnonce, node, parent);
141140
}
142141
}
143142

@@ -163,12 +162,7 @@ describe('ReactDOMFizzServer', () => {
163162
document = jsdom.window.document;
164163
container = document;
165164
buffer = '';
166-
await replaceScriptsAndMove(
167-
window,
168-
rollupCache,
169-
CSPnonce,
170-
document.documentElement,
171-
);
165+
await replaceScriptsAndMove(window, CSPnonce, document.documentElement);
172166
}
173167

174168
function getVisibleChildren(element) {

packages/react-dom/src/__tests__/ReactDOMFloat-test.js

+2-14
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ let buffer = '';
2727
let hasErrored = false;
2828
let fatalError = undefined;
2929
const renderOptions = {};
30-
const rollupCache: Map<string, string | null> = new Map();
3130

3231
describe('ReactDOMFloat', () => {
3332
beforeEach(() => {
@@ -103,13 +102,7 @@ describe('ReactDOMFloat', () => {
103102
container.nodeName === '#document' ? container.body : container;
104103
while (fakeBody.firstChild) {
105104
const node = fakeBody.firstChild;
106-
await replaceScriptsAndMove(
107-
document.defaultView,
108-
rollupCache,
109-
CSPnonce,
110-
node,
111-
parent,
112-
);
105+
await replaceScriptsAndMove(document.defaultView, CSPnonce, node, parent);
113106
}
114107
}
115108

@@ -134,12 +127,7 @@ describe('ReactDOMFloat', () => {
134127
document = jsdom.window.document;
135128
container = document;
136129
buffer = '';
137-
await replaceScriptsAndMove(
138-
jsdom.window,
139-
rollupCache,
140-
null,
141-
document.documentElement,
142-
);
130+
await replaceScriptsAndMove(jsdom.window, null, document.documentElement);
143131
}
144132

145133
function getMeaningfulChildren(element) {

packages/react-dom/src/test-utils/FizzTestUtils.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ import * as fs from 'fs';
1313
import replace from 'rollup-plugin-replace';
1414
import {rollup} from 'rollup';
1515

16+
const rollupCache: Map<string, string | null> = new Map();
17+
1618
// Utility function to read and bundle a standalone browser script
17-
async function getRollupResult(
18-
scriptSrc: string,
19-
rollupCache: Map<string, string | null>,
20-
): Promise<string | null> {
19+
async function getRollupResult(scriptSrc: string): Promise<string | null> {
2120
const cachedResult = rollupCache.get(scriptSrc);
2221
if (cachedResult !== undefined) {
2322
return cachedResult;
@@ -71,7 +70,6 @@ async function getRollupResult(
7170
// 2. Resolving scripts with sources
7271
async function replaceScriptsAndMove(
7372
window: any,
74-
rollupCache: Map<string, string | null>,
7573
CSPnonce: string | null,
7674
node: Node,
7775
parent: Node | null,
@@ -85,7 +83,7 @@ async function replaceScriptsAndMove(
8583
const script = window.document.createElement('SCRIPT');
8684
const scriptSrc = element.getAttribute('src');
8785
if (scriptSrc) {
88-
const rollupOutput = await getRollupResult(scriptSrc, rollupCache);
86+
const rollupOutput = await getRollupResult(scriptSrc);
8987
if (rollupOutput) {
9088
// Manually call eval(...) here, since changing the HTML text content
9189
// may interfere with hydration
@@ -107,7 +105,7 @@ async function replaceScriptsAndMove(
107105
} else {
108106
for (let i = 0; i < node.childNodes.length; i++) {
109107
const inner = node.childNodes[i];
110-
await replaceScriptsAndMove(window, rollupCache, CSPnonce, inner, null);
108+
await replaceScriptsAndMove(window, CSPnonce, inner, null);
111109
}
112110
if (parent != null) {
113111
parent.appendChild(node);

0 commit comments

Comments
 (0)