-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: test args evaluated at runtime #186
Comments
Hi @kvalv,
Many thanks for these kind words ❤️ I'm really happy the monorepo support works "in the wild" as well 😄 as I haven't heard much on this particular topic (could also be a sign it just works for a majority of the cases, heh). I'd be happy to have the adapter support your use case of wanting to provide a function, which would be called just-in-time style, rather than be sourced on adapter intialization. It just happens that there was another inquiry in #187 that might be of interest to you, which talks about expanding the ability to customize the test runner and its logic. You can subscribe/follow that if you wish. I think your naive implementation of detecting whether the I guess we could whip up a quick PR just to have something to have you try out. |
Please give something like this a try: return {
{
"nvim-neotest/neotest",
dependencies = {
"nvim-neotest/nvim-nio",
"nvim-lua/plenary.nvim",
"antoinemadec/FixCursorHold.nvim",
"nvim-treesitter/nvim-treesitter",
{
"fredrikaverpil/neotest-golang", -- Installation
branch = "args-function", -- Custom branch
},
},
config = function()
local opts = { -- Specify configuration
go_test_args = function()
-- Place your custom logic here for the 'go test' args
return {
"-v",
"-race",
"-count=1",
"-coverprofile=" .. vim.fn.getcwd() .. "/coverage.out",
}
end,
}
require("neotest").setup({
adapters = {
require("neotest-golang")(opts), -- Apply configuration
},
})
end,
},
} It uses the By the way, are these build flags? |
Hi, nice to see a PR for this out already! I checked out the branch and it works as expected. So believe if this gets merged it would certainly solve my problems 😄
No, I just have some tests that depend on external services that are skipped if no flags are provided. For example, if I run Regarding Thanks again for the quick response! |
Ok, nice. I'll just add some tests for the options (so that function support is covered) and then I'll merge this in. |
Did you check docs and existing issues?
Is your feature request related to a problem? Please describe.
Hi, first of all thanks for taking the effort to write this plugin! Very happy to see a neotest adapter that works in monorepos, and the documentation provided in the README has made the adapter easy to configure.
I am currently working in a monorepo that roughly has this structure:
If I'm in service A, I would like to test with
go test ./... -flagA
and in service B I would run tests likego test ./... -flagB
. So the flags I want to use can differ on each service. Based on the configuration I can pass ingo_test_args
for providing flags. However, thego_test_args
is initialized on startup (or whenever neotest-golang is configured), so it's not possible to adjust them depending on the current file - they are static.Describe the solution you'd like to see.
Approach 1 - static
I already have one workaround - depending on the current working directory I start neovim in, set the appropriate flags. Something like this:
A disadvantage of this approach is that I must start the neovim instance in the
/serviceA
directory to be able to run tests inserviceA
. Ideally, I don't want this to matter -- if I'm in a test file, I should be able to run a test appropriately, without having to worry about where I started the neovim session.Approach 2 - dynamic
Instead of
go_test_args
being a table, it can either be a table or a function that returns a table. If it's a function, evaluate the function to produce the arguments used for testing. Continuing on the example above, it would be something like this:Describe alternatives you've considered.
neotest.run.run()
supported arguments, but it did not.Additional context
A very naive implementation would probably be something like this? Haven't tested it, and don't have good understanding of how neotest adapters are written -- just my attempt to figure out whether this is a large feature request or a little one 😄
The text was updated successfully, but these errors were encountered: