How to have testable Javascript in a Phoenix LiveView Project?

Hey @Exadra37 , looks like I was responding to you just as you wrote your follow-up. Overall, I think you landed in a good place for unit testing your JS.

I would make a few tweaks, but feel free to ignore them if you’re happily on your way:

  1. If the JS source code you’ve written for your canvas abstraction is completely authored by your team, I would move the code out of assets/vendor/, as that directory is traditionally used for third-party code. You can instead house your js in assets/js as direct descendant files (or in a subdirectory if you have many modules that you want to semantically group)
  2. You can simplify your tsconfig ←→ vitest.config by creating your test files as direct siblings of the modules they test. Then your test files can import the modules under test using very simple relative paths, i.e. import { funcToTest } from "./canvas" . That will allow you to remove the various aliasing configs you’ve set up, which, I can tell you from experience, can lead to configuration maintenance headaches over time. If you want to go that route, I’d use file infixing for the test files, where your test files would look like canvas.test.ts

Either way, happy you landed in a decent spot. Test on! :rocket: