diff --git a/packages/react-native/src/private/renderer/runtimescheduler/__tests__/RuntimeScheduler-benchmark-itest.js b/packages/react-native/src/private/renderer/runtimescheduler/__tests__/RuntimeScheduler-benchmark-itest.js index 4ffe7e624d06..e15f397a165f 100644 --- a/packages/react-native/src/private/renderer/runtimescheduler/__tests__/RuntimeScheduler-benchmark-itest.js +++ b/packages/react-native/src/private/renderer/runtimescheduler/__tests__/RuntimeScheduler-benchmark-itest.js @@ -11,6 +11,8 @@ import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment'; +import type {TestOptions} from '@react-native/fantom/src/Benchmark'; + import NativeFantomTestSpecificMethods from '../../../testing/fantom/specs/NativeFantomTestSpecificMethods'; import * as Fantom from '@react-native/fantom'; @@ -60,3 +62,93 @@ Fantom.unstable_benchmark Fantom.runTask(noop); } }); + +for (const count of [100, 1000]) { + let completed = 0; + let resolvedValues: Array = []; + const expectedValues = Array.from({length: count}, (_, i) => i + 1); + const verifyCompleted = () => { + expect(completed).toBe(count); + }; + const options: TestOptions = { + beforeAll: () => { + expect(global.HermesInternal?.hasPromise?.()).toBe(true); + }, + beforeEach: () => { + completed = 0; + }, + afterEach: verifyCompleted, + }; + + Fantom.unstable_benchmark + .suite(`Promise microtasks (${count} operations)`, { + minTestExecutionTimeMs: 1000, + minWarmupIterations: 100, + }) + .test( + 'Promise.then chain', + () => { + Fantom.runTask(() => { + let promise = Promise.resolve(0); + for (let i = 0; i < count; i++) { + promise = promise.then(value => value + 1); + } + void promise.then(value => { + completed = value; + }); + }); + }, + options, + ) + .test( + 'Promise.all fan-out', + () => { + Fantom.runTask(() => { + const promises = []; + for (let i = 0; i < count; i++) { + promises.push(Promise.resolve(i).then(value => value + 1)); + } + void Promise.all(promises).then(values => { + resolvedValues = values; + completed = values.length; + }); + }); + }, + { + ...options, + afterEach: () => { + verifyCompleted(); + expect(resolvedValues).toEqual(expectedValues); + }, + }, + ) + .test( + 'serial async/await', + () => { + Fantom.runTask(() => { + async function run() { + let value = 0; + for (let i = 0; i < count; i++) { + value += await Promise.resolve(1); + } + completed = value; + } + void run(); + }); + }, + options, + ) + .test( + 'queueMicrotask control', + () => { + Fantom.runTask(() => { + for (let i = 0; i < count; i++) { + queueMicrotask(() => { + completed++; + }); + } + }); + }, + options, + ); +} diff --git a/private/react-native-fantom/runner/__tests__/runCommandSync-test.js b/private/react-native-fantom/runner/__tests__/runCommandSync-test.js index b06b5d3d28dd..c1bda423206e 100644 --- a/private/react-native-fantom/runner/__tests__/runCommandSync-test.js +++ b/private/react-native-fantom/runner/__tests__/runCommandSync-test.js @@ -8,9 +8,33 @@ * @format */ -import {getDebugInfoFromCommandResult, runCommandSync} from '../utils'; +import { + HermesVariant, + getBuckOptionsForHermes, + getDebugInfoFromCommandResult, + runCommandSync, +} from '../utils'; import path from 'node:path'; +describe('getBuckOptionsForHermes', () => { + it('enables native internal JavaScript for both Static Hermes variants', () => { + const modifier = + '--modifier=fbsource//xplat/hermes_common:internal_javascript_native[enabled]'; + expect(getBuckOptionsForHermes(HermesVariant.StaticHermesStable)).toContain( + modifier, + ); + expect( + getBuckOptionsForHermes(HermesVariant.StaticHermesExperimental), + ).toContain(modifier); + }); + + it('does not enable the modifier for legacy Hermes', () => { + expect(getBuckOptionsForHermes(HermesVariant.Hermes)).not.toContain( + '--modifier=fbsource//xplat/hermes_common:internal_javascript_native[enabled]', + ); + }); +}); + describe('runCommandSync', () => { it('preserves the spawn error when the command cannot start', () => { const command = path.join(__dirname, 'nonexistent-fantom-executable'); diff --git a/private/react-native-fantom/runner/utils.js b/private/react-native-fantom/runner/utils.js index 0c4bb472218a..bac81c066af4 100644 --- a/private/react-native-fantom/runner/utils.js +++ b/private/react-native-fantom/runner/utils.js @@ -38,9 +38,17 @@ export function getBuckOptionsForHermes( case HermesVariant.Hermes: return [...baseOptions, '-c hermes.static_hermes=legacy']; case HermesVariant.StaticHermesStable: - return [...baseOptions, '-c hermes.static_hermes=stable']; + return [ + ...baseOptions, + '-c hermes.static_hermes=stable', + '--modifier=fbsource//xplat/hermes_common:internal_javascript_native[enabled]', + ]; case HermesVariant.StaticHermesExperimental: - return [...baseOptions, '-c hermes.static_hermes=trunk']; + return [ + ...baseOptions, + '-c hermes.static_hermes=trunk', + '--modifier=fbsource//xplat/hermes_common:internal_javascript_native[enabled]', + ]; } }