diff --git a/packages/runtime/src/index.ts b/packages/runtime/src/index.ts index dc03137..6fd2a8c 100644 --- a/packages/runtime/src/index.ts +++ b/packages/runtime/src/index.ts @@ -1,3 +1,5 @@ +// Polyfills must be imported first to ensure compatibility with Hermes +import './polyfills.js'; import './globals.d.ts'; export { UI as ReactNativeHarness } from './ui/index.js'; diff --git a/packages/runtime/src/polyfills.ts b/packages/runtime/src/polyfills.ts new file mode 100644 index 0000000..4410462 --- /dev/null +++ b/packages/runtime/src/polyfills.ts @@ -0,0 +1,16 @@ +/** + * Polyfills for Hermes JavaScript engine compatibility. + * + * Hermes (React Native's default JS engine) doesn't support all ES2022+ features. + * This file provides polyfills for features used by harness dependencies. + */ + +/** + * Object.hasOwn (ES2022) + * Used by @vitest/expect v4.x for property checking. + * @see https://github.com/facebook/hermes/issues/1875 + */ +if (typeof Object.hasOwn !== 'function') { + Object.hasOwn = (obj: object, prop: PropertyKey): boolean => + Object.prototype.hasOwnProperty.call(obj, prop); +}