nvim-neotest / neotest

An extensible framework for interacting with tests within NeoVim.
MIT License
2.13k stars 105 forks source link

Question/Feature #333

Closed delabere closed 6 months ago

delabere commented 7 months ago

Is there a way to limit how neotest searches for tests?

Currently I'm working with a massive mono-repo and neotest tries to grab every test it can find which slows my computer to a halt.

It would be great if I could set a set of root files that neotest could search upwards for lazily in order to find the current working directory, in my case this could be ["main.go", "README.md"] etc.

Thanks!

rcarriga commented 6 months ago

There are several options related to test discovery. You can disable discovery completely so only open buffers are shown. You can also filter directories to search using a function. See :help neotest.Config.discovery for both

neotest-go looks for go.mod and go.sum already to find the root directory https://github.com/nvim-neotest/neotest-go/blob/d29d20d912aca81a07c50022d880cc66f0d26542/lua/neotest-go/init.lua#L23 but currently it searches from the current directory and searches upwards, it doesn't search sub-directories. You could assign your own root discovery function to the adapter if you wanted

local go_adapter = require("neotest-go")
go_adapter.root = function (cwd)
  ...
end
require("neotest").setup({
  adapters = {go_adapter},
})
delabere commented 6 months ago

Thank you @rcarriga this is really helpful I'll see if I can implement something to suit my needs - I'll close this as well