marilari88 / neotest-vitest

Vitest adapter for Neovim Neotest plugin
106 stars 33 forks source link

feat: Add support for watch flag #44

Closed marcoSven closed 8 months ago

marcoSven commented 8 months ago

This commit introduces a feature to support the watch mode in neotest. In the previous implementation, the user had the ability to run tests but there was no provision to watch the files and run the tests when changes occur. This feature is particularly helpful while doing test-driven development where code changes frequently.

  1. Added key mappings examples in README.md to trigger watch mode.
  2. Refactored the build_spec function in init.lua to support watch mode. It now includes command flag "--watch=false" in the command list instead of --run.
  3. Added a new function stream in util.lua which continuously reads file data and triggers a callback function for new data. This is used to watch the test files and run tests on file change.

https://github.com/marilari88/neotest-vitest/assets/3860298/649933e2-6944-4bf0-a4e8-f487159a2d90

closes #27

marilari88 commented 8 months ago

@marcoSven Big thanks for your contribution! I left a couple of comments for you. One concern though: I noticed when testing the PR that the vitest process in watch mode sticks around until Neovim shuts down or Neotest stop is called. This could lead to a bunch of unwanted background processes if we're running lots of tests in watch mode. How do you handle it?

marcoSven commented 8 months ago

I noticed when testing the PR that the vitest process in watch mode sticks around until Neovim shuts down or Neotest stop is called.

I think this is the same with the Jest adapter.

marilari88 commented 8 months ago

@marcoSven thanks!