nvim-neotest / neotest

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

`output.open_on_run` doesn't? #71

Closed rouge8 closed 2 years ago

rouge8 commented 2 years ago

When I set output.open_on_run = true, I expected Neotest to open the output window after running a test, even if the test passes, but no window opened. Is this expected behavior?

This is my Neotest config:

local neotest = require("neotest")
neotest.setup({
    adapters = {
        require("neotest-python")({}),
    },
    output = {
        enabled = true,
        open_on_run = true,
    },
})
rcarriga commented 2 years ago

No it's intended behaviour to open on successful tests.

You can use a custom consumer if you want to always show output on run

local neotest = require("neotest")
neotest.setup({
  consumers = {

    always_open_output = function(client)
      local async = require("neotest.async")

      client.listeners.results = function(adapter_id, results)
        local file_path = async.fn.expand("%:p")
        local row = async.fn.getpos(".")[2] - 1
        local position = client:get_nearest(file_path, row, {})
        if not position then
          return
        end
        local pos_id = position:data().id
        if not results[pos_id] then
          return
        end
        neotest.output.open({ position_id = pos_id, adapter = adapter_id })
      end
    end,
  },
  ...
rouge8 commented 2 years ago

No it's intended behaviour to open on successful tests

So it’s a bug that it’s not?

rcarriga commented 2 years ago

No meant to say it's not intended behaviour

rouge8 commented 2 years ago
  consumers = {

    always_open_output = function(client)
      local async = require("neotest.async")

      client.listeners.results = function(adapter_id, results)
        local file_path = async.fn.expand("%:p")
        local row = async.fn.getpos(".")[2] - 1
        local position = client:get_nearest(file_path, row, {})
        if not position then
          return
        end
        local pos_id = position:data().id
        if not results[pos_id] then
          return
        end
        neotest.output.open({ position_id = pos_id, adapter = adapter_id })
      end
    end,
  },

This works, thanks!