RN Web support #1554
Replies: 2 comments 8 replies
-
I agree very much with the first downside you identified but I'm not sure I understand your solution. What would it mean to include RNWeb support into RNTL exactly? I don't think there really is a way around having a test setup for RN and another for RNWeb because you don't want to use the same preset and also not the same environment (node vs jsdom). Maybe there would be solutions to make that setup easier though, that's definitely worth exploring. You could however run the same test files using two different environments if RNTL supported a web setup, probably by mapping to RTL's APIs like you suggested. That being said I have some concerns about this approach:
|
Beta Was this translation helpful? Give feedback.
-
Closing due to the lack of interest. |
Beta Was this translation helpful? Give feedback.
-
RN vs RN Web comparison
RN Web renders HTML elements like
<div>
instead of typical RN host views like<View />
,<Text />
.This can be replicated by installing
jest-expo
package and applying Jest"preset": "jest-expo/universal"
. Using is the Jest Expo package is the only known popular way to render in RN Web mode I am aware of.The comparison above has been achieved using React Test Renderer, since RNTL's
detectHostComponentNames()
function throws error when running underweb
preset.Potential solution
React.js (web) has a mature testing solution in form of RTL, on which RNLT is modelled. However, as noted in our docs, RTL has much better testing environment due to usage of Jest DOM package, which is a reliable browser DOM simulation. In contrast, RNTL contains code simulating only the key aspects of RN env, sometimes in a very crude way.
Therefore, our recommendation so far, has been to test RN Web rendering using a proper RTL setup. This has two major downsides:
In order to ease life of RN Web users, we could potentially include proper RN Web setup inside RNTL. The env setup could be modelled on Jest Expo package (or simply re-use it). That would solve pain no. 1.
In order to solve pain no. 2, we would have to be able to execute given test suit in both RN+RNTL and RN Web+RTL+Jest DOM setup. The easiest, but not easy, way to achieve it would be create a adapter/facade layer, that would expose the familiar RNTL API to the user, but would internally translate it to RTL calls. This should be possible as, RNTL API is largely coherent with RTL API. There are some semantic differences between the queries which would need to be bridged by such RNTL adapter. E.g., RNTL exposes
includeHiddenElements
option which is an alias tohidden
option in RTL, but RNTL exposes it on all queries, while on RTL it's only available on*ByRole
queries.Alternative approaches
Recommend users to test the core RN (not yet translated to Web) using current RNTL. This is what we support now. It does provide a unified testing ground for RN apps, by mixing together various iOS and Android observed runtime behaviours, but does not allow for testing of RN Web-specific aspects.
Provide example setup for devs wanting to test RN Web using RTL+Jest DOM, but without ability to share testing code. Users would have to duplicate their tests manually. RTL testing code would be largely copy-paste from RNTL with minor tweaks, but that the burden of maintaining RNTL/RTL differences would be on the users.
Create and maintain an external RNTL Web package, that would do support the API adaptation described above, in a similar way that RN Web exposes RN APIs. This could be maintained either by RNTL team or by some 3rd party with serious interest in RN Web support.
Considerations
The decision whether to pursue this effort inside RNTL should be based on the following factors:
CC: @thymikee, @AugustinLF, @pierrezimmermannbam, @MattAgn
Beta Was this translation helpful? Give feedback.
All reactions