Skip to content

Commit d460302

Browse files
sammy-SCfacebook-github-bot
authored andcommitted
Add Fantom integration test for FabricUIManager
Summary: Converts the Jest tests for getFabricUIManager() to Fantom integration tests using the real native Fabric runtime. Tests that rely on jest.resetModules() to simulate an uninitialized environment are omitted, as Fantom always provides a fully initialized runtime. Changelog: [Internal] Differential Revision: D94887591
1 parent 5a2aac7 commit d460302

2 files changed

Lines changed: 70 additions & 67 deletions

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and 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+
* @flow strict-local
8+
* @format
9+
*/
10+
11+
import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
12+
13+
import {getFabricUIManager} from '../FabricUIManager';
14+
15+
// NOTE: The test that verifies getFabricUIManager() returns undefined when
16+
// global.nativeFabricUIManager is not set cannot be converted to a Fantom
17+
// integration test. That test relies on jest.resetModules() to clear the
18+
// module-level singleton (nativeFabricUIManagerProxy). In the Fantom
19+
// environment, global.nativeFabricUIManager is always set up by the runtime,
20+
// and there is no module reset mechanism available. That test exercises a code
21+
// path (getFabricUIManager returning undefined) that is not reachable in a
22+
// fully-initialized Fantom environment.
23+
24+
describe('getFabricUIManager', () => {
25+
it('should return an object when the global binding is set in the Fantom environment', () => {
26+
// In the Fantom environment, global.nativeFabricUIManager is always set by
27+
// the native runtime, so getFabricUIManager() must return a non-null object.
28+
const fabricUIManager = getFabricUIManager();
29+
expect(fabricUIManager).not.toBeNull();
30+
expect(fabricUIManager).not.toBeUndefined();
31+
expect(typeof fabricUIManager).toBe('object');
32+
});
33+
34+
it('should return the same object on subsequent calls', () => {
35+
// getFabricUIManager() caches the proxy object in a module-level variable.
36+
// Subsequent calls should return the same reference.
37+
const first = getFabricUIManager();
38+
const second = getFabricUIManager();
39+
expect(first).toBe(second);
40+
});
41+
42+
it('should cache the createNode property so the same reference is returned each time', () => {
43+
// The proxy created by getFabricUIManager() uses defineLazyObjectProperty
44+
// to cache properties from the underlying global binding. Accessing the
45+
// same property twice should return the same reference even if the
46+
// underlying binding produces a new host function on each access.
47+
const fabricUIManager = getFabricUIManager();
48+
expect(fabricUIManager).not.toBeNull();
49+
expect(fabricUIManager).not.toBeUndefined();
50+
51+
if (fabricUIManager != null) {
52+
const firstCreateNode = fabricUIManager.createNode;
53+
const secondCreateNode = fabricUIManager.createNode;
54+
expect(firstCreateNode).toBe(secondCreateNode);
55+
}
56+
});
57+
58+
it('should expose the createNode method', () => {
59+
// Verify that the returned proxy exposes createNode as a function.
60+
// createNode is one of the CACHED_PROPERTIES in FabricUIManager.js and
61+
// is provided by the Fantom native runtime.
62+
const fabricUIManager = getFabricUIManager();
63+
expect(fabricUIManager).not.toBeNull();
64+
expect(fabricUIManager).not.toBeUndefined();
65+
66+
if (fabricUIManager != null) {
67+
expect(typeof fabricUIManager.createNode).toBe('function');
68+
}
69+
});
70+
});

packages/react-native/Libraries/ReactNative/__tests__/FabricUIManager-test.js

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)