Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run Jest (and react-native-testing-library tests) on Hermes? #1707

Closed
fabiendem opened this issue Nov 19, 2024 · 4 comments
Closed

Run Jest (and react-native-testing-library tests) on Hermes? #1707

fabiendem opened this issue Nov 19, 2024 · 4 comments
Labels
question Further information is requested

Comments

@fabiendem
Copy link

Hi everyone, I am asking here because I may have a better React Native audience:

Has anyone ever been able to run their tests on the Hermes engine instead of the normal Node V8 engine?
We have some inconsistencies between the behaviour of the code in our tests VS while running on a device (Hermes)

Happy to move this to the Jest repo (Hermes already said it's not their concern facebook/hermes#650), I get that it's not an RNTL concern initially.

Thanks!

@fabiendem fabiendem added the question Further information is requested label Nov 19, 2024
@mdjastrzebski
Copy link
Member

RNTL is focusing on provided RN testing utilities and env simulation, on top of Jest as a test runner. The selection of JS engine is probably the responsibility of JS runtime like node, deno, bun. Not sure if there are any JS runtimes which use Hermes, afaik most use either V8 or JSC.

Out of curiosity, what inconsistencies have you encountered between V8 and Hermes?

@andresmartinezstay
Copy link

andresmartinezstay commented Nov 20, 2024

I had some inconsistencies as well, for example the URL class is available in nodejs but not on hermes (it is needed to install a polyfill in react native). If I hadn't tested the app manually this bug would have hit production, despite having tests, so being able to run the tests on hermes itself I'd say it is a must to ensure consistency

@fabiendem
Copy link
Author

Thanks @mdjastrzebski

Out of curiosity, what inconsistencies have you encountered between V8 and Hermes?

In our case, the issue is around Date parsing.
V8/JSC will support non-standard date formats (example: MM/dd/yyyy), while Hermes doesn't.

Our Jest tests run on node and will pass, while the code running on Hermes breaks.
It's not the end of the world, but it makes it difficult to:

  • prevent the bug in the first place
  • debug it

Date expects an ISO 8601 format, but Non-standard format support depends on the implementation of the engine: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#date_time_string_format:~:text=Non%2Dstandard%20strings,non%2Dstandard%20cases.

A JSC/V8 engine will gracefully handle other formats because it has some fallbacks. Hermes doesn't yet.
The issue is tracked at facebook/hermes#865

I created a Snack and shared it at facebook/hermes#865 (comment) if you want to play with it.

I know it's not react-native-testing-library's responsibility; feel free to close this when you feel like it.
I know there is a lot of Jest/RN expertise here, so I used this forum.

@mdjastrzebski
Copy link
Member

Closing as non-actionable.

@mdjastrzebski mdjastrzebski closed this as not planned Won't fix, can't repro, duplicate, stale Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants