-
Notifications
You must be signed in to change notification settings - Fork 18
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
Running test:watch only on current method or current file #12
Comments
It's an interesting Idea, But I don't know if should be in the core or in a plugin. require("laravel.artisan").run({ "test", "<file>" }, "watch") this same can be use but selecting the current file name and calling the function. |
I had something like this in mind, you could just have your cursor in vim in the test method and run that command ["test_file:watch"] = function()
local currentFile = string.gsub(vim.api.nvim_buf_get_name(0), vim.loop.cwd() .. "/", "")
return require("laravel.artisan").run({ "test", currentFile }, "watch")
end,
["test_method:watch"] = function()
local currentFile = string.gsub(vim.api.nvim_buf_get_name(0), vim.loop.cwd() .. "/", "")
local node = vim.treesitter.get_node()
local testMethod = function(node)
if node:type() == "method_declaration" then
return true
end
return false
end
if not testMethod(node) then
while node do
if not testMethod(node) then
node = node:parent()
else
break
end
end
end
if node then
local method_name = vim.inspect(vim.treesitter.get_node_text(node:field("name")[1], 0))
if string.sub(method_name, 2, 5) == "test" then
return require("laravel.artisan").run({ "test", currentFile, "--filter", method_name }, "watch")
end
end
utils.notify("artisan.run", { msg = "cursor is not on the testable method", level = "ERROR" })
end, It supports only phpunit style tests though. |
@adalessa let me know if you find this useful, i can make the PR, otherwise we can just close the issue |
@dorkster100 yes I have started to work on this I will have a PR soon. |
@dorkster100 been thinking about this, I think trying to test the near test intead of write if from scratch we can integrate the https://github.com/vim-test/vim-test I currently use it, and it works really well. |
I will checkout the vim-test solution, do you think of integrating it or just adding some documentation of how to set it up? In general the solution i posted in this issue is sufficient for most of my needs, the only missing thing is PEST variant, since I have not used it yet, i do not have enough information to implement it. What do you think is missing from the code I wrote? |
Would be nice to add watch only for one method or one file as it may be too much to run whole test suite every time. Probably a simple treesitter parse.
I can implement this, it seems to be simple considering the
watch
runner that is in the project.The text was updated successfully, but these errors were encountered: