get-convex / convex-test

Testing harness for pure-JS Convex tests
Apache License 2.0
3 stars 1 forks source link

Fix issues with dynamic imports #7

Closed xixixao closed 4 months ago

xixixao commented 4 months ago

Dynamic imports for resolving Convex function references have had a number of issues:

  1. Saving the dynamically imported file did not rerun tests
  2. The dynamically imported file could have been cached even after restarting vitest
  3. Coverage was not working
  4. Workspaces broke the dynamic imports altogether

I asked Vitest folks and they advised on using import.meta.glob and server: { deps: { inline:. With this approach convexTest first imports all the source files that could contain functions. This is done by assuming the installation path in node_modules, or the developer can pass in import.meta.glob() result if they have custom functions path.

All the issues are now fixed except for workspaces, which now do run, but the files are still not being tracked correctly (I'm asking for more help on vitest discord).

This does mean that saving any source file reruns all tests. This is unfortunate but unavoidable, as we have to support passing raw string function references, and so there is no bundler approach that can be taken here. In practice this is not too bad, because Vitest is uber fast, and because the developer can select the individual test / test file they're working on anyway.