Skip to content

Commit 818a261

Browse files
committed
test
1 parent 172a32d commit 818a261

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @emails react-core
8+
* @jest-environment node
9+
*/
10+
11+
let React;
12+
let ReactNoop;
13+
let Scheduler;
14+
let act;
15+
16+
let useState;
17+
let startTransition;
18+
19+
describe('ReactInteractionTracing', () => {
20+
beforeEach(() => {
21+
jest.resetModules();
22+
23+
React = require('react');
24+
ReactNoop = require('react-noop-renderer');
25+
Scheduler = require('scheduler');
26+
27+
act = require('jest-react').act;
28+
29+
useState = React.useState;
30+
startTransition = React.startTransition;
31+
});
32+
33+
function Text({text}) {
34+
Scheduler.unstable_yieldValue(text);
35+
return text;
36+
}
37+
38+
function advanceTimers(ms) {
39+
// Note: This advances Jest's virtual time but not React's. Use
40+
// ReactNoop.expire for that.
41+
if (typeof ms !== 'number') {
42+
throw new Error('Must specify ms');
43+
}
44+
jest.advanceTimersByTime(ms);
45+
// Wait until the end of the current tick
46+
// We cannot use a timer since we're faking them
47+
return Promise.resolve().then(() => {});
48+
}
49+
50+
// @gate enableTransitionTracing
51+
it('should correctly trace basic interaction', async () => {
52+
const transitionCallbacks = {
53+
onTransitionStart: (name, startTime) => {
54+
Scheduler.unstable_yieldValue(
55+
`onTransitionStart(${name}, ${startTime})`,
56+
);
57+
},
58+
onTransitionComplete: (name, startTime, endTime) => {
59+
Scheduler.unstable_yieldValue(
60+
`onTransitionComplete(${name}, ${startTime}, ${endTime})`,
61+
);
62+
},
63+
};
64+
65+
let navigateToPageTwo;
66+
function App() {
67+
const [navigate, setNavigate] = useState(false);
68+
navigateToPageTwo = () => {
69+
setNavigate(true);
70+
};
71+
72+
return (
73+
<div>
74+
{navigate ? <Text text="Page Two" /> : <Text text="Page One" />}
75+
</div>
76+
);
77+
}
78+
79+
const root = ReactNoop.createRoot({transitionCallbacks});
80+
await act(async () => {
81+
root.render(<App />);
82+
ReactNoop.expire(1000);
83+
await advanceTimers(1000);
84+
85+
expect(Scheduler).toFlushAndYield(['Page One']);
86+
87+
await act(async () => {
88+
startTransition(() => navigateToPageTwo(), {name: 'page transition'});
89+
90+
ReactNoop.expire(1000);
91+
await advanceTimers(1000);
92+
93+
expect(Scheduler).toFlushAndYield([
94+
'Page Two',
95+
'onTransitionStart(page transition, 1000)',
96+
'onTransitionComplete(page transition, 1000, 2000)',
97+
]);
98+
});
99+
});
100+
});
101+
});

packages/shared/forks/ReactFeatureFlags.www-dynamic.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export const consoleManagedByDevToolsDuringStrictMode = __VARIANT__;
2828
export const warnOnSubscriptionInsideStartTransition = __VARIANT__;
2929
export const enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay = __VARIANT__;
3030
export const enableClientRenderFallbackOnHydrationMismatch = __VARIANT__;
31+
export const enableTransitionTracing = __VARIANT__;
3132

3233
// Enable this flag to help with concurrent mode debugging.
3334
// It logs information to the console about React scheduling, rendering, and commit phases.

0 commit comments

Comments
 (0)