Issafalcon / neotest-dotnet

Neotest adapter for dotnet
MIT License
63 stars 20 forks source link

Trouble getting this to work in LazyVim #71

Closed tucker87 closed 9 months ago

tucker87 commented 10 months ago

Setup: I'm on Windows 10, NVIM v0.9.2. A few warnings about Treesitter in the :checkhealth for some reason.

Problem: Just installed LazyVim to learn Vim and I'm a C# dev. Followed youtube video that setup jest testing and got it kind of working.

return {
  {
    "nvim-neotest/neotest",
    dependencies = { "Issafalcon/neotest-dotnet" },
    opts = function(_, opts)
      table.insert(
        opts.adapters,
        require("neotest-dotnet")({
          -- env = { CI = true },
          -- cwd = function()
          --   return vim.fn.getcwd()
          -- end,
          -- vim.fn.expand('%'),
          -- strategy = require("neotest-dotnet.strategies.netcoredbg"),
          -- is_custom_dotnet_debug = true,
        })
      )
    end,
  },
}

Here's my config with a bunch of commented out things that I've attempted to try and get this working.

I can get my test to show up in the Test Summary, but when I run it it doesn't reflect pass/fail even though I can see the output. And I can't run tests using tr, It says there are no tests.

Any help would be much apprieciated!

Issafalcon commented 9 months ago

Hi @tucker87,

A few things to point out. You mentioned jest testing here, but there is no relation to the neotest-jest adapter in this one (including the config options, which it looks like you are using some of for the neotest-dotnet adapter). Please read https://github.com/Issafalcon/neotest-dotnet#usage to see the up to date options you can provide to the adapter.

I'm not entirely sure your opts value is correct. As far as I know, it needs to resolve to a lua table. Maybe you meant to use config instead?

Here is my spec for neotest in case it helps:

local neotest_spec = {
  "nvim-neotest/neotest",
  event = "VeryLazy",
  dependencies = {
    "nvim-lua/plenary.nvim",
    "nvim-neotest/neotest-python",
    "nvim-neotest/neotest-plenary",
    "Issafalcon/neotest-dotnet",
    "haydenmeade/neotest-jest",
    "antoinemadec/FixCursorHold.nvim",
  },
  keys = fignvim.mappings.make_lazy_keymaps(neotest_keys, true),
  config = function()
    local neotest = require("neotest")
    neotest.setup({
      log_level = 1, -- For verbose logs
      adapters = {
        require("neotest-python")({
          dap = { justMyCode = false },
        }),
        require("neotest-plenary"),
        require("neotest-dotnet")({
          discovery_root = "solution",
        }),
        require("neotest-jest")({
          jestCommand = "npm test -- --runInBand --no-cache --watchAll=false",
          env = { CI = "true" },
          cwd = function(path) return vim.fn.getcwd() end,
        }),
      },
      icons = {
        expanded = "",
        child_prefix = "",
        child_indent = "",
        final_child_prefix = "",
        non_collapsible = "",
        collapsed = "",
        passed = "",
        running = "",
        failed = "",
        unknown = "",
        skipped = "",
      },
    })
  end,
}

I'm not sure what tr is, but I assume it's a keymapping in LazyVim. You would need to be more specific in explaining what neotest function that maps to.

In case you have any further issues, please provide exact reproduction steps, including the test framework you're using, and a repo with the dotnet code tests in that can recreate the problem you're seeing.

tucker87 commented 9 months ago

Thanks for the reply. It looks like the markdown ate some of my inputs.

I'm guessing I'm missing some knowledge of how LazyVim works.

image This is before I add any config.

< leader>ts shows this summary. < leader>tr should run the nearest test.

From https://www.lazyvim.org/extras/test/core { "< leader>tr", function() require("neotest").run.run() end, desc = "Run Nearest" }, { "< leader>ts", function() require("neotest").summary.toggle() end, desc = "Toggle Summary" },

return {
  { "nvim-neotest/neotest-plenary" },
  {
    "nvim-neotest/neotest",
    opts = { adapters = { "neotest-plenary" } },
  },
}

I took the above example and made this:

return {
  { "Issafalcon/neotest-dotnet" },
  {
    "nvim-neotest/neotest",
    opts = { adapters = { "neotest-dotnet" } },
  },
}

Which gave me this: image and image

So I'm doing something right. But it behaving exactly like it was when I first posted.

I'm honestly probably giving up on Neovim. It's been too hard to get even basic debugging working. :(

Feel free to close if this is just some LazyVim issue I guess.

Issafalcon commented 9 months ago

Thanks for the clarification.

To be fair, setting up debugging and testing are some of the most difficult things to do correctly in Neovim, especially for .NET. I mostly still need to switch back to VS or Rider to debug and run tests in a lot of the projects I work with professionally. So don't be too disheartened by this stuff not working properly.

I'll take a look at reproducing the above, as I haven't actively been using my own adapter much recently (working on a legacy .NET MVC app, so this isn't really do-able with Neovim). Things sometimes change in the .NET ecosystem that break the flow from running tests to matching up the output with the tests, so it could be something like this.

Issafalcon commented 9 months ago

@tucker87 - I wasn't able to reproduce your issue, so I can only assume that LazyVim is doing something I'm not expecting.

image

I can run the function() require("neotest").run.run() end shortcut I have without issue also. It may be worth raising this in the LazyVim repo, because it isn't an issue with "vanilla" configuration.