Skip to content

Commit 527e308

Browse files
rubennortefacebook-github-bot
authored andcommitted
Add private function in feature flags to reset internal JS state for testing (#53056)
Summary: Pull Request resolved: #53056 Changelog: [internal] This exposes a utility method in `ReactNativeFeatureFlagsBase` to reset its internal state for testing purposes. This is intentionally not exposed through `ReactNativeFeatureFlags` to avoid it being used at runtime. Reviewed By: rshest Differential Revision: D79639889 fbshipit-source-id: adfb6125d991994c9706d5952d309915fec8f815
1 parent 1f9667e commit 527e308

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

packages/react-native/src/private/featureflags/ReactNativeFeatureFlagsBase.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ import NativeReactNativeFeatureFlags from './specs/NativeReactNativeFeatureFlags
1818
const accessedFeatureFlags: Set<string> = new Set();
1919
let overrides: ?ReactNativeFeatureFlagsJsOnlyOverrides;
2020

21+
// This is a list of functions to clear the cached value for each feature flag
22+
// getter. This is only used in development.
23+
const clearCachedValuesFns: Array<() => void> = [];
24+
2125
export type Getter<T> = () => T;
2226

2327
// This defines the types for the overrides object, whose methods also receive
@@ -33,6 +37,12 @@ function createGetter<T: boolean | number | string>(
3337
): Getter<T> {
3438
let cachedValue: ?T;
3539

40+
if (__DEV__) {
41+
clearCachedValuesFns.push(() => {
42+
cachedValue = undefined;
43+
});
44+
}
45+
3646
return () => {
3747
if (cachedValue == null) {
3848
cachedValue = customValueGetter() ?? defaultValue;
@@ -115,3 +125,12 @@ function maybeLogUnavailableNativeModuleError(configName: string): void {
115125
);
116126
}
117127
}
128+
129+
export function dangerouslyResetForTesting(): void {
130+
if (__DEV__) {
131+
overrides = null;
132+
accessedFeatureFlags.clear();
133+
reportedConfigNames.clear();
134+
clearCachedValuesFns.forEach(fn => fn());
135+
}
136+
}

0 commit comments

Comments
 (0)