Skip to content

Commit 8c191e8

Browse files
author
Brian Vaughn
committed
Add gates to tests affected by new semantics
1 parent e9624da commit 8c191e8

File tree

3 files changed

+95
-30
lines changed

3 files changed

+95
-30
lines changed

packages/react-reconciler/src/__tests__/ReactLazy-test.internal.js

+26-6
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,9 @@ describe('ReactLazy', () => {
12711271
// @gate enableLazyElements
12721272
it('mount and reorder lazy types', async () => {
12731273
class Child extends React.Component {
1274+
componentWillUnmount() {
1275+
Scheduler.unstable_yieldValue('Did unmount: ' + this.props.label);
1276+
}
12741277
componentDidMount() {
12751278
Scheduler.unstable_yieldValue('Did mount: ' + this.props.label);
12761279
}
@@ -1348,6 +1351,12 @@ describe('ReactLazy', () => {
13481351
expect(Scheduler).toFlushAndYield(['Init B2', 'Loading...']);
13491352
jest.runAllTimers();
13501353

1354+
gate(flags => {
1355+
if (flags.enableSuspenseLayoutEffectSemantics) {
1356+
expect(Scheduler).toHaveYielded(['Did unmount: A', 'Did unmount: B']);
1357+
}
1358+
});
1359+
13511360
// The suspense boundary should've triggered now.
13521361
expect(root).toMatchRenderedOutput('Loading...');
13531362
await resolveB2({default: ChildB});
@@ -1356,12 +1365,23 @@ describe('ReactLazy', () => {
13561365
expect(Scheduler).toFlushAndYield(['Init A2']);
13571366
await LazyChildA2;
13581367

1359-
expect(Scheduler).toFlushAndYield([
1360-
'b',
1361-
'a',
1362-
'Did update: b',
1363-
'Did update: a',
1364-
]);
1368+
gate(flags => {
1369+
if (flags.enableSuspenseLayoutEffectSemantics) {
1370+
expect(Scheduler).toFlushAndYield([
1371+
'b',
1372+
'a',
1373+
'Did mount: b',
1374+
'Did mount: a',
1375+
]);
1376+
} else {
1377+
expect(Scheduler).toFlushAndYield([
1378+
'b',
1379+
'a',
1380+
'Did update: b',
1381+
'Did update: a',
1382+
]);
1383+
}
1384+
});
13651385
expect(root).toMatchRenderedOutput('ba');
13661386
});
13671387

packages/react-reconciler/src/__tests__/ReactSuspenseFuzz-test.internal.js

+48-14
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ describe('ReactSuspenseFuzz', () => {
100100
}
101101
}, [updates]);
102102

103-
const fullText = `${text}:${step}`;
103+
const fullText = `[${text}:${step}]`;
104104

105105
const shouldSuspend = useContext(ShouldSuspendContext);
106106

@@ -163,19 +163,26 @@ describe('ReactSuspenseFuzz', () => {
163163
resolveAllTasks();
164164
const expectedOutput = expectedRoot.getChildrenAsJSX();
165165

166-
resetCache();
167-
ReactNoop.renderLegacySyncRoot(children);
168-
resolveAllTasks();
169-
const legacyOutput = ReactNoop.getChildrenAsJSX();
170-
expect(legacyOutput).toEqual(expectedOutput);
171-
ReactNoop.renderLegacySyncRoot(null);
172-
173-
resetCache();
174-
const concurrentRoot = ReactNoop.createRoot();
175-
concurrentRoot.render(children);
176-
resolveAllTasks();
177-
const concurrentOutput = concurrentRoot.getChildrenAsJSX();
178-
expect(concurrentOutput).toEqual(expectedOutput);
166+
gate(flags => {
167+
resetCache();
168+
ReactNoop.renderLegacySyncRoot(children);
169+
resolveAllTasks();
170+
const legacyOutput = ReactNoop.getChildrenAsJSX();
171+
expect(legacyOutput).toEqual(expectedOutput);
172+
ReactNoop.renderLegacySyncRoot(null);
173+
174+
// Observable behavior differs here in a way that's expected:
175+
// If enableSuspenseLayoutEffectSemantics is enabled, layout effects are destroyed on re-suspend
176+
// before larger 'beginAfter' timers have a chance to fire.
177+
if (!flags.enableSuspenseLayoutEffectSemantics) {
178+
resetCache();
179+
const concurrentRoot = ReactNoop.createRoot();
180+
concurrentRoot.render(children);
181+
resolveAllTasks();
182+
const concurrentOutput = concurrentRoot.getChildrenAsJSX();
183+
expect(concurrentOutput).toEqual(expectedOutput);
184+
}
185+
});
179186
}
180187

181188
function pickRandomWeighted(rand, options) {
@@ -410,5 +417,32 @@ Random seed is ${SEED}
410417
</>,
411418
);
412419
});
420+
421+
it('4', () => {
422+
const {Text, testResolvedOutput} = createFuzzer();
423+
testResolvedOutput(
424+
<React.Suspense fallback="Loading...">
425+
<React.Suspense>
426+
<React.Suspense>
427+
<Text initialDelay={9683} text="E" updates={[]} />
428+
</React.Suspense>
429+
<Text
430+
initialDelay={4053}
431+
text="C"
432+
updates={[
433+
{
434+
beginAfter: 1566,
435+
suspendFor: 4142,
436+
},
437+
{
438+
beginAfter: 9572,
439+
suspendFor: 4832,
440+
},
441+
]}
442+
/>
443+
</React.Suspense>
444+
</React.Suspense>,
445+
);
446+
});
413447
});
414448
});

packages/react-reconciler/src/__tests__/ReactSuspenseWithNoopRenderer-test.js

+21-10
Original file line numberDiff line numberDiff line change
@@ -468,19 +468,30 @@ describe('ReactSuspenseWithNoopRenderer', () => {
468468

469469
await rejectText('Result', new Error('Failed to load: Result'));
470470

471-
expect(Scheduler).toFlushAndYield([
472-
'Error! [Result]',
471+
gate(flags => {
472+
if (flags.enableSuspenseLayoutEffectSemantics) {
473+
expect(Scheduler).toFlushAndYield([
474+
'Error! [Result]',
473475

474-
// React retries one more time
475-
'Error! [Result]',
476+
// React retries one more time
477+
'Error! [Result]',
478+
]);
479+
expect(ReactNoop.getChildren()).toEqual([]);
480+
} else {
481+
expect(Scheduler).toFlushAndYield([
482+
'Error! [Result]',
476483

477-
// Errored again on retry. Now handle it.
484+
// React retries one more time
485+
'Error! [Result]',
478486

479-
'Caught error: Failed to load: Result',
480-
]);
481-
expect(ReactNoop.getChildren()).toEqual([
482-
span('Caught error: Failed to load: Result'),
483-
]);
487+
// Errored again on retry. Now handle it.
488+
'Caught error: Failed to load: Result',
489+
]);
490+
expect(ReactNoop.getChildren()).toEqual([
491+
span('Caught error: Failed to load: Result'),
492+
]);
493+
}
494+
});
484495
});
485496

486497
// @gate enableCache

0 commit comments

Comments
 (0)