mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Use enum for Fantom modes (#48179)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/48179 Changelog: [internal] Migrating this type to an enum, which is safer, because it prevents errors like: ``` // when it's actually 'dev' if (mode === 'development') { } ``` Reviewed By: rshest Differential Revision: D66888985 fbshipit-source-id: 4f3f91fad6ca5256baa2123425b2bad11fe036f9
This commit is contained in:
committed by
Facebook GitHub Bot
parent
07a7b63fdd
commit
4d07fb7662
+14
-6
@@ -19,7 +19,10 @@ type JsOnlyFeatureFlags = (typeof ReactNativeFeatureFlags)['jsOnly'];
|
||||
|
||||
type DocblockPragmas = {[key: string]: string | string[]};
|
||||
|
||||
export type FantomTestConfigMode = 'dev' | 'opt';
|
||||
export enum FantomTestConfigMode {
|
||||
Development,
|
||||
Optimized,
|
||||
}
|
||||
|
||||
export type FantomTestConfigCommonFeatureFlags = Partial<{
|
||||
[key in keyof CommonFeatureFlags]: CommonFeatureFlags[key]['defaultValue'],
|
||||
@@ -37,7 +40,7 @@ export type FantomTestConfig = {
|
||||
},
|
||||
};
|
||||
|
||||
const DEFAULT_MODE: FantomTestConfigMode = 'dev';
|
||||
const DEFAULT_MODE: FantomTestConfigMode = FantomTestConfigMode.Development;
|
||||
|
||||
const FANTOM_FLAG_FORMAT = /^(\w+):(\w+)$/;
|
||||
|
||||
@@ -84,10 +87,15 @@ export default function getFantomTestConfig(
|
||||
|
||||
const mode = maybeMode;
|
||||
|
||||
if (mode === 'dev' || mode === 'opt') {
|
||||
config.mode = mode;
|
||||
} else {
|
||||
throw new Error(`Invalid Fantom mode: ${mode}`);
|
||||
switch (mode) {
|
||||
case 'dev':
|
||||
config.mode = FantomTestConfigMode.Development;
|
||||
break;
|
||||
case 'opt':
|
||||
config.mode = FantomTestConfigMode.Optimized;
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Invalid Fantom mode: ${mode}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -13,6 +13,7 @@ import type {TestSuiteResult} from '../runtime/setup';
|
||||
|
||||
import entrypointTemplate from './entrypoint-template';
|
||||
import getFantomTestConfig from './getFantomTestConfig';
|
||||
import {FantomTestConfigMode} from './getFantomTestConfig';
|
||||
import {
|
||||
getBuckModeForPlatform,
|
||||
getDebugInfoFromCommandResult,
|
||||
@@ -97,7 +98,7 @@ module.exports = async function runTest(
|
||||
|
||||
const testConfig = getFantomTestConfig(testPath);
|
||||
|
||||
const isOptimizedMode = testConfig.mode === 'opt';
|
||||
const isOptimizedMode = testConfig.mode === FantomTestConfigMode.Optimized;
|
||||
|
||||
const metroConfig = await Metro.loadConfig({
|
||||
config: path.resolve(__dirname, '..', 'config', 'metro.config.js'),
|
||||
|
||||
Reference in New Issue
Block a user