Add Fantom.getHostPlatform() to expose test runner host OS (#56990)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/56990

Adds a new `Fantom.getHostPlatform()` API that returns the host
operating system where the Fantom test runner is running (e.g. 'linux',
'macos', 'windows', 'android'). This is different from React Native's
`Platform.OS`, which always reflects the React Native target platform
being tested.

The value is determined by the Node.js Jest runner (via
`process.platform`) and baked into the JS bundle through the existing
`setConstants(...)` pipeline, so no native changes are needed.

- Add `HostPlatform` type and `hostPlatform` field to
  `FantomRuntimeConstants`.
- Populate `hostPlatform` from the host platform in the entrypoint
  template (maps darwin -> macos, win32 -> windows, etc.).
- Expose `getHostPlatform()` from the public Fantom API.

Changelog: [Internal]

Reviewed By: javache

Differential Revision: D106669673

fbshipit-source-id: 6948e0c1eb0075131211d8c5099da96a87306b0a
This commit is contained in:
Rubén Norte authored and meta-codesync[bot] committed 2026-05-29 08:02:57 -07:00
1 parent 622941d9dc
commit 9199b3933a
3 files changed
+37 -1

No files matched your search

+22 -1
View File
@@ -9,12 +9,32 @@
*/
import type {SnapshotConfig} from '../runtime/snapshotContext';
import type {FantomRuntimeConstants} from '../src/Constants';
import type {FantomRuntimeConstants, HostPlatform} from '../src/Constants';
import type {FantomTestConfig} from './getFantomTestConfigs';
import * as EnvironmentOptions from './EnvironmentOptions';
import formatFantomConfig from './formatFantomConfig';
function getHostPlatform(): HostPlatform {
match (process.platform) {
'darwin' => {
return 'macos';
}
'win32' => {
return 'windows';
}
'linux' => {
return 'linux';
}
'android' => {
return 'android';
}
_ => {
throw new Error(`Unsupported platform: ${process.platform}`);
}
}
}
module.exports = function entrypointTemplate({
testPath,
setupModulePath,
@@ -42,6 +62,7 @@ module.exports = function entrypointTemplate({
jsTraceOutputPath,
jsHeapSnapshotOutputPathTemplate,
jsHeapSnapshotOutputPathTemplateToken,
hostPlatform: getHostPlatform(),
};
return `/**
+4
View File
@@ -8,6 +8,8 @@
* @format
*/
export type HostPlatform = 'android' | 'windows' | 'macos' | 'linux';
export type FantomRuntimeConstants = Readonly<{
isOSS: boolean,
isRunningFromCI: boolean,
@@ -16,6 +18,7 @@ export type FantomRuntimeConstants = Readonly<{
jsHeapSnapshotOutputPathTemplate: string,
jsHeapSnapshotOutputPathTemplateToken: string,
jsTraceOutputPath: ?string,
hostPlatform: HostPlatform,
}>;
let constants: FantomRuntimeConstants = {
@@ -26,6 +29,7 @@ let constants: FantomRuntimeConstants = {
jsHeapSnapshotOutputPathTemplate: '',
jsHeapSnapshotOutputPathTemplateToken: '',
jsTraceOutputPath: null,
hostPlatform: 'linux',
};
export function getConstants(): FantomRuntimeConstants {
+11
View File
@@ -8,6 +8,7 @@
* @format
*/
import type {HostPlatform} from './Constants';
import type {
FantomRenderedOutput,
RenderOutputConfig,
@@ -46,6 +47,16 @@ export type RootConfig = {
export {getConstants} from './Constants';
/**
* Returns the host OS where the Fantom test runner is running (e.g.
* 'linux', 'macos', 'windows'). This is different from React Native's
* `Platform.OS`, which always reflects the React Native target platform
* being tested.
*/
export function getHostPlatform(): HostPlatform {
return getConstants().hostPlatform;
}
// Defaults use iPhone 14 values (very common device).
const DEFAULT_VIEWPORT_WIDTH = 390;
const DEFAULT_VIEWPORT_HEIGHT = 844;