mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Remove RTR from ReactProfiler-test (#28407)
## Summary Internal cleanup of ReactTestRenderer ## How did you test this change? `yarn test packages/react/src/__tests__/ReactProfiler-test.internal.js`
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,137 @@
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @emails react-core
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
let React;
|
||||
let ReactDOMClient;
|
||||
let ReactFeatureFlags;
|
||||
let act;
|
||||
let container;
|
||||
|
||||
function loadModules({
|
||||
enableProfilerTimer = true,
|
||||
enableProfilerCommitHooks = true,
|
||||
enableProfilerNestedUpdatePhase = true,
|
||||
enableProfilerNestedUpdateScheduledHook = false,
|
||||
replayFailedUnitOfWorkWithInvokeGuardedCallback = false,
|
||||
} = {}) {
|
||||
ReactFeatureFlags = require('shared/ReactFeatureFlags');
|
||||
|
||||
ReactFeatureFlags.enableProfilerTimer = enableProfilerTimer;
|
||||
ReactFeatureFlags.enableProfilerCommitHooks = enableProfilerCommitHooks;
|
||||
ReactFeatureFlags.enableProfilerNestedUpdatePhase =
|
||||
enableProfilerNestedUpdatePhase;
|
||||
ReactFeatureFlags.enableProfilerNestedUpdateScheduledHook =
|
||||
enableProfilerNestedUpdateScheduledHook;
|
||||
ReactFeatureFlags.replayFailedUnitOfWorkWithInvokeGuardedCallback =
|
||||
replayFailedUnitOfWorkWithInvokeGuardedCallback;
|
||||
|
||||
React = require('react');
|
||||
ReactDOMClient = require('react-dom/client');
|
||||
const InternalTestUtils = require('internal-test-utils');
|
||||
act = InternalTestUtils.act;
|
||||
}
|
||||
|
||||
describe('Profiler', () => {
|
||||
beforeEach(() => {
|
||||
container = document.createElement('div');
|
||||
});
|
||||
|
||||
describe('works in profiling and non-profiling bundles', () => {
|
||||
[true, false].forEach(enableProfilerTimer => {
|
||||
describe(`enableProfilerTimer:${
|
||||
enableProfilerTimer ? 'enabled' : 'disabled'
|
||||
}`, () => {
|
||||
beforeEach(() => {
|
||||
jest.resetModules();
|
||||
|
||||
loadModules({enableProfilerTimer});
|
||||
});
|
||||
|
||||
// This will throw in production too,
|
||||
// But the test is only interested in verifying the DEV error message.
|
||||
if (__DEV__ && enableProfilerTimer) {
|
||||
it('should warn if required params are missing', async () => {
|
||||
const root = ReactDOMClient.createRoot(container);
|
||||
await expect(async () => {
|
||||
await act(() => {
|
||||
root.render(<React.Profiler />);
|
||||
});
|
||||
}).toErrorDev(
|
||||
'Profiler must specify an "id" of type `string` as a prop. Received the type `undefined` instead.',
|
||||
{
|
||||
withoutStack: true,
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
it('should support an empty Profiler (with no children)', async () => {
|
||||
const root = ReactDOMClient.createRoot(container);
|
||||
// As root
|
||||
await act(() => {
|
||||
root.render(<React.Profiler id="label" onRender={jest.fn()} />);
|
||||
});
|
||||
expect(container.innerHTML).toMatchSnapshot();
|
||||
|
||||
// As non-root
|
||||
await act(() => {
|
||||
root.render(
|
||||
<div>
|
||||
<React.Profiler id="label" onRender={jest.fn()} />
|
||||
</div>,
|
||||
);
|
||||
});
|
||||
expect(container.innerHTML).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('should render children', async () => {
|
||||
const FunctionComponent = ({label}) => <span>{label}</span>;
|
||||
const root = ReactDOMClient.createRoot(container);
|
||||
await act(() => {
|
||||
root.render(
|
||||
<div>
|
||||
<span>outside span</span>
|
||||
<React.Profiler id="label" onRender={jest.fn()}>
|
||||
<span>inside span</span>
|
||||
<FunctionComponent label="function component" />
|
||||
</React.Profiler>
|
||||
</div>,
|
||||
);
|
||||
});
|
||||
expect(container.innerHTML).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('should support nested Profilers', async () => {
|
||||
const FunctionComponent = ({label}) => <div>{label}</div>;
|
||||
class ClassComponent extends React.Component {
|
||||
render() {
|
||||
return <span>{this.props.label}</span>;
|
||||
}
|
||||
}
|
||||
const root = ReactDOMClient.createRoot(container);
|
||||
await act(() => {
|
||||
root.render(
|
||||
<React.Profiler id="outer" onRender={jest.fn()}>
|
||||
<FunctionComponent label="outer function component" />
|
||||
<React.Profiler id="inner" onRender={jest.fn()}>
|
||||
<ClassComponent label="inner class component" />
|
||||
<span>inner span</span>
|
||||
</React.Profiler>
|
||||
</React.Profiler>,
|
||||
);
|
||||
});
|
||||
|
||||
expect(container.innerHTML).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
+8
-56
@@ -1,65 +1,17 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`Profiler works in profiling and non-profiling bundles enableProfilerTimer:disabled should render children 1`] = `
|
||||
<div>
|
||||
<span>
|
||||
outside span
|
||||
</span>
|
||||
<span>
|
||||
inside span
|
||||
</span>
|
||||
<span>
|
||||
function component
|
||||
</span>
|
||||
</div>
|
||||
`;
|
||||
exports[`Profiler works in profiling and non-profiling bundles enableProfilerTimer:disabled should render children 1`] = `"<div><span>outside span</span><span>inside span</span><span>function component</span></div>"`;
|
||||
|
||||
exports[`Profiler works in profiling and non-profiling bundles enableProfilerTimer:disabled should support an empty Profiler (with no children) 1`] = `null`;
|
||||
exports[`Profiler works in profiling and non-profiling bundles enableProfilerTimer:disabled should support an empty Profiler (with no children) 1`] = `""`;
|
||||
|
||||
exports[`Profiler works in profiling and non-profiling bundles enableProfilerTimer:disabled should support an empty Profiler (with no children) 2`] = `<div />`;
|
||||
exports[`Profiler works in profiling and non-profiling bundles enableProfilerTimer:disabled should support an empty Profiler (with no children) 2`] = `"<div></div>"`;
|
||||
|
||||
exports[`Profiler works in profiling and non-profiling bundles enableProfilerTimer:disabled should support nested Profilers 1`] = `
|
||||
[
|
||||
<div>
|
||||
outer function component
|
||||
</div>,
|
||||
<block>
|
||||
inner class component
|
||||
</block>,
|
||||
<span>
|
||||
inner span
|
||||
</span>,
|
||||
]
|
||||
`;
|
||||
exports[`Profiler works in profiling and non-profiling bundles enableProfilerTimer:disabled should support nested Profilers 1`] = `"<div>outer function component</div><span>inner class component</span><span>inner span</span>"`;
|
||||
|
||||
exports[`Profiler works in profiling and non-profiling bundles enableProfilerTimer:enabled should render children 1`] = `
|
||||
<div>
|
||||
<span>
|
||||
outside span
|
||||
</span>
|
||||
<span>
|
||||
inside span
|
||||
</span>
|
||||
<span>
|
||||
function component
|
||||
</span>
|
||||
</div>
|
||||
`;
|
||||
exports[`Profiler works in profiling and non-profiling bundles enableProfilerTimer:enabled should render children 1`] = `"<div><span>outside span</span><span>inside span</span><span>function component</span></div>"`;
|
||||
|
||||
exports[`Profiler works in profiling and non-profiling bundles enableProfilerTimer:enabled should support an empty Profiler (with no children) 1`] = `null`;
|
||||
exports[`Profiler works in profiling and non-profiling bundles enableProfilerTimer:enabled should support an empty Profiler (with no children) 1`] = `""`;
|
||||
|
||||
exports[`Profiler works in profiling and non-profiling bundles enableProfilerTimer:enabled should support an empty Profiler (with no children) 2`] = `<div />`;
|
||||
exports[`Profiler works in profiling and non-profiling bundles enableProfilerTimer:enabled should support an empty Profiler (with no children) 2`] = `"<div></div>"`;
|
||||
|
||||
exports[`Profiler works in profiling and non-profiling bundles enableProfilerTimer:enabled should support nested Profilers 1`] = `
|
||||
[
|
||||
<div>
|
||||
outer function component
|
||||
</div>,
|
||||
<block>
|
||||
inner class component
|
||||
</block>,
|
||||
<span>
|
||||
inner span
|
||||
</span>,
|
||||
]
|
||||
`;
|
||||
exports[`Profiler works in profiling and non-profiling bundles enableProfilerTimer:enabled should support nested Profilers 1`] = `"<div>outer function component</div><span>inner class component</span><span>inner span</span>"`;
|
||||
Reference in New Issue
Block a user