Skip to content

Commit b57f65e

Browse files
rubennortemeta-codesync[bot]
authored andcommitted
Migrate StyleSheet pure-logic Jest tests to Fantom (#57260)
Summary: Pull Request resolved: #57260 Migrates the pure-logic StyleSheet unit tests from regular Jest (`-test.js`) to Fantom (`-itest.js`), so they run on Hermes inside the real React Native runtime, the same engine that runs this code in production. Migrated files (all style-processing utilities that run on the client at runtime): `flattenStyle`, `processAspectRatio`, `processBackgroundPosition`, `processBackgroundRepeat`, `processBackgroundSize`, `processFilter`, `processFontVariant`, `processTransform`, `processTransformOrigin`, `setNormalizedColorAlpha`, `splitLayoutProps`. Notable adaptations: - `toThrowErrorMatchingSnapshot()` and `toThrowErrorMatchingInlineSnapshot()` are not available in Fantom, so they were replaced with `toThrow('<exact message>')`, preserving the exact error messages that were previously captured in snapshots. - Removed the now-obsolete file snapshots for `processAspectRatio`, `processTransform`, and `processTransformOrigin`. - `toMatchInlineSnapshot` (used by `splitLayoutProps`) is supported by Fantom and was kept unchanged. Changelog: [Internal] Reviewed By: sammy-SC Differential Revision: D108759084 fbshipit-source-id: 42085f6f09286022655ea71b6a8e430cadf647a7
1 parent 65bdf26 commit b57f65e

15 files changed

Lines changed: 188 additions & 250 deletions

packages/react-native/Libraries/StyleSheet/__tests__/__snapshots__/processAspectRatio-test.js.snap

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

packages/react-native/Libraries/StyleSheet/__tests__/__snapshots__/processTransform-test.js.snap

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

packages/react-native/Libraries/StyleSheet/__tests__/__snapshots__/processTransformOrigin-test.js.snap

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

packages/react-native/Libraries/StyleSheet/__tests__/flattenStyle-test.js renamed to packages/react-native/Libraries/StyleSheet/__tests__/flattenStyle-itest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @format
99
*/
1010

11-
'use strict';
11+
import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
1212

1313
const flattenStyle = require('../flattenStyle').default;
1414
const StyleSheet = require('../StyleSheet').default;

packages/react-native/Libraries/StyleSheet/__tests__/processAspectRatio-test.js renamed to packages/react-native/Libraries/StyleSheet/__tests__/processAspectRatio-itest.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* @format
99
*/
1010

11+
import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
1112
import processAspectRatio from '../processAspectRatio';
1213

1314
describe('processAspectRatio', () => {
@@ -41,9 +42,15 @@ describe('processAspectRatio', () => {
4142
});
4243

4344
it('should not accept invalid formats', () => {
44-
expect(() => processAspectRatio('0a')).toThrowErrorMatchingSnapshot();
45-
expect(() => processAspectRatio('1 / 1 1')).toThrowErrorMatchingSnapshot();
46-
expect(() => processAspectRatio('auto 1/1')).toThrowErrorMatchingSnapshot();
45+
expect(() => processAspectRatio('0a')).toThrow(
46+
'aspectRatio must either be a number, a ratio string or `auto`. You passed: 0a',
47+
);
48+
expect(() => processAspectRatio('1 / 1 1')).toThrow(
49+
'aspectRatio must either be a number, a ratio string or `auto`. You passed: 1 / 1 1',
50+
);
51+
expect(() => processAspectRatio('auto 1/1')).toThrow(
52+
'aspectRatio must either be a number, a ratio string or `auto`. You passed: auto 1/1',
53+
);
4754
});
4855

4956
it('should ignore non string falsy types', () => {
@@ -57,8 +64,12 @@ describe('processAspectRatio', () => {
5764
it('should not accept non string truthy types', () => {
5865
const invalidThings = [() => {}, [1, 2, 3], {}];
5966
for (const thing of invalidThings) {
60-
// $FlowExpectedError[incompatible-type]
61-
expect(() => processAspectRatio(thing)).toThrowErrorMatchingSnapshot();
67+
expect(() =>
68+
// $FlowExpectedError[incompatible-type]
69+
processAspectRatio(thing),
70+
).toThrow(
71+
`aspectRatio must either be a number, a ratio string or \`auto\`. You passed: ${String(thing)}`,
72+
);
6273
}
6374
});
6475
});

packages/react-native/Libraries/StyleSheet/__tests__/processBackgroundPosition-test.js renamed to packages/react-native/Libraries/StyleSheet/__tests__/processBackgroundPosition-itest.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
* @format
99
*/
1010

11-
'use strict';
12-
11+
import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
1312
import processBackgroundPosition from '../processBackgroundPosition';
1413

1514
describe('processBackgroundPosition', () => {

packages/react-native/Libraries/StyleSheet/__tests__/processBackgroundRepeat-test.js renamed to packages/react-native/Libraries/StyleSheet/__tests__/processBackgroundRepeat-itest.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
* @format
99
*/
1010

11-
'use strict';
12-
11+
import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
1312
import processBackgroundRepeat from '../processBackgroundRepeat';
1413

1514
describe('processBackgroundRepeat', () => {

packages/react-native/Libraries/StyleSheet/__tests__/processBackgroundSize-test.js renamed to packages/react-native/Libraries/StyleSheet/__tests__/processBackgroundSize-itest.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
* @format
99
*/
1010

11-
'use strict';
12-
11+
import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
1312
import processBackgroundSize from '../processBackgroundSize';
1413

1514
describe('processBackgroundSize', () => {

packages/react-native/Libraries/StyleSheet/__tests__/processFilter-test.js renamed to packages/react-native/Libraries/StyleSheet/__tests__/processFilter-itest.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
'use strict';
1212

13+
import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
14+
1315
import type {FilterFunction} from '../StyleSheetTypes';
1416

1517
import processColor from '../processColor';

packages/react-native/Libraries/StyleSheet/__tests__/processFontVariant-test.js renamed to packages/react-native/Libraries/StyleSheet/__tests__/processFontVariant-itest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @format
99
*/
1010

11-
'use strict';
11+
import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
1212

1313
const processFontVariant = require('../processFontVariant').default;
1414

0 commit comments

Comments
 (0)