Skip to content

Commit 0335fec

Browse files
rubennortefacebook-github-bot
authored andcommitted
Add Fantom.getHostPlatform() to expose test runner host OS (#56990)
Summary: 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
1 parent 622941d commit 0335fec

3 files changed

Lines changed: 37 additions & 1 deletion

File tree

private/react-native-fantom/runner/entrypoint-template.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,32 @@
99
*/
1010

1111
import type {SnapshotConfig} from '../runtime/snapshotContext';
12-
import type {FantomRuntimeConstants} from '../src/Constants';
12+
import type {FantomRuntimeConstants, HostPlatform} from '../src/Constants';
1313
import type {FantomTestConfig} from './getFantomTestConfigs';
1414

1515
import * as EnvironmentOptions from './EnvironmentOptions';
1616
import formatFantomConfig from './formatFantomConfig';
1717

18+
function getHostPlatform(): HostPlatform {
19+
match (process.platform) {
20+
'darwin' => {
21+
return 'macos';
22+
}
23+
'win32' => {
24+
return 'windows';
25+
}
26+
'linux' => {
27+
return 'linux';
28+
}
29+
'android' => {
30+
return 'android';
31+
}
32+
_ => {
33+
throw new Error(`Unsupported platform: ${process.platform}`);
34+
}
35+
}
36+
}
37+
1838
module.exports = function entrypointTemplate({
1939
testPath,
2040
setupModulePath,
@@ -42,6 +62,7 @@ module.exports = function entrypointTemplate({
4262
jsTraceOutputPath,
4363
jsHeapSnapshotOutputPathTemplate,
4464
jsHeapSnapshotOutputPathTemplateToken,
65+
hostPlatform: getHostPlatform(),
4566
};
4667

4768
return `/**

private/react-native-fantom/src/Constants.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* @format
99
*/
1010

11+
export type HostPlatform = 'android' | 'windows' | 'macos' | 'linux';
12+
1113
export type FantomRuntimeConstants = Readonly<{
1214
isOSS: boolean,
1315
isRunningFromCI: boolean,
@@ -16,6 +18,7 @@ export type FantomRuntimeConstants = Readonly<{
1618
jsHeapSnapshotOutputPathTemplate: string,
1719
jsHeapSnapshotOutputPathTemplateToken: string,
1820
jsTraceOutputPath: ?string,
21+
hostPlatform: HostPlatform,
1922
}>;
2023

2124
let constants: FantomRuntimeConstants = {
@@ -26,6 +29,7 @@ let constants: FantomRuntimeConstants = {
2629
jsHeapSnapshotOutputPathTemplate: '',
2730
jsHeapSnapshotOutputPathTemplateToken: '',
2831
jsTraceOutputPath: null,
32+
hostPlatform: 'linux',
2933
};
3034

3135
export function getConstants(): FantomRuntimeConstants {

private/react-native-fantom/src/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* @format
99
*/
1010

11+
import type {HostPlatform} from './Constants';
1112
import type {
1213
FantomRenderedOutput,
1314
RenderOutputConfig,
@@ -46,6 +47,16 @@ export type RootConfig = {
4647

4748
export {getConstants} from './Constants';
4849

50+
/**
51+
* Returns the host OS where the Fantom test runner is running (e.g.
52+
* 'linux', 'macos', 'windows'). This is different from React Native's
53+
* `Platform.OS`, which always reflects the React Native target platform
54+
* being tested.
55+
*/
56+
export function getHostPlatform(): HostPlatform {
57+
return getConstants().hostPlatform;
58+
}
59+
4960
// Defaults use iPhone 14 values (very common device).
5061
const DEFAULT_VIEWPORT_WIDTH = 390;
5162
const DEFAULT_VIEWPORT_HEIGHT = 844;

0 commit comments

Comments
 (0)