Skip to content
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

[BUG] Cannot run nearest test or all tests from file #386

Closed
rluetzner opened this issue Mar 25, 2024 · 6 comments
Closed

[BUG] Cannot run nearest test or all tests from file #386

rluetzner opened this issue Mar 25, 2024 · 6 comments
Assignees

Comments

@rluetzner
Copy link

rluetzner commented Mar 25, 2024

NeoVim Version
NVIM v0.9.5

Describe the bug
When I try to run any test directly from a file, I get an exception that indicates that no client is set.

E5108: Error executing lua ...obertl/.local/share/nvim/lazy/nvim-nio/lua/nio/tasks.lua:95: Async task failed without callback: The coroutine failed with this message: 
...al/share/nvim/lazy/neotest/lua/neotest/consumers/run.lua:37: attempt to index upvalue 'client' (a nil value)
stack traceback:
	...al/share/nvim/lazy/neotest/lua/neotest/consumers/run.lua: in function <...al/share/nvim/lazy/neotest/lua/neotest/consumers/run.lua:24>
	...al/share/nvim/lazy/neotest/lua/neotest/consumers/run.lua:38: in function 'get_tree_from_args'
	...al/share/nvim/lazy/neotest/lua/neotest/consumers/run.lua:142: in function 'func'
	...obertl/.local/share/nvim/lazy/nvim-nio/lua/nio/tasks.lua:168: in function <...obertl/.local/share/nvim/lazy/nvim-nio/lua/nio/tasks.lua:167>
stack traceback:
	[C]: in function 'error'
	...obertl/.local/share/nvim/lazy/nvim-nio/lua/nio/tasks.lua:95: in function 'close_task'
	...obertl/.local/share/nvim/lazy/nvim-nio/lua/nio/tasks.lua:117: in function 'step'
	...obertl/.local/share/nvim/lazy/nvim-nio/lua/nio/tasks.lua:145: in function 'stop'
	[string ":lua"]:1: in main chunk

Surprisingly enough, when I open up the summary instead, all tests are discovered and can be run without problems. Well, almost...after I trigger the above exception once, I can't ran tests via the summary pane either.

To Reproduce
Please provide a minimal init.lua to reproduce which can be run as the following:

nvim --clean -u minimal.lua

You can edit the following example file to include your adapters and other required setup.

cal lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "https://github.com/folke/lazy.nvim.git",
    "--branch=stable", -- latest stable release
    lazypath,
  })
end
vim.opt.rtp:prepend(lazypath)

-- Example using a list of specs with the default options
vim.g.mapleader = " " -- Make sure to set `mapleader` before lazy so your mappings are correct
vim.g.maplocalleader = "\\" -- Same for `maplocalleader`

require("lazy").setup({
  {
    "nvim-treesitter/nvim-treesitter",
    opts = {
      ensure_installed = {
        "c_sharp",
        "go",
      },
      auto_install = true,
    },
  },
  {"nvim-neotest/neotest",
    dependencies = {
      "nvim-neotest/nvim-nio",
      "nvim-lua/plenary.nvim",
      "antoinemadec/FixCursorHold.nvim",
      "Issafalcon/neotest-dotnet",
      "nvim-neotest/neotest-go"
    },
    config = function()
      -- get neotest namespace (api call creates or returns namespace)
      local neotest_ns = vim.api.nvim_create_namespace("neotest")
      vim.diagnostic.config({
        virtual_text = {
          format = function(diagnostic)
            local message =
              diagnostic.message:gsub("\n", " "):gsub("\t", " "):gsub("%s+", " "):gsub("^%s+", "")
            return message
          end,
        },
      }, neotest_ns)

      -- setup keybindings
      vim.api.nvim_set_keymap("n", "<Leader>tt", ':lua require("neotest").run().run()<CR>', { noremap = true, silent = true, desc = 'Run nearest [t]est' })
      vim.api.nvim_set_keymap("n", "<Leader>tf", ':lua require("neotest").run().run(vim.fn.expand("%"))<CR>', { noremap = true, silent = true, desc = 'Run all tests in [f]ile' })
      vim.api.nvim_set_keymap("n", "<Leader>tt", ':lua require("neotest").run().stop()<CR>', { noremap = true, silent = true, desc = '[S]top nearest test' })
      vim.api.nvim_set_keymap("n", "<Leader>to", ':lua require("neotest").output.open()<CR>', { noremap = true, silent = true, desc = 'Show test [o]utput' })
      vim.api.nvim_set_keymap("n", "<Leader>tO", ':lua require("neotest").output.open({ enter = true })<CR>', { noremap = true, silent = true, desc = 'Show test [O]utput and enter' })
      vim.api.nvim_set_keymap("n", "<Leader>ts", ':lua require("neotest").summary.toggle()<CR>', { noremap = true, silent = true, desc = 'Show test [s]ummary' })

      require('neotest').setup({
        adapters = {
          require('neotest-dotnet'),
          require('neotest-go'),
        }
      })
    end,
  }
})

Steps to reproduce the behavior:

  1. Open a dotnet or go testfile.
  2. Use <Leader>ts to toggle the summary view.
  3. Execute a test.
  4. Use :lua require('neotest').run.run() or <Leader>tt to run the nearest test.
  5. See error.
  6. Try to execute the test via the summary view.
  7. See the same error.

Please provide example test files to reproduce. --> I will provide these, if it turns out that this cannot be reproduced with other languages. I don't have time to write a new set of C# or Go tests. I assume that this behavior is not limited to C# or Go and I'm surprised that nobody else seems to have reported it yet.

Expected behavior
When I hit <Leader>tt or execute :lua require('neotest').run.run() I should run the nearest test. When I hit <Leader>tf, I should run all tests from the file.

Logs
neotest.log

Additional context
Add any other context about the problem here.

@GoldenChrysus
Copy link

GoldenChrysus commented Mar 31, 2024

Same issue as well. Sometimes it works, sometimes it doesn't (applies to all commands, like watch, summary, etc.). Using rustaceanvim. Have had to abandon using neotest for now due to the issue. Tried versions 5.0.1, 5.0.0, and 4.9.0; issue occurs in all of them.

@rcarriga
Copy link
Collaborator

rcarriga commented Apr 8, 2024

Can you please provide the logs as requested, the error suggests the setup is not completing correctly

@rcarriga rcarriga closed this as completed Apr 8, 2024
@rcarriga rcarriga reopened this Apr 8, 2024
@rluetzner
Copy link
Author

Sorry @rcarriga , I forgot about this for a while. I've appended the log file to the bug report.

I did a quick scan myself, but couldn't find any errors or warnings in it.

@koptan
Copy link

koptan commented Apr 17, 2024

Same issue here, I am using NvChad

  {
  "nvim-neotest/neotest",
  lazy = false,
  dependencies = {
    "nvim-neotest/nvim-nio",
    "nvim-lua/plenary.nvim",
    "antoinemadec/FixCursorHold.nvim",
    "nvim-treesitter/nvim-treesitter"
  },
  config = function()
    require("neotest").setup({
      disable_all = true,
      enable = {
        "test_nearest",
        "test_file",
        "test_suite",
        "last_failed",
        "visit",
        "rerun",
        "debug",
      },
      term_pos = "vert",
      term_opener = "vsplit",
      term_closer = "q",
      term_geo = { "curwin", "vertical", "botright", "split" },
      adapters = {
           require('rustaceanvim.neotest')
      },
     }
       )
  end
},
 

@koptan
Copy link

koptan commented Apr 18, 2024

@rluetzner I found the issue, don't call first run as function

.run().run() it should be run.run()

@rluetzner
Copy link
Author

Thank you. That did it! 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants