Replies: 1 comment 3 replies
-
|
This is really interesting! Great to see this implemented as custom pool. It kind of validates the idea we've been thinking about whether custom pools could work as abstraction for running test cases in non-Node environments. 💯
This is not a known issue. There is |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello! I'm a big fan of Vite/Vitest, have been using them for years. Our company needed better React Native testing, so I made Vitest Mobile: https://github.com/pzuraq/vitest-mobile/
The thing that sets this apart from other projects like vitest-native and vitest-react-native is that Vitest Mobile actually boots a full emulator/simulator and runs the tests in the real environment. The idea is to use the same structure that Vitest Browser established and to try to fit into the ecosystem in exactly the same way. I also considered react-native-harness, but I really ended up believing that the Vite model works much better. The parts are just much more composable, and building it was relatively straightforward - all signs of a well run, well factored project.
Anyways! I wanted to raise a couple of topics for discussion here:
Upstreaming?
Would this be something we could eventually upstream into the Vite/Vitest org/umbrella? Would the team be interested in an "official" solution for testing apps in a mobile environment? I think, FWIW, we could also test PWAs with a lot of the same tooling, so this wouldn't necessarily be limited to just React Native apps, it really could be a set of composable tools for running Vitest in emulators/simulators in general.
Coordinating API development and providing feedback?
Even if it's never an official plugin in the Vitest org, I'd like to work with the team to make sure that everything is solid and does things the "Vitest way" internally. In my experience, that makes these projects much easier as a maintainer, using solid public APIs rather than hacking around things. The
poolAPI already feels like it has some limitations that I'm working around, so would love to spend some time (eventually, when I have time 🫠) hardening those APIs and maybe working with y'all to figure out where the rough edges are.Replacing Metro Entirely?
The biggest one here, and probably a wider discussion than just Vitest, but this is a good place to start.
So, Metro is very much based on a non-Vite like build world. It feels very tailored to React Native, and very built for the Webpack world. All of these assumptions are built in, and that basically means I have:
~/.cachedirThis is the most brittle part of the architecture IMO, for a number of reasons. I also felt like, as I started to dig in, maybe we could just replace Metro with Vite?
For reference, I'm a former Ember.js core team member and worked a lot with Ember-CLI stuff back in the day, so I'm very familiar with module systems and AMD like output as a compile target. This is what Metro ultimately produces, since React Native apps generally just have one big JS file, and Hermes does not support
importdirectly.I feel like what we could do here is something like this:
devmode, Metro just sends plain-text JS, it doesn't compile to byte-code, SO we coulda. Setup an module system in the built output, similar to Metro
b. Send updates over a WebSocket, eval them, and replace the modules, again, like Metro
c. But, change any custom semantics for HMR and such to match Vite's model
This would all be done as a plugin, to be clear, not built directly into Vite. I think the plugin model would already be flexible enough here, for the most part. If we did this, we would be able to run Vite as the webserver, and Vitest Mobile would be able to use the same update patterns as standard Vitest (rather than having to rely on Metro HMR semantics).
Things that would be out of scope IMO would be:
I won't have time to work on this in the immediate future, but I wanted to start the discussion to share ideas, and because maybe someone else does have that time. Also, maybe I'm underestimating the complexity of the Metro build pipeline, definitely still new to it so not sure if there are aspects I'm not thinking about.
Beta Was this translation helpful? Give feedback.
All reactions