Skip to content

Commit

Permalink
Use enum for Fantom modes (facebook#48179)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#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
  • Loading branch information
rubennorte authored and facebook-github-bot committed Dec 9, 2024
1 parent 07a7b63 commit 4d07fb7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
20 changes: 14 additions & 6 deletions packages/react-native-fantom/runner/getFantomTestConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -37,7 +40,7 @@ export type FantomTestConfig = {
},
};

const DEFAULT_MODE: FantomTestConfigMode = 'dev';
const DEFAULT_MODE: FantomTestConfigMode = FantomTestConfigMode.Development;

const FANTOM_FLAG_FORMAT = /^(\w+):(\w+)$/;

Expand Down Expand Up @@ -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}`);
}
}

Expand Down
3 changes: 2 additions & 1 deletion packages/react-native-fantom/runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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'),
Expand Down

0 comments on commit 4d07fb7

Please sign in to comment.