Skip to content

Commit bfe31ba

Browse files
rubennortefacebook-github-bot
authored andcommitted
Small refactor of how Fantom configs are formatted (facebook#52826)
Summary: Pull Request resolved: facebook#52826 Changelog: [internal] This is just an intermediate change to simplify how we format Fantom configs, so we can extend it to use other formatting formats (e.g.: short format to use in file names). Reviewed By: lenaic Differential Revision: D78924771 fbshipit-source-id: 4886a800a6836dc6a66539b1df079adb6c9c52e1
1 parent 0f7ba79 commit bfe31ba

File tree

2 files changed

+48
-13
lines changed

2 files changed

+48
-13
lines changed

private/react-native-fantom/runner/formatFantomConfig.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@ import type {FantomTestConfig} from '../runner/getFantomTestConfigs';
1313
import type {HermesVariant} from '../runner/utils';
1414

1515
import {
16-
DEFAULT_FEATURE_FLAGS,
17-
DEFAULT_HERMES_VARIANT,
18-
DEFAULT_MODE,
1916
FantomTestConfigHermesVariant,
2017
FantomTestConfigMode,
2118
} from '../runner/getFantomTestConfigs';
19+
import {getOverrides} from './getFantomTestConfigs';
2220

2321
function formatFantomMode(mode: FantomTestConfigMode): string {
2422
switch (mode) {
@@ -56,22 +54,25 @@ function formatFantomFeatureFlag(
5654
}
5755

5856
export default function formatFantomConfig(config: FantomTestConfig): string {
57+
const overrides = getOverrides(config);
5958
const parts = [];
6059

61-
if (config.mode !== DEFAULT_MODE) {
62-
parts.push(formatFantomMode(config.mode));
60+
if (overrides.mode) {
61+
parts.push(formatFantomMode(overrides.mode));
6362
}
6463

65-
if (config.hermesVariant !== DEFAULT_HERMES_VARIANT) {
66-
parts.push(formatFantomHermesVariant(config.hermesVariant));
64+
if (overrides.hermesVariant) {
65+
parts.push(formatFantomHermesVariant(overrides.hermesVariant));
6766
}
6867

69-
for (const flagType of ['common', 'jsOnly', 'reactInternal'] as const) {
70-
for (const [flagName, flagValue] of Object.entries(
71-
config.flags[flagType],
72-
)) {
73-
if (flagValue !== DEFAULT_FEATURE_FLAGS[flagType][flagName]) {
74-
parts.push(formatFantomFeatureFlag(flagName, flagValue));
68+
if (overrides.flags) {
69+
for (const flagType of ['common', 'jsOnly', 'reactInternal'] as const) {
70+
if (overrides.flags[flagType]) {
71+
for (const [flagName, flagValue] of Object.entries(
72+
overrides.flags[flagType],
73+
)) {
74+
parts.push(formatFantomFeatureFlag(flagName, flagValue));
75+
}
7576
}
7677
}
7778
}

private/react-native-fantom/runner/getFantomTestConfigs.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,40 @@ const VALID_FANTOM_PRAGMAS = [
8989
'fantom_react_fb_flags',
9090
];
9191

92+
export function getOverrides(
93+
config: FantomTestConfig,
94+
): PartialFantomTestConfig {
95+
const overrides: PartialFantomTestConfig = {};
96+
97+
if (config.mode !== DEFAULT_MODE) {
98+
overrides.mode = config.mode;
99+
}
100+
101+
if (config.hermesVariant !== DEFAULT_HERMES_VARIANT) {
102+
overrides.hermesVariant = config.hermesVariant;
103+
}
104+
105+
const flags: FantomTestConfigFeatureFlags = {
106+
common: {},
107+
jsOnly: {},
108+
reactInternal: {},
109+
};
110+
111+
for (const flagType of ['common', 'jsOnly', 'reactInternal'] as const) {
112+
for (const [flagName, flagValue] of Object.entries(
113+
config.flags[flagType],
114+
)) {
115+
if (flagValue !== DEFAULT_FEATURE_FLAGS[flagType][flagName]) {
116+
flags[flagType][flagName] = flagValue;
117+
}
118+
}
119+
}
120+
121+
overrides.flags = {...flags};
122+
123+
return overrides;
124+
}
125+
92126
/**
93127
* Extracts the Fantom configurations from the test file, specified as part of
94128
* the docblock comment. E.g.:

0 commit comments

Comments
 (0)