facebook / hermes

A JavaScript engine optimized for running React Native.
https://hermesengine.dev/
MIT License
9.78k stars 628 forks source link

Hermes and Jest integration #650

Closed joe-sam closed 1 year ago

joe-sam commented 2 years ago

Problem

When jest unit tests run they are typically run in a virtual environment vmContext typically emulating nodejs or browser (jsdom).

To make a clean and safe transition from plain JSC to Hermes it would be considerably quicker to troubleshoot by running various fundamental unit jest tests under hermes VM engine, before any e2e tests are required.

Solution

Should be an easier way to configure the setup so as to run the unit tests under a specially built Hermes VM context module, and then compare the unit test results to a JSC context.

Additional Context

For more info see

nandorojo commented 2 years ago

Did you figure out a way to do this? I’m migrating to Hermes for iOS and am very concerned about the lack of Intl support. I’m thinking of using a dates polyfill, but I want to run tests to ensure their accuracy.

joe-sam commented 2 years ago

No, unfortunately I haven't figured out a way to do this exactly as there were still some critical missing features in Hermes implementation at that time notably the implementation of a runtime eval which makes awkward sense as hermes is a bytecode compiler. If this changes it would be entirely possible to write your own testbench framework in a few hundred lines as explained by Christoph Nakazawa building a javascript testing framework such a gem of wonderful tutorial on understanding and expanding the usage of the Jest f/w by an original implementer.

The status for Hermes iOS support seems to be open ended with some users claiming that Intl is fully (???) supported but RN framework apparently hasn't yet re-wired support to the new libs (projected ETA @ RNv0.71) (statistically that would be about 1.2 years as each major release seems to take a more than a quarter of a year). Hermes itself undergoes a battery of Intltests but it is hard to see which ones have been skipped to pass the CI.

Follow this other thread for further updates on Intl, which in my opinion is a huge project having thousands of edge cases and my estimate is it would take many man months of effort.

steveluscher commented 1 year ago

I would love to have this to test https://github.com/solana-labs/solana-web3.js. I want unit tests that protect against the React Native bundle breaking because someone introduced a primitive that's not available in Hermes. Things like this have happened countless times in the past (SubtleCrypto not being available, JSC not supporting BigInt literals, Intl differences, et cetera).

tmikov commented 1 year ago

As far as I can tell, there is no concrete ask for the Hermes team here. We are not experts on Jest and unfortunately we don't know why Jest doesn't work with Hermes or what would be required to change that either in Hermes or in Jest.

Moving this to Discussions. If concrete Hermes features get request as a result, file them as issues.