Skip to content

Commit

Permalink
Run ReactFabric-test.internal.js in xplat variant (#30101)
Browse files Browse the repository at this point in the history
The explicit mock override in this test was causing it to always run as
native-oss instead of also as xplat. This moves the test to use `//
@GATE persistent` instead to run it in all persistent configs.
  • Loading branch information
kassens authored Jun 26, 2024
1 parent ef0f44e commit 7045700
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 145 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ const SEND_ACCESSIBILITY_EVENT_REQUIRES_HOST_COMPONENT =
"sendAccessibilityEvent was called with a ref that isn't a " +
'native component. Use React.forwardRef to get access to the underlying native component';

jest.mock('shared/ReactFeatureFlags', () =>
require('shared/forks/ReactFeatureFlags.native-oss'),
);

describe('ReactFabric', () => {
beforeEach(() => {
jest.resetModules();

// TODO: migrate these tests off of the legacy API
require('shared/ReactFeatureFlags').disableLegacyMode = false;

require('react-native/Libraries/ReactPrivate/InitializeNativeFabricUIManager');

React = require('react');
Expand Down Expand Up @@ -198,9 +197,9 @@ describe('ReactFabric', () => {
).toEqual({
bar: 'b',
});
expect(
nativeFabricUIManager.__dumpHierarchyForJestTestsOnly(),
).toMatchSnapshot();
expect(nativeFabricUIManager.__dumpHierarchyForJestTestsOnly()).toBe(`11
RCTText {"foo":"a","bar":"b"}
RCTRawText {"text":"1"}`);

await act(() => {
ReactFabric.render(
Expand All @@ -220,9 +219,9 @@ describe('ReactFabric', () => {
).toEqual({
foo: 'b',
});
expect(
nativeFabricUIManager.__dumpHierarchyForJestTestsOnly(),
).toMatchSnapshot();
expect(nativeFabricUIManager.__dumpHierarchyForJestTestsOnly()).toBe(`11
RCTText {"foo":"b","bar":"b"}
RCTRawText {"text":"2"}`);
});

it('should not clone nodes without children when updating props', async () => {
Expand Down Expand Up @@ -443,16 +442,54 @@ describe('ReactFabric', () => {
await act(() => {
ReactFabric.render(<Component chars={before} />, 11);
});
expect(
nativeFabricUIManager.__dumpHierarchyForJestTestsOnly(),
).toMatchSnapshot();
expect(nativeFabricUIManager.__dumpHierarchyForJestTestsOnly()).toBe(`11
RCTView null
RCTView {"title":"a"}
RCTView {"title":"b"}
RCTView {"title":"c"}
RCTView {"title":"d"}
RCTView {"title":"e"}
RCTView {"title":"f"}
RCTView {"title":"g"}
RCTView {"title":"h"}
RCTView {"title":"i"}
RCTView {"title":"j"}
RCTView {"title":"k"}
RCTView {"title":"l"}
RCTView {"title":"m"}
RCTView {"title":"n"}
RCTView {"title":"o"}
RCTView {"title":"p"}
RCTView {"title":"q"}
RCTView {"title":"r"}
RCTView {"title":"s"}
RCTView {"title":"t"}`);

await act(() => {
ReactFabric.render(<Component chars={after} />, 11);
});
expect(
nativeFabricUIManager.__dumpHierarchyForJestTestsOnly(),
).toMatchSnapshot();
expect(nativeFabricUIManager.__dumpHierarchyForJestTestsOnly()).toBe(`11
RCTView null
RCTView {"title":"m"}
RCTView {"title":"x"}
RCTView {"title":"h"}
RCTView {"title":"p"}
RCTView {"title":"g"}
RCTView {"title":"w"}
RCTView {"title":"f"}
RCTView {"title":"r"}
RCTView {"title":"a"}
RCTView {"title":"l"}
RCTView {"title":"k"}
RCTView {"title":"e"}
RCTView {"title":"o"}
RCTView {"title":"i"}
RCTView {"title":"v"}
RCTView {"title":"c"}
RCTView {"title":"s"}
RCTView {"title":"t"}
RCTView {"title":"z"}
RCTView {"title":"y"}`);
});

it('recreates host parents even if only children changed', async () => {
Expand Down Expand Up @@ -490,18 +527,60 @@ describe('ReactFabric', () => {
11,
);
});
expect(
nativeFabricUIManager.__dumpHierarchyForJestTestsOnly(),
).toMatchSnapshot();
expect(nativeFabricUIManager.__dumpHierarchyForJestTestsOnly()).toBe(
`11
RCTView null
RCTView null
RCTView {"title":"a"}
RCTView {"title":"b"}
RCTView {"title":"c"}
RCTView {"title":"d"}
RCTView {"title":"e"}
RCTView {"title":"f"}
RCTView {"title":"g"}
RCTView {"title":"h"}
RCTView {"title":"i"}
RCTView {"title":"j"}
RCTView {"title":"k"}
RCTView {"title":"l"}
RCTView {"title":"m"}
RCTView {"title":"n"}
RCTView {"title":"o"}
RCTView {"title":"p"}
RCTView {"title":"q"}
RCTView {"title":"r"}
RCTView {"title":"s"}
RCTView {"title":"t"}`,
);

// Call setState() so that we skip over the top-level host node.
// It should still get recreated despite a bailout.
ref.current.setState({
chars: after,
});
expect(
nativeFabricUIManager.__dumpHierarchyForJestTestsOnly(),
).toMatchSnapshot();
expect(nativeFabricUIManager.__dumpHierarchyForJestTestsOnly()).toBe(`11
RCTView null
RCTView null
RCTView {"title":"m"}
RCTView {"title":"x"}
RCTView {"title":"h"}
RCTView {"title":"p"}
RCTView {"title":"g"}
RCTView {"title":"w"}
RCTView {"title":"f"}
RCTView {"title":"r"}
RCTView {"title":"a"}
RCTView {"title":"l"}
RCTView {"title":"k"}
RCTView {"title":"e"}
RCTView {"title":"o"}
RCTView {"title":"i"}
RCTView {"title":"v"}
RCTView {"title":"c"}
RCTView {"title":"s"}
RCTView {"title":"t"}
RCTView {"title":"z"}
RCTView {"title":"y"}`);
});

it('calls setState with no arguments', async () => {
Expand Down Expand Up @@ -544,7 +623,10 @@ describe('ReactFabric', () => {
22,
);
});
expect(snapshots).toMatchSnapshot();
expect(snapshots).toEqual([
`RCTView {"foo":"a"}
RCTView {"foo":"b"}`,
]);
});

it('should not throw when <View> is used inside of a <Text> ancestor', async () => {
Expand Down

This file was deleted.

0 comments on commit 7045700

Please sign in to comment.