Some consumers for neotest.
Mostly based on the following pattern I use when investigating a failing test:
- Run the failing test once.
- Close the test file, open the source code, change something.
- Rerun the failing test again without opening the test file. (
require("neotest").run.run_last()
) - (optional) View the test's output using
output_or_attach
consumer. - (optional) Stop the current test run using
stop_global
consumer. - Repeat steps 3-5 until done.
Apart from the initial test run (step 1), I don't need to open the test file again. I can just keep editing the source code and rerunning the test.
Resiliently view the test output.
This consumer will work regardless of which file you're currently editing. If there is a running test, it'll find it. If no test is currently running, it'll select the most recent test instead.
Stop a test run from anywhere.
Yanks the test command for the test under the cursor. You can then paste into a terminal, edit it, and run it manually. Useful for debugging.
Using lazy:
{
"nvim-neotest/neotest",
dependencies = {
-- 1. add as dependency to neotest
"thenbe/neotest-consumers",
},
config = function()
require("neotest").setup({
consumers = {
-- 2. add to your consumers list
neotest_consumers = require("neotest-consumers").consumers,
},
})
end,
keys = {
-- 3. map keys
{
"<leader>ts",
function()
require("neotest").neotest_consumers.stop_global()
end,
desc = "test stop",
},
{
"<leader>to",
function()
require("neotest").neotest_consumers.output_or_attach()
end,
desc = "test output",
},
{
"<leader>ty",
function()
require("neotest").neotest_consumers.yank()
end,
desc = "test yank command",
},
},
},