@samitouri / QOS-React / commits / b9ddd206f9

Fiber SSR tests (#9846)

Edvin Erikson committed Jun 5, 2017 at 00:44 UTC b9ddd206f95af4a42265874b73f3e31b97ab0fe6
4 files changed +146 -59
scripts/fiber/tests-passing.txt
+3
@@ -1327,6 +1327,9 @@ src/renderers/dom/shared/__tests__/ReactServerRendering-test.js
1327 * should only execute certain lifecycle methods
1328 * should throw with silly args
1329 * allows setState in componentWillMount without using DOM
1330 +* allows setState in componentWillMount with custom constructor
1331 +* renders with props when using custom constructor
1332 +* renders with context when using custom constructor
1333 * renders components with different batching strategies
1334 * warns with a no-op when an async setState is triggered
1335 * warns with a no-op when an async forceUpdate is triggered
scripts/rollup/results.json
+58 -58
@@ -9,28 +9,28 @@
9 "gzip": 3089
10 },
11 "react-dom.development.js (UMD_DEV)": {
12 - "size": 605435,
13 - "gzip": 139358
12 + "size": 603820,
13 + "gzip": 138900
14 },
15 "react-dom.production.min.js (UMD_PROD)": {
16 - "size": 125246,
17 - "gzip": 39624
16 + "size": 124927,
17 + "gzip": 39493
18 },
19 "react-dom-server.development.js (UMD_DEV)": {
20 - "size": 534438,
21 - "gzip": 129160
20 + "size": 532325,
21 + "gzip": 128572
22 },
23 "react-dom-server.production.min.js (UMD_PROD)": {
24 - "size": 113386,
25 - "gzip": 35642
24 + "size": 112876,
25 + "gzip": 35439
26 },
27 "react-art.development.js (UMD_DEV)": {
28 - "size": 359125,
29 - "gzip": 79859
28 + "size": 358834,
29 + "gzip": 79713
30 },
31 "react-art.production.min.js (UMD_PROD)": {
32 - "size": 98612,
33 - "gzip": 29993
32 + "size": 98607,
33 + "gzip": 29968
34 },
35 "react.development.js (NODE_DEV)": {
36 "size": 64064,
@@ -57,36 +57,36 @@
57 "gzip": 86700
58 },
59 "react-dom.development.js (NODE_DEV)": {
60 - "size": 563003,
61 - "gzip": 129288
60 + "size": 562438,
61 + "gzip": 129053
62 },
63 "react-dom.production.min.js (NODE_PROD)": {
64 - "size": 121459,
65 - "gzip": 38279
64 + "size": 121292,
65 + "gzip": 38189
66 },
67 "ReactDOMFiber-dev.js (FB_DEV)": {
68 - "size": 563992,
69 - "gzip": 129811
68 + "size": 563608,
69 + "gzip": 129673
70 },
71 "ReactDOMFiber-prod.js (FB_PROD)": {
72 - "size": 423415,
73 - "gzip": 96616
72 + "size": 423197,
73 + "gzip": 96509
74 },
75 "react-dom-server.development.js (NODE_DEV)": {
76 - "size": 482987,
77 - "gzip": 116600
76 + "size": 481924,
77 + "gzip": 116242
78 },
79 "react-dom-server.production.min.js (NODE_PROD)": {
80 - "size": 107761,
81 - "gzip": 33495
80 + "size": 107403,
81 + "gzip": 33347
82 },
83 "ReactDOMServerStack-dev.js (FB_DEV)": {
84 - "size": 464469,
85 - "gzip": 112326
84 + "size": 463581,
85 + "gzip": 112069
86 },
87 "ReactDOMServerStack-prod.js (FB_PROD)": {
88 - "size": 341137,
89 - "gzip": 82395
88 + "size": 340301,
89 + "gzip": 82162
90 },
91 "ReactARTStack-dev.js (FB_DEV)": {
92 "size": 143177,
@@ -97,20 +97,20 @@
97 "gzip": 23049
98 },
99 "react-art.development.js (NODE_DEV)": {
100 - "size": 280466,
101 - "gzip": 59782
100 + "size": 280175,
101 + "gzip": 59621
102 },
103 "react-art.production.min.js (NODE_PROD)": {
104 - "size": 59997,
105 - "gzip": 18059
104 + "size": 59992,
105 + "gzip": 18043
106 },
107 "ReactARTFiber-dev.js (FB_DEV)": {
108 - "size": 279735,
109 - "gzip": 59621
108 + "size": 279625,
109 + "gzip": 59561
110 },
111 "ReactARTFiber-prod.js (FB_PROD)": {
112 - "size": 217307,
113 - "gzip": 45335
112 + "size": 217340,
113 + "gzip": 45300
114 },
115 "ReactNativeStack.js (RN)": {
116 "size": 233993,
@@ -121,20 +121,20 @@
121 "gzip": 84001
122 },
123 "ReactTestRendererFiber-dev.js (FB_DEV)": {
124 - "size": 277216,
125 - "gzip": 58480
124 + "size": 277109,
125 + "gzip": 58420
126 },
127 "ReactTestRendererStack-dev.js (FB_DEV)": {
128 - "size": 151781,
129 - "gzip": 34856
128 + "size": 151247,
129 + "gzip": 34719
130 },
131 "react-noop-renderer.development.js (NODE_DEV)": {
132 - "size": 269122,
133 - "gzip": 56410
132 + "size": 268831,
133 + "gzip": 56248
134 },
135 "react-test-renderer.development.js (NODE_DEV)": {
136 - "size": 277956,
137 - "gzip": 58660
136 + "size": 277668,
137 + "gzip": 58491
138 },
139 "react-dom-test-utils.development.js (NODE_DEV)": {
140 "size": 52792,
@@ -145,8 +145,8 @@
145 "gzip": 13574
146 },
147 "react-test-renderer-stack.development.js (NODE_DEV)": {
148 - "size": 152686,
149 - "gzip": 35015
148 + "size": 151979,
149 + "gzip": 34761
150 },
151 "react-test-renderer-shallow.development.js (NODE_DEV)": {
152 "size": 8108,
@@ -157,28 +157,28 @@
157 "gzip": 2234
158 },
159 "ReactDOMServerStream-dev.js (FB_DEV)": {
160 - "size": 481456,
161 - "gzip": 116430
160 + "size": 480568,
161 + "gzip": 116171
162 },
163 "ReactDOMServerStream-prod.js (FB_PROD)": {
164 - "size": 352294,
165 - "gzip": 85249
164 + "size": 351458,
165 + "gzip": 85017
166 },
167 "ReactNativeStack-dev.js (RN_DEV)": {
168 - "size": 182421,
169 - "gzip": 35496
168 + "size": 186098,
169 + "gzip": 35885
170 },
171 "ReactNativeStack-prod.js (RN_PROD)": {
172 - "size": 134188,
173 - "gzip": 25741
172 + "size": 137881,
173 + "gzip": 26310
174 },
175 "ReactNativeFiber-dev.js (RN_DEV)": {
176 - "size": 278278,
177 - "gzip": 50225
176 + "size": 282183,
177 + "gzip": 50630
178 },
179 "ReactNativeFiber-prod.js (RN_PROD)": {
180 - "size": 216205,
181 - "gzip": 37384
180 + "size": 220295,
181 + "gzip": 37795
182 }
183 }
184 }
\ No newline at end of file
src/renderers/dom/shared/__tests__/ReactServerRendering-test.js
+81 -1
@@ -19,6 +19,7 @@ var ReactDOMServer;
19 var ReactMarkupChecksum;
20 var ReactReconcileTransaction;
21 var ReactTestUtils;
22 +var PropTypes;
23
24 var ID_ATTRIBUTE_NAME;
25 var ROOT_ATTRIBUTE_NAME;
@@ -32,6 +33,7 @@ describe('ReactDOMServer', () => {
33 ReactMarkupChecksum = require('ReactMarkupChecksum');
34 ReactTestUtils = require('ReactTestUtils');
35 ReactReconcileTransaction = require('ReactReconcileTransaction');
36 + PropTypes = require('prop-types');
37
38 ExecutionEnvironment = require('fbjs/lib/ExecutionEnvironment');
39 ExecutionEnvironment.canUseDOM = false;
@@ -424,7 +426,85 @@ describe('ReactDOMServer', () => {
426 throw new Error('Browser reconcile transaction should not be used');
427 };
428 var markup = ReactDOMServer.renderToString(<Component />);
427 - expect(markup.indexOf('hello, world') >= 0).toBe(true);
429 + expect(markup).toContain('hello, world');
430 + });
431 +
432 + it('allows setState in componentWillMount with custom constructor', () => {
433 + class Component extends React.Component {
434 + constructor() {
435 + super();
436 + this.state = {text: 'default state'};
437 + }
438 +
439 + componentWillMount() {
440 + this.setState({text: 'hello, world'});
441 + }
442 +
443 + render() {
444 + return <div>{this.state.text}</div>;
445 + }
446 + }
447 +
448 + ReactReconcileTransaction.prototype.perform = function() {
449 + // We shouldn't ever be calling this on the server
450 + throw new Error('Browser reconcile transaction should not be used');
451 + };
452 + var markup = ReactDOMServer.renderToString(<Component />);
453 + expect(markup).toContain('hello, world');
454 + });
455 +
456 + it('renders with props when using custom constructor', () => {
457 + class Component extends React.Component {
458 + constructor() {
459 + super();
460 + }
461 +
462 + render() {
463 + return <div>{this.props.text}</div>;
464 + }
465 + }
466 +
467 + var markup = ReactDOMServer.renderToString(
468 + <Component text="hello, world" />,
469 + );
470 + expect(markup).toContain('hello, world');
471 + });
472 +
473 + it('renders with context when using custom constructor', () => {
474 + class Component extends React.Component {
475 + constructor() {
476 + super();
477 + }
478 +
479 + render() {
480 + return <div>{this.context.text}</div>;
481 + }
482 + }
483 +
484 + Component.contextTypes = {
485 + text: PropTypes.string.isRequired,
486 + };
487 +
488 + class ContextProvider extends React.Component {
489 + getChildContext() {
490 + return {
491 + text: 'hello, world',
492 + };
493 + }
494 +
495 + render() {
496 + return this.props.children;
497 + }
498 + }
499 +
500 + ContextProvider.childContextTypes = {
501 + text: PropTypes.string,
502 + };
503 +
504 + var markup = ReactDOMServer.renderToString(
505 + <ContextProvider><Component /></ContextProvider>,
506 + );
507 + expect(markup).toContain('hello, world');
508 });
509
510 it('renders components with different batching strategies', () => {
src/renderers/shared/server/ReactServerRenderer.js
+4
@@ -278,6 +278,10 @@ function resolve(child, context) {
278 }
279 }
280
281 + inst.props = child.props;
282 + inst.context = publicContext;
283 + inst.updater = updater;
284 +
285 var initialState = inst.state;
286 if (initialState === undefined) {
287 inst.state = initialState = null;