问HN:我应该使用什么工具在设备上运行React Native测试?
在 JavaScript/TypeScript 领域,我发现一个比较普遍的问题是,单元测试通常被期望在 Node.js 进程中运行。在过去的多个项目中,这种方法证明是有问题的,因为无法实现与目标运行环境(浏览器)的“环境一致性”(例如,没有 WebRTC[1])。在这些项目中,我们通过编写自己的测试运行器来解决这个问题,该运行器可以注入到无头浏览器进程中。
现在,在一个使用 React Native 的移动设备项目中,出现了类似的问题:我原以为单元测试可以在设备上或至少在模拟器上运行,但似乎并非如此(参见:https://docs.expo.dev/develop/unit-testing/)。或者至少到目前为止,我还没有找到能够实现这一点的秘密武器或工具。欢迎提供任何指引。
[1] 是的,确实有一个用于 Node 的 WebRTC 移植版,它使用了 Google 的旧版 C++ 库,但实际上并不能正常工作。
查看原文
Something of a common problem in JS/TS-land, I've found is that unit tests are expected to be run in a Node.js process. In the past in various projects this approach proved problematic because "environment parity" with the target runtime (browser) couldn't be achieved (e.g. no WebRTC[1]). In those projects we resolved this problem by writing our own test runner that could be injected into a headless browser process.<p>So now the same sort of problem has arisen with a mobile device project using react native: I assumed that unit tests would be runnable on a device or at least an emulator, but it seems not (see: https://docs.expo.dev/develop/unit-testing/). Or at least so far I haven't found the secret sauce or tool to allow that. Any pointers welcome.<p>[1]Yes there is a WebRTC port for Node that uses an old version of Google's C++ library, but it doesn't actually work properly.