Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -60,3 +62,93 @@ Fantom.unstable_benchmark
Fantom.runTask(noop);
}
});

for (const count of [100, 1000]) {
let completed = 0;
let resolvedValues: Array<number> = [];
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,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
12 changes: 10 additions & 2 deletions private/react-native-fantom/runner/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]',
];
}
}

Expand Down
Loading