Skip to content

Commit bff4af5

Browse files
committed
Run all tests in <StrictMode>
- Prevented warnings about legacy context usage from showing up in <StrictMode>. - Added a few different builds of React to the repository for running the tests under different versions of React. Helps with remix-run#6385 and remix-run#6388
1 parent 1dd8be5 commit bff4af5

File tree

311 files changed

+262187
-938
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

311 files changed

+262187
-938
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# node.js
22
node_modules/
3+
!react-builds/*/node_modules/
34
npm-debug.log
45

56
# lerna

packages/react-router-config/modules/__tests__/integration-test.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React from "react";
2-
import ReactDOMServer from "react-dom/server";
32

43
import { StaticRouter } from "react-router";
54
import { matchRoutes, renderRoutes } from "react-router-config";
65

6+
import renderToStringStrict from "./utils/renderToStringStrict";
7+
78
describe("integration", () => {
89
it("generates the same matches in renderRoutes and matchRoutes", () => {
910
const rendered = [];
@@ -44,11 +45,13 @@ describe("integration", () => {
4445

4546
const pathname = "/pepper/jalepeno";
4647
const branch = matchRoutes(routes, pathname);
47-
ReactDOMServer.renderToString(
48+
49+
renderToStringStrict(
4850
<StaticRouter location={pathname} context={{}}>
4951
{renderRoutes(routes)}
5052
</StaticRouter>
5153
);
54+
5255
expect(branch.length).toEqual(2);
5356
expect(rendered.length).toEqual(2);
5457
expect(branch[0].match).toEqual(rendered[0]);
@@ -94,7 +97,7 @@ describe("integration", () => {
9497

9598
const pathname = "/ghost";
9699
const branch = matchRoutes(routes, pathname);
97-
ReactDOMServer.renderToString(
100+
renderToStringStrict(
98101
<StaticRouter location={pathname} context={{}}>
99102
{renderRoutes(routes)}
100103
</StaticRouter>
@@ -129,7 +132,7 @@ describe("integration", () => {
129132

130133
const pathname = "/pepper";
131134
const branch = matchRoutes(routes, pathname);
132-
ReactDOMServer.renderToString(
135+
renderToStringStrict(
133136
<StaticRouter location={pathname} context={{}}>
134137
{renderRoutes(routes)}
135138
</StaticRouter>
@@ -167,17 +170,20 @@ describe("integration", () => {
167170

168171
let pathname = "/pepper";
169172
let branch = matchRoutes(routes, pathname);
170-
ReactDOMServer.renderToString(
173+
174+
renderToStringStrict(
171175
<StaticRouter location={pathname} context={{}}>
172176
{renderRoutes(routes)}
173177
</StaticRouter>
174178
);
179+
175180
expect(branch.length).toEqual(0);
176181
expect(rendered.length).toEqual(0);
177182

178183
pathname = "/pepper/";
179184
branch = matchRoutes(routes, pathname);
180-
ReactDOMServer.renderToString(
185+
186+
renderToStringStrict(
181187
<StaticRouter location={pathname} context={{}}>
182188
{renderRoutes(routes)}
183189
</StaticRouter>

packages/react-router-config/modules/__tests__/renderRoutes-test.js

+25-20
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import React from "react";
22
import ReactDOM from "react-dom";
3-
import ReactDOMServer from "react-dom/server";
43
import createHistory from "history/createMemoryHistory";
54

65
import { Router, StaticRouter } from "react-router";
76
import { renderRoutes } from "react-router-config";
87

8+
import renderStrict from "./utils/renderStrict";
9+
import renderToStringStrict from "./utils/renderToStringStrict";
10+
911
describe("renderRoutes", () => {
1012
let renderedRoutes;
1113
let renderedExtraProps;
@@ -26,7 +28,7 @@ describe("renderRoutes", () => {
2628
};
2729
const routes = [routeToMatch];
2830

29-
ReactDOMServer.renderToString(
31+
renderToStringStrict(
3032
<StaticRouter location="/path" context={{}}>
3133
{renderRoutes(routes)}
3234
</StaticRouter>
@@ -42,7 +44,7 @@ describe("renderRoutes", () => {
4244
const routes = [routeToMatch];
4345
const extraProps = { anExtraProp: "anExtraPropValue" };
4446

45-
ReactDOMServer.renderToString(
47+
renderToStringStrict(
4648
<StaticRouter location="/path" context={{}}>
4749
{renderRoutes(routes, extraProps)}
4850
</StaticRouter>
@@ -64,7 +66,7 @@ describe("renderRoutes", () => {
6466
];
6567
const extraProps = { anExtraProp: "anExtraPropValue" };
6668

67-
ReactDOMServer.renderToString(
69+
renderToStringStrict(
6870
<StaticRouter location="/" context={{}}>
6971
{renderRoutes(routes, extraProps)}
7072
</StaticRouter>
@@ -86,7 +88,7 @@ describe("renderRoutes", () => {
8688
}
8789
];
8890

89-
ReactDOMServer.renderToString(
91+
renderToStringStrict(
9092
<StaticRouter location="/" context={{}}>
9193
{renderRoutes(routes)}
9294
</StaticRouter>
@@ -117,7 +119,7 @@ describe("renderRoutes", () => {
117119
}
118120
];
119121

120-
ReactDOMServer.renderToString(
122+
renderToStringStrict(
121123
<StaticRouter location="/" context={{}}>
122124
{renderRoutes(routes)}
123125
</StaticRouter>
@@ -171,7 +173,7 @@ describe("renderRoutes", () => {
171173
initialEntries: ["/one"]
172174
});
173175

174-
ReactDOM.render(
176+
renderStrict(
175177
<Router history={history}>{renderRoutes(routes)}</Router>,
176178
node
177179
);
@@ -209,7 +211,7 @@ describe("renderRoutes", () => {
209211
}
210212
];
211213

212-
ReactDOMServer.renderToString(
214+
renderToStringStrict(
213215
<StaticRouter location="/two" context={{}}>
214216
{renderRoutes(routes, {}, { location: { pathname: "/one" } })}
215217
</StaticRouter>
@@ -241,7 +243,7 @@ describe("renderRoutes", () => {
241243
routeToMatch
242244
];
243245

244-
ReactDOMServer.renderToString(
246+
renderToStringStrict(
245247
<StaticRouter location="/path/child" context={{}}>
246248
{renderRoutes(routes)}
247249
</StaticRouter>
@@ -268,12 +270,12 @@ describe("renderRoutes", () => {
268270
}
269271
];
270272

271-
ReactDOMServer.renderToString(
273+
renderToStringStrict(
272274
<StaticRouter location="/path/child" context={{}}>
273275
{renderRoutes(routes)}
274276
</StaticRouter>
275277
);
276-
ReactDOMServer.renderToString(
278+
renderToStringStrict(
277279
<StaticRouter location="/" context={{}}>
278280
{renderRoutes(routes)}
279281
</StaticRouter>
@@ -303,12 +305,12 @@ describe("renderRoutes", () => {
303305
}
304306
];
305307

306-
ReactDOMServer.renderToString(
308+
renderToStringStrict(
307309
<StaticRouter location="/path/child/grandchild" context={{}}>
308310
{renderRoutes(routes)}
309311
</StaticRouter>
310312
);
311-
ReactDOMServer.renderToString(
313+
renderToStringStrict(
312314
<StaticRouter location="/path" context={{}}>
313315
{renderRoutes(routes)}
314316
</StaticRouter>
@@ -339,7 +341,7 @@ describe("renderRoutes", () => {
339341
routeToMatch
340342
];
341343

342-
ReactDOMServer.renderToString(
344+
renderToStringStrict(
343345
<StaticRouter location="/path/" context={{}}>
344346
{renderRoutes(routes)}
345347
</StaticRouter>
@@ -366,17 +368,17 @@ describe("renderRoutes", () => {
366368
}
367369
];
368370

369-
ReactDOMServer.renderToString(
371+
renderToStringStrict(
370372
<StaticRouter location="/path/child" context={{}}>
371373
{renderRoutes(routes)}
372374
</StaticRouter>
373375
);
374-
ReactDOMServer.renderToString(
376+
renderToStringStrict(
375377
<StaticRouter location="/" context={{}}>
376378
{renderRoutes(routes)}
377379
</StaticRouter>
378380
);
379-
ReactDOMServer.renderToString(
381+
renderToStringStrict(
380382
<StaticRouter location="/path" context={{}}>
381383
{renderRoutes(routes)}
382384
</StaticRouter>
@@ -418,16 +420,18 @@ describe("renderRoutes", () => {
418420
}
419421
];
420422

421-
ReactDOMServer.renderToString(
423+
renderToStringStrict(
422424
<StaticRouter location="/path/child/grandchild" context={{}}>
423425
{renderRoutes(routes)}
424426
</StaticRouter>
425427
);
426-
ReactDOMServer.renderToString(
428+
429+
renderToStringStrict(
427430
<StaticRouter location="/path/" context={{}}>
428431
{renderRoutes(routes)}
429432
</StaticRouter>
430433
);
434+
431435
expect(renderedRoutes.length).toEqual(2);
432436
expect(renderedRoutes[0]).toEqual(routes[1]);
433437
expect(renderedRoutes[1]).toEqual(routes[1].routes[1]);
@@ -442,11 +446,12 @@ describe("renderRoutes", () => {
442446
}
443447
];
444448

445-
ReactDOMServer.renderToString(
449+
renderToStringStrict(
446450
<StaticRouter location="/path" context={{}}>
447451
{renderRoutes(routes)}
448452
</StaticRouter>
449453
);
454+
450455
expect(renderedRoutes.length).toEqual(1);
451456
expect(renderedRoutes[0]).toEqual(routes[0]);
452457
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from "react";
2+
3+
let StrictMode = function(props) {
4+
return props.children || null;
5+
};
6+
7+
if (React.StrictMode) {
8+
StrictMode = React.StrictMode;
9+
}
10+
11+
export default StrictMode;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from "react";
2+
import ReactDOM from "react-dom";
3+
4+
import StrictMode from "./StrictMode";
5+
6+
function renderStrict(element, node) {
7+
return ReactDOM.render(<StrictMode>{element}</StrictMode>, node);
8+
}
9+
10+
export default renderStrict;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from "react";
2+
import ReactDOMServer from "react-dom/server";
3+
4+
import StrictMode from "./StrictMode";
5+
6+
function renderToStringStrict(element) {
7+
return ReactDOMServer.renderToString(<StrictMode>{element}</StrictMode>);
8+
}
9+
10+
module.exports = renderToStringStrict;

0 commit comments

Comments
 (0)